17 Commits

Author SHA1 Message Date
3ab9eab943 (fix) more reference errors 2021-04-28 19:30:19 +02:00
3eb549b593 (fix) Uncaught ReferenceError: Discord is not defined 2021-04-28 19:21:15 +02:00
caeb668fe2 (fix) chants_title 2021-04-28 19:07:27 +02:00
4504a32614 rc1 2021-04-28 18:56:08 +02:00
20d00d47b5 removed db storage location 2021-04-28 18:44:57 +02:00
471213dae0 fixed storage location issues and minor bugs 2021-04-28 18:43:19 +02:00
9bbf1b302e Merge branch 'add-spells' of https://github.com/TobenderZephyr/dsabot into add-spells 2021-04-28 16:29:55 +02:00
beb4ee7ef5 updated README 2021-04-28 16:29:40 +02:00
ee9310af8b Merge branch 'master' into add-spells 2021-04-28 16:11:38 +02:00
c1ac938588 cleanup testing variables and code 2021-04-28 16:05:19 +02:00
e16759bc35 (fix) Chants were referring to spells 2021-04-28 15:56:11 +02:00
d29e04a103 better error handling, added chant command 2021-04-28 15:50:02 +02:00
f5c485fdcc added related messages, added skillcheck for spells (cast) 2021-04-27 18:11:47 +02:00
1b67dcb4e6 added more chants, added command for getting info 2021-04-26 15:16:39 +02:00
cee6fee5a3 added _some_ chants, restructuring data from spells 2021-04-26 07:54:58 +02:00
e65715cce6 added return list of spells. Moved them into seperate json 2021-04-24 09:53:05 +02:00
8e4f4eedb8 initial implementation of spells 2021-04-22 19:14:15 +02:00
68 changed files with 12412 additions and 17184 deletions

View File

@ -1,83 +0,0 @@
{
"parserOptions": {
"ecmaVersion": 10,
"sourceType": "script",
"ecmaFeatures": {
"jsx": true
}
},
"rules": {
"constructor-super": 2,
"for-direction": 2,
"getter-return": 2,
"no-async-promise-executor": 2,
"no-case-declarations": 2,
"no-class-assign": 2,
"no-compare-neg-zero": 2,
"no-cond-assign": 2,
"no-const-assign": 2,
"no-constant-condition": 2,
"no-control-regex": 2,
"no-debugger": 2,
"no-delete-var": 2,
"no-dupe-args": 2,
"no-dupe-class-members": 2,
"no-dupe-else-if": 2,
"no-dupe-keys": 2,
"no-duplicate-case": 2,
"no-empty": 2,
"no-empty-character-class": 2,
"no-empty-pattern": 2,
"no-ex-assign": 2,
"no-extra-boolean-cast": 2,
"no-extra-semi": 2,
"no-fallthrough": 2,
"no-func-assign": 2,
"no-global-assign": 2,
"no-import-assign": 2,
"no-inner-declarations": 2,
"no-invalid-regexp": 2,
"no-irregular-whitespace": 2,
"no-misleading-character-class": 2,
"no-mixed-spaces-and-tabs": 2,
"no-new-symbol": 2,
"no-obj-calls": 2,
"no-octal": 2,
"no-prototype-builtins": 0,
"no-redeclare": 2,
"no-regex-spaces": 2,
"no-self-assign": 2,
"no-setter-return": 2,
"no-shadow-restricted-names": 2,
"no-sparse-arrays": 2,
"no-this-before-super": 2,
"no-undef": 2,
"no-unexpected-multiline": 2,
"no-unreachable": 2,
"no-unsafe-finally": 2,
"no-unsafe-negation": 2,
"no-unused-labels": 2,
"no-unused-vars": 2,
"no-useless-catch": 2,
"no-useless-escape": 2,
"no-with": 2,
"require-yield": 2,
"use-isnan": 2,
"valid-typeof": 2,
"no-underscore-dangle": 0,
"spaced-comment": 0,
"no-console": 0,
"no-unneeded-ternary": 0,
"object-shorthand": 0,
"no-useless-rename": 0,
"arrow-body-style": ["error", "as-needed", { "requireReturnForObjectLiteral": true }]
},
"env": {
"node": true,
"jest": true,
"commonjs": true,
"es2017": true
},
"plugins": ["prettier"],
"extends": ["airbnb", "prettier"]
}

View File

@ -1,49 +0,0 @@
# This workflow checks out code, performs a Codacy security scan
# and integrates the results with the
# GitHub Advanced Security code scanning feature. For more information on
# the Codacy security scan action usage and parameters, see
# https://github.com/codacy/codacy-analysis-cli-action.
# For more information on Codacy Analysis CLI in general, see
# https://github.com/codacy/codacy-analysis-cli.
name: Codacy Security Scan
on:
push:
branches: [ master ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ master ]
schedule:
- cron: '33 2 * * 6'
jobs:
codacy-security-scan:
name: Codacy Security Scan
runs-on: ubuntu-latest
steps:
# Checkout the repository to the GitHub Actions runner
- name: Checkout code
uses: actions/checkout@v2
# Execute Codacy Analysis CLI and generate a SARIF output with the security issues identified during the analysis
- name: Run Codacy Analysis CLI
uses: codacy/codacy-analysis-cli-action@v4.4.7
with:
# Check https://github.com/codacy/codacy-analysis-cli#project-token to get your project token from your Codacy repository
# You can also omit the token and run the tools that support default configurations
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
verbose: true
output: results.sarif
format: sarif
# Adjust severity of non-security issues
gh-code-scanning-compat: true
# Force 0 exit code to allow SARIF file generation
# This will handover control about PR rejection to the GitHub side
max-allowed-issues: 2147483647
# Upload the SARIF file generated in the previous step
- name: Upload SARIF results file
uses: github/codeql-action/upload-sarif@v1
with:
sarif_file: results.sarif

View File

@ -13,31 +13,16 @@ on:
- 'Dockerfile'
pull_request:
branches: [ master ]
pull_request_target:
branches: [ master ]
jobs:
test:
build:
runs-on: ubuntu-latest
# If the PR is coming from a fork (pull_request_target), ensure it's opened by "dependabot[bot]".
# Otherwise, clone it normally.
if: |
(github.event_name == 'pull_request_target' && github.actor == 'dependabot[bot]') ||
(github.event_name != 'pull_request_target' && github.actor != 'dependabot[bot]')
strategy:
matrix:
node-version: [15.x]
node-version: [10.x, 12.x, 14.x, 15.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- name: Checkout
if: ${{ github.event_name != 'pull_request_target' }}
uses: actions/checkout@v2
- name: Checkout PR
if: ${{ github.event_name == 'pull_request_target' }}
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
@ -45,13 +30,10 @@ jobs:
- run: npm ci
- run: npm run build --if-present
- run: npm test
- name: Run codacy-coverage-reporter
uses: codacy/codacy-coverage-reporter-action@v1
with:
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
deploy:
needs: test
needs: build
if: ${{github.event_name == 'push'}}
runs-on: ubuntu-latest
steps:

2
.gitignore vendored
View File

@ -12,4 +12,4 @@ Thumbs.db
!/data/*.js
!/data/*.json
/private
coverage

View File

@ -1,6 +1,6 @@
# DSA Discord Bot
[![CodeQL](https://github.com/TobenderZephyr/dsabot/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/TobenderZephyr/dsabot/actions/workflows/codeql-analysis.yml)
![GitHub package.json version](https://img.shields.io/github/package-json/v/TobenderZephyr/dsabot?style=flat-square) ![node-current](https://img.shields.io/node/v/discord.js?style=flat-square) ![GitHub last commit](https://img.shields.io/github/last-commit/TobenderZephyr/dsabot?style=flat-square) ![GitHub Workflow Status (branch)](https://img.shields.io/github/workflow/status/TobenderZephyr/dsabot-docker/Build%20Image%20on%20Push/main?label=docker%20image&style=flat-square) ![Docker Pulls](https://img.shields.io/docker/pulls/tobenderzephyr/dsabot) [![Codacy Badge](https://app.codacy.com/project/badge/Grade/e7dfc961c9eb481185468cc59b22fdfa)](https://www.codacy.com/gh/TobenderZephyr/dsabot/dashboard?utm_source=github.com&utm_medium=referral&utm_content=TobenderZephyr/dsabot&utm_campaign=Badge_Grade) [![Codacy Badge](https://app.codacy.com/project/badge/Coverage/e7dfc961c9eb481185468cc59b22fdfa)](https://www.codacy.com/gh/TobenderZephyr/dsabot/dashboard?utm_source=github.com&utm_medium=referral&utm_content=TobenderZephyr/dsabot&utm_campaign=Badge_Coverage)
# DSA Discord Bot
This Project is a fork of LucaSchwan/dsa-bot.

View File

@ -1,231 +0,0 @@
require('module-alias/register');
require('babel-plugin-rewire');
const Attack = require('@Commands/Attack');
const getWeapon = Attack.__get__('getWeapon');
const getAttributeLevel = Attack.__get__('getAttributeLevel');
const getCombatTechniqueLevel = Attack.__get__('getCombatTechniqueLevel');
const isMeleeWeapon = Attack.__get__('isMeleeWeapon');
const getAttribute = Attack.__get__('getAttribute');
const CompareAttackResult = Attack.__get__('CompareAttackResult');
const getCombatTechnique = Attack.__get__('getCombatTechnique');
describe('getCombatTechnique', () => {
it('should be undefined without value', () => {
expect(getCombatTechnique({})).toBeUndefined();
});
it('should be undefined without value', () => {
expect(getCombatTechnique({ combattechnique: 'made-up' })).toBeUndefined();
});
it('should be null without any params.', () => {
expect(getCombatTechnique()).toBeNull();
});
it('should return defined object', () => {
expect(getCombatTechnique({ combattechnique: 'dolche' })).toEqual(
expect.objectContaining({
id: expect.any(String),
name: expect.any(String),
Leiteigenschaft: expect.anything(),
})
);
});
});
describe('getAttribute', () => {
test('should return Object', () => {
const obj = { id: 'mut', kuerzel: 'MU', name: 'Mut' };
expect(getAttribute('KK')).toBeInstanceOf(Object);
expect(getAttribute('KK')).toEqual(
expect.objectContaining({
id: expect.any(String),
kuerzel: expect.any(String),
name: expect.any(String),
})
);
expect(getAttribute('MU')).toEqual(obj);
});
});
describe('CompareAttackResults', () => {
test('CompareAttackResults', () => {
expect(CompareAttackResult()).toEqual(
expect.objectContaining({
Ok: expect.any(Boolean),
Patzer: expect.any(Boolean),
CriticalHit: expect.any(Boolean),
DoubleDamage: expect.any(Boolean),
Dice: expect.anything(),
})
);
});
it('should return object with fumble', () => {
const obj = {
Ok: false,
Patzer: true,
CriticalHit: false,
DoubleDamage: false,
Dice: [20, 14],
};
expect(CompareAttackResult([20, 14], 8)).toEqual(obj);
});
it('should return object with crit', () => {
const obj = {
Ok: true,
Patzer: false,
CriticalHit: true,
DoubleDamage: false,
Dice: [1, 14],
};
expect(CompareAttackResult([1, 14], 8)).toEqual(obj);
});
it('should return object with double damage', () => {
const obj = {
Ok: true,
Patzer: false,
CriticalHit: true,
DoubleDamage: true,
Dice: [1, 4],
};
expect(CompareAttackResult([1, 4], 8)).toEqual(obj);
});
it('should return object without passing', () => {
const obj = {
Ok: false,
Patzer: false,
CriticalHit: false,
DoubleDamage: false,
Dice: [10],
};
expect(CompareAttackResult([10, 14], 8)).toEqual(obj);
});
});
describe('getAttributeLevel', () => {
it('returns a number ', () => {
expect(getAttributeLevel({ attributes: [{ id: 'mut', level: 8 }] }, 'mut')).toBe(8);
});
});
describe('getCombatTechniqueLevel', () => {
it('returnsa defined object ', () => {
const Player = { combattechniques: [{ id: 'dolche', level: 9 }] };
const CombatTechnique = { name: 'Dolche', id: 'dolche', Leiteigenschaft: ['GE'] };
expect(getCombatTechniqueLevel(Player, CombatTechnique)).toEqual(
expect.objectContaining({
id: expect.any(String),
name: expect.any(String),
level: expect.any(Number),
Leiteigenschaft: expect.any(Array),
})
);
});
});
describe('getWeapon', () => {
it('returns an object', () => {
expect(getWeapon('waqqif')).toBeInstanceOf(Object);
});
it('returns a defined object ', () => {
expect(getWeapon('waqqif')).toEqual(
expect.objectContaining({
id: expect.any(String),
name: expect.any(String),
dice: expect.any(Number),
diemodificator: expect.any(Number),
at_mod: expect.any(Number),
pa_mod: expect.any(Number),
article: expect.any(Number),
DmgThreshold: expect.any(Number),
combattechnique: expect.any(String),
})
);
});
});
describe('isMeleeWeapon', () => {
it('returns true ', () => {
expect(isMeleeWeapon({ id: 'waqqif' })).toBeTruthy();
});
it('returns false ', () => {
expect(isMeleeWeapon({ id: 'bogen' })).toBeFalsy();
});
});
describe('main Function', () => {
it('should abort with a message: no entry found', () => {
const reply = jest.fn(str => str);
const message = {
reply: reply,
};
const handleAttack = Attack.__get__('handleAttack');
//expect(handleAttack(err)).toThrowError();
expect(handleAttack({}, { message: message })).toEqual(
'Sorry, für dich habe ich leider keinen Eintrag 😥'
);
});
it('should abort with a message: No such weapon', () => {
const reply = jest.fn(str => str);
const message = {
reply: reply,
};
const handleAttack = Attack.__get__('handleAttack');
const args = [''];
expect(handleAttack([{ character: {} }], { message: message, args: args })).toEqual(
'Diese Waffe gibt es nicht.'
);
});
it('complete run with melee weapon', () => {
const reply = jest.fn(str => str);
const message = {
reply: reply,
};
const character = {
attributes: [
{ id: 'mut', level: 10 },
{ id: 'fingerfertigkeit', level: 10 },
{ id: 'klugheit', level: 10 },
{ id: 'intuition', level: 10 },
{ id: 'charisma', level: 10 },
{ id: 'gewandtheit', level: 16 },
{ id: 'konstitution', level: 10 },
{ id: 'koerperkraft', level: 10 },
],
combattechniques: [{ id: 'dolche', level: 8 }],
};
const handleAttack = Attack.__get__('handleAttack');
const args = ['messer'];
expect(handleAttack({ character: character }, { message: message, args: args })).toEqual(
expect.any(String)
);
});
it('complete run with ranged weapon', () => {
const reply = jest.fn(str => str);
const message = {
reply: reply,
};
const character = {
attributes: [
{ id: 'mut', level: 10 },
{ id: 'fingerfertigkeit', level: 14 },
{ id: 'klugheit', level: 10 },
{ id: 'intuition', level: 10 },
{ id: 'charisma', level: 10 },
{ id: 'gewandtheit', level: 16 },
{ id: 'konstitution', level: 10 },
{ id: 'koerperkraft', level: 10 },
],
combattechniques: [{ id: 'boegen', level: 8 }],
};
const handleAttack = Attack.__get__('handleAttack');
const args = ['langbogen'];
expect(handleAttack({ character: character }, { message: message, args: args })).toEqual(
expect.any(String)
);
});
});

View File

@ -1,123 +0,0 @@
require('module-alias/register');
require('babel-plugin-rewire');
const Attribute = require('@Commands/Attribute');
const HandleNamedAttributes = Attribute.__get__('HandleNamedAttributes');
const getAttributeLevel = Attribute.__get__('getAttributeLevel');
const getAttribute = Attribute.__get__('getAttribute');
const handleAttributeCheck = Attribute.__get__('handleAttributeCheck');
describe('getAttribute', () => {
test('getAttribute should return Object', () => {
const obj = { id: 'mut', kuerzel: 'MU', name: 'Mut' };
expect(getAttribute('KK')).toEqual(
expect.objectContaining({
id: expect.any(String),
kuerzel: expect.any(String),
name: expect.any(String),
})
);
expect(getAttribute('MU')).toEqual(obj);
expect(getAttribute('mut')).toEqual(obj);
});
it('should return undefined', () => {
expect(getAttribute()).toBeUndefined();
});
});
describe('getAttributeLevel', () => {
it('returns a number ', () => {
expect(getAttributeLevel({ attributes: [{ id: 'mut', level: 8 }] }, { id: 'mut' })).toBe(8);
});
});
describe('HandleNamedAttribute', () => {
it('should return an object', () => {
const Character = {
attributes: [{ id: 'mut', level: 8 }],
};
expect(HandleNamedAttributes({ Character: Character, args: ['mut'] })).toEqual({
Name: 'Mut',
Level: 8,
});
});
});
it('should return with no errors', () => {
const reply = jest.fn(str => str);
const message = {
reply: reply,
author: {
tag: 'test',
},
};
const doc = { character: { attributes: [{ id: 'mut', level: 8 }] } };
const args = ['mut'];
expect(handleAttributeCheck(doc, { message, args })).toEqual(expect.any(String));
});
it('should return with no errors', () => {
const reply = jest.fn(str => str);
const message = {
reply: reply,
author: {
tag: 'test',
},
};
const docs = { character: { attributes: [{ id: 'mut', level: 8 }] } };
const args = ['MU'];
expect(handleAttributeCheck(docs, { message, args })).toEqual(expect.any(String));
});
it('should return with no errors', () => {
const reply = jest.fn(str => str);
const message = {
reply: reply,
author: {
tag: 'test',
},
};
const docs = [{ character: { attributes: [{ id: 'mut', level: 8 }] } }];
const args = [8];
for (let i = 0; i < 30; i += 1) {
expect(handleAttributeCheck(docs, { message, args })).toEqual(expect.any(String));
}
});
it('should return with no errors', () => {
const reply = jest.fn(str => str);
const message = {
reply: reply,
author: {
tag: 'test',
},
};
const docs = [{ character: { attributes: [{ id: 'mut', level: 8 }] } }];
const args = [8, '+2'];
for (let i = 0; i < 30; i += 1) {
expect(handleAttributeCheck(docs, { message, args })).toEqual(expect.any(String));
}
});
it('should return empty', () => {
const message = { author: { tag: 'test' }, reply: jest.fn(str => str) };
const args = ['MU'];
expect(Attribute.exec(message, args)).toBeInstanceOf(Promise);
//expect(Attribute.exec(message, args)).resolves.toBeUndefined();
});
/*
const reply = jest.fn(str => str);
const message = {
reply: reply,
author: {
tag: 'test',
},
};
const docs = [{ character: { attributes: [{ id: 'mut', level: 8 }] } }];
const args = ['MU'];
const run = [];
for (let i = 1; i < 100; i++) {
run.push(i);
}
test.each(run)('run multiple times (%s)', () => {
expect(handleAttributeCheck(docs, { message, args })).toEqual(expect.any(String));
});
*/

View File

@ -1,76 +0,0 @@
require('module-alias/register');
require('babel-plugin-rewire');
const Chants = require('@Commands/Chants');
const createChantList = Chants.__get__('createChantList');
const TestValue = {
Name: 'Test',
Level: 10,
Attributes: [
{ Name: 'Klugheit', Level: 10 },
{ Name: 'Charisma', Level: 11 },
{ Name: 'Mut', Level: 12 },
],
};
describe('createChantList', () => {
it('should return an array with expected object(s)', () => {
const Test = { chants: [{ id: 'test', level: 10 }] };
const expected = {
Name: 'Test',
Level: 10,
Attributes: [
{ Name: 'Klugheit', Level: 10 },
{ Name: 'Charisma', Level: 11 },
{ Name: 'Mut', Level: 12 },
],
};
Chants.__Rewire__('getChant', () => expected);
expect(createChantList(Test)).toEqual(expect.arrayContaining([expected]));
Chants.__ResetDependency__('getChant');
});
it('should abort if character has no chants', () => {
expect(createChantList({ attributes: [] })).toBeNull();
expect(createChantList()).toBeNull();
expect(createChantList({})).toBeNull();
});
});
describe('ReplyChant', () => {
const ReplyChant = Chants.__get__('ReplyChant');
it('should return null if no param given.', () => {
expect(ReplyChant()).toBeNull();
});
it('should return a string', () => {
// toBeInstanceOf(String) is not working :(
expect(
ReplyChant({
Name: 'Test',
Level: 9,
Attributes: [
{ Name: 'Klugheit', Level: 10 },
{ Name: 'Charisma', Level: 11 },
{ Name: 'Mut', Level: 12 },
],
})
).toMatch(/.*Test.*(9)?.*/);
});
Chants.__ResetDependency__('ReplyChant');
});
describe('ReplyChantList', () => {
const ReplyChantList = Chants.__get__('ReplyChantList');
it('should return null if params are empty', () => {
expect(ReplyChantList('')).toBeNull();
expect(ReplyChantList([])).toBeNull();
expect(ReplyChantList()).toBeNull();
});
it('should return Name and Level', () => {
const input = [TestValue];
expect(ReplyChantList(input)).toMatch('Test (10)');
});
});

View File

@ -1,134 +0,0 @@
require('module-alias/register');
require('babel-plugin-rewire');
const List = require('@Commands/List');
// const getStats = reWireUtils.__get__('getStats');
const getAttribute = List.__get__('getAttribute');
const printHeader = List.__get__('printHeader');
const listStats = List.__get__('listStats');
describe('getAttributes', () => {
it('should return an attribute object', () => {
expect(getAttribute({ id: 'mut', level: 9 })).toEqual(
expect.objectContaining({
id: 'mut',
Name: 'Mut',
Level: 9,
})
);
expect(getAttribute()).toEqual(
expect.objectContaining({
id: expect.any(String),
Name: expect.any(String),
Level: expect.any(Number),
})
);
});
});
describe('printHeader', () => {
it('should return null with no params', () => {
expect(printHeader()).toBeNull();
});
it('should return a string', () => {
const attributes = [{ Short: 'AA' }, { Short: 'BB' }, { Short: 'CC' }];
expect(printHeader(attributes)).toMatch(/\s+AA\s+[|]\s+BB\s+[|]\s+CC\s+/g);
});
});
describe('listStats', () => {
it('should return a string', () => {
expect(listStats([{ Level: 8 }, { Level: 9 }, { Level: 10 }])).toMatch(
/\s+8\s+[|]\s+9\s+[|]\s+10\s+/
);
});
});
describe('findUser', () => {
const expected = {
user: 'Test',
character: {
name: 'test',
},
};
List.__Rewire__('db', {
findOne: () => Promise.resolve(expected),
});
const findUser = List.__get__('findUser');
expect(findUser()).toBeInstanceOf(Promise);
expect(findUser()).resolves.toEqual(expected);
});
/*
describe('findUsers', () => {
const expected = {
user: 'Test',
character: {
name: 'test',
attributes: [{ id: 'mut', level: 9 }],
},
};
List.__Rewire__('db', {
findOne: () => {
return Promise.resolve(expected);
},
});
const findUsers = List.__get__('findUsers');
expect(findUser()).toBeInstanceOf(Promise);
expect(findUser()).resolves.toEqual(expected);
});*/
describe('getStats', () => {
it('should give name, id and level in order', () => {
const getStats = List.__get__('getStats');
const user = {
character: {
attributes: [
{ id: 'mut', level: 10 },
{ id: 'klugheit', level: 11 },
],
},
};
expect(getStats(user)).toEqual(
expect.arrayContaining([
{
Name: expect.any(String),
Level: expect.any(Number),
Short: expect.any(String),
id: expect.any(String),
},
])
);
});
});
describe('returnResult', () => {
const returnResult = List.__get__('returnResult');
const message = { reply: str => str };
const characters = [
{
Name: 'Zulu',
Attributes: [
{ id: 'charisma', Level: 7, Short: 'CH' },
{ id: 'mut', Level: 14, Short: 'MU' },
],
},
{
Name: 'Alfa',
Attributes: [
{ id: 'mut', Level: 10, Short: 'MU' },
{ id: 'charisma', Level: 11, Short: 'CH' },
],
},
];
it('returns if no characters were found', () => {
expect(returnResult(message, [])).toBe('Keine Benutzer auf dieser Liste gefunden.');
expect(returnResult(message)).toBe('Keine Benutzer auf dieser Liste gefunden.');
});
it('returns a string ', () => {
expect(returnResult(message, characters)).toMatch(/.*/);
});
});

View File

@ -1,14 +0,0 @@
require('module-alias/register');
require('babel-plugin-rewire');
const command = require('@Commands/Roll');
//const exec = command.__get__('exec');
describe('roll command', () => {
const reply = jest.fn(str => str);
const message = { author: { tag: 'test' }, reply: reply };
it('should not return anything without correct arguments', () => {
const args = ['1w6'];
expect(command.exec(message, args)).resolves.toBeUndefined();
expect(reply).toHaveBeenCalled();
});
});

View File

@ -1,76 +0,0 @@
require('module-alias/register');
require('babel-plugin-rewire');
const Spells = require('@Commands/Spells');
const createSpellList = Spells.__get__('createSpellList');
const TestValue = {
Name: 'Test',
Level: 10,
Attributes: [
{ Name: 'Klugheit', Level: 10 },
{ Name: 'Charisma', Level: 11 },
{ Name: 'Mut', Level: 12 },
],
};
describe('createSpellList', () => {
it('should return an array with expected object(s)', () => {
const Test = { spells: [{ id: 'test', level: 10 }] };
const expected = {
Name: 'Test',
Level: 10,
Attributes: [
{ Name: 'Klugheit', Level: 10 },
{ Name: 'Charisma', Level: 11 },
{ Name: 'Mut', Level: 12 },
],
};
Spells.__Rewire__('getSpell', () => expected);
expect(createSpellList(Test)).toEqual(expect.arrayContaining([expected]));
Spells.__ResetDependency__('getSpell');
});
it('should abort if character has no chants', () => {
expect(createSpellList({ attributes: [] })).toBeNull();
expect(createSpellList()).toBeNull();
expect(createSpellList({})).toBeNull();
});
});
describe('ReplySpell', () => {
const ReplySpell = Spells.__get__('ReplySpell');
it('should return null if no param given.', () => {
expect(ReplySpell()).toBeNull();
});
it('should return a string', () => {
// toBeInstanceOf(String) is not working :(
expect(
ReplySpell({
Name: 'Test',
Level: 9,
Attributes: [
{ Name: 'Klugheit', Level: 10 },
{ Name: 'Charisma', Level: 11 },
{ Name: 'Mut', Level: 12 },
],
})
).toMatch(/.*Test.*(9)?.*/);
});
Spells.__ResetDependency__('ReplySpell');
});
describe('ReplySpellList', () => {
const ReplySpellList = Spells.__get__('ReplySpellList');
it('should return null if params are empty', () => {
expect(ReplySpellList('')).toBe('Du kennst keine Zaubersprüche.');
expect(ReplySpellList([])).toBe('Du kennst keine Zaubersprüche.');
expect(ReplySpellList()).toBe('Du kennst keine Zaubersprüche.');
});
it('should return Name and Level', () => {
const input = [TestValue];
expect(ReplySpellList(input)).toMatch('Test (10)');
});
});

View File

@ -1,33 +1,12 @@
require('module-alias/register');
const {CalculateQuality} = require('@dsabot/CalculateQuality');
const TestValues = [
[1, 1],
[2, 1],
[3, 1],
[4, 2],
[5, 2],
[6, 2],
[7, 3],
[8, 3],
[9, 3],
[10, 4],
[11, 4],
[12, 4],
[13, 5],
[14, 5],
[15, 5],
[16, 6],
[17, 6],
[18, 6],
[19, 6],
[20, 6],
[1,1], [2,1], [3,1],
[4,2], [5,2], [6,2],
[7,3], [8,3], [9,3],
[10,4],[11,4],[12,4],
[13,5],[14,5],[15,5]
];
test.each(TestValues)('Retrieving Quality for %s', (input, output) => {
expect(CalculateQuality(input)).toBe(output);
});
it('should return 1 without input', () => {
expect(CalculateQuality()).toBe(1);
});

View File

@ -1,10 +0,0 @@
require('module-alias/register');
const { Capitalize } = require('@dsabot/Capitalize');
it('should capitalize the first letter.', () => {
expect(Capitalize('mother')).toBe('Mother');
});
it('should capitalize without any word given', () => {
expect(Capitalize()).toBe('None');
});

View File

@ -1,60 +0,0 @@
require('module-alias/register');
const { CompareResults } = require('@dsabot/CompareResults');
it('should return an object', () => {
const Obj = {
Passed: 0,
CriticalHit: 0,
Fumbles: 0,
PointsUsed: [],
PointsRemaining: 0,
};
expect(CompareResults).toBeInstanceOf(Object);
expect(CompareResults()).toMatchObject(Obj);
});
it('should match No. of Fumbles', () => {
const Obj = {
Passed: 0,
CriticalHit: 0,
Fumbles: 2,
PointsUsed: [0, 0, 0],
PointsRemaining: 0,
};
expect(CompareResults([9, 20, 20])).toMatchObject(Obj);
});
it('should match No. of Passed', () => {
const Obj = {
Passed: 3,
CriticalHit: 0,
Fumbles: 0,
PointsUsed: [0, 0, 0],
PointsRemaining: 0,
};
expect(CompareResults([7, 7, 7])).toMatchObject(Obj);
});
it('should match No. of Critical Hits', () => {
const Obj = {
Passed: 3,
CriticalHit: 2,
Fumbles: 0,
PointsUsed: [0, 0, 0],
PointsRemaining: 0,
};
expect(CompareResults([8, 1, 1])).toMatchObject(Obj);
});
it('should decrease Points remaining', () => {
const Obj = {
Passed: 3,
CriticalHit: 0,
Fumbles: 0,
PointsUsed: [0, 0, 3],
PointsRemaining: 3,
};
expect(CompareResults([11, 9, 15], [12, 12, 12], 0, 6)).toMatchObject(Obj);
});

View File

@ -1,4 +1,6 @@
const { CountOccurences } = require('../../functions/CountOccurences');
const {
CountOccurences
} = require('../../functions/CountOccurences');
test('Counting Occurences', () => {
expect(CountOccurences([1, 2, 3, 4, 1], 1)).toBe(2);
});

View File

@ -1,19 +0,0 @@
require('module-alias/register');
const { CreateResultTable, f } = require('@dsabot/CreateResultTable');
it('turn any number into a string', () => {
expect(f(2)).toBe('+2');
expect(f(0)).toBe('0');
expect(f(-1)).toBe('-1');
});
it('should return a string', () => {
const obj = {
Attributes: [8, 8, 8],
Throws: [7, 7, 7],
PointsUsed: [0, 0, 0],
Bonus: 0,
};
expect(CreateResultTable(obj)).toEqual(expect.any(String));
});

View File

@ -1,19 +0,0 @@
require('module-alias/register');
const { Random } = require('@dsabot/Random');
it('should return with no min or max value', () => {
expect(Random.int()).toBeUndefined();
});
it('call for use should return true', () => {
expect(Random.use(null)).toBeTruthy();
});
it('should return between 1 and 2', () => {
expect(Random.int(1, 2)).toBeGreaterThanOrEqual(1);
});
it('should return between 1 and 2', () => {
expect(Random.int(1, 2)).toBeLessThanOrEqual(2);
});
it('should return exactly 1', () => {
expect(Random.int(1, 1)).toBe(1);
});

View File

@ -2,14 +2,7 @@ const { roll } = require('@dsabot/Roll');
describe('rolling dice', () => {
const expected = [1, 2, 3, 4, 5, 6];
test.each(expected)('contains only numbers from 1 to 6', value => {
test.each(expected)('contains only numbers from 1 to 6', (value) => {
expect(roll(200, 6).dice).toContain(value);
});
});
describe('rolling dice', () => {
const expected = [1, 2, 3, 4, 5, 6];
test.each(expected)('contains only numbers from 1 to 6', value => {
expect(roll(200, 6, 'test').dice).toContain(value);
});
});

View File

@ -1,6 +0,0 @@
require('module-alias/register');
const { findMessage } = require('@dsabot/findMessage');
it('should capitalize the first letter.', () => {
expect(findMessage('ERROR')).toBe('Irgendwas ist schief gelaufen. 🤔');
});

View File

@ -1,23 +0,0 @@
require('module-alias/register');
const { getAttributeLevels } = require('@dsabot/getAttributeLevels');
const Character = {
attributes: [
{ id: 'mut', level: 10 },
{ id: 'klugheit', level: 11 },
{ id: 'intuition', level: 12 },
{ id: 'charisma', level: 13 },
{ id: 'fingerfertigkeit', level: 14 },
{ id: 'gewandtheit', level: 15 },
{ id: 'konstitution', level: 16 },
{ id: 'koerperkraft', level: 17 },
],
};
it('should return an array', () => {
expect(getAttributeLevels(['MU', 'IN', 'KO'], Character)).toBeInstanceOf(Array);
});
it('should have 3 items in it.', () => {
expect(getAttributeLevels(['MU', 'IN', 'KO'], Character)).toHaveLength(3);
});

View File

@ -1,103 +0,0 @@
require('module-alias/register');
require('babel-plugin-rewire');
const command = require('@dsabot/getChant');
describe('getChant integration test', () => {
it('should not find an entry for a chant', () => {
const getChant = command.__get__('getChant');
expect(getChant({ Character: { name: '' }, chant_name: 'test' })).toBeNull();
});
it('should return null if char has no chants.', () => {
const Character = {
attributes: [
{ id: 'mut', level: 10 },
{ id: 'klugheit', level: 11 },
{ id: 'charisma', level: 12 },
],
};
command.__set__('Chants', [{ id: 'test', name: 'Test', attributes: ['MU', 'KL', 'CH'] }]);
const getChant = command.__get__('getChant');
expect(getChant({ Character: Character, chant_name: 'test' })).toBeNull();
});
it('should return a correct chant result.', () => {
const Character = {
attributes: [
{ id: 'mut', level: 10 },
{ id: 'klugheit', level: 11 },
{ id: 'charisma', level: 12 },
],
chants: [{ id: 'test', level: 7 }, { id: 'no-level' }],
};
const Chants = [
{
id: 'test',
name: 'Testchant',
attributes: ['MU', 'KL', 'CH'],
},
{ id: 'no-level', name: 'No Level', attributes: ['MU', 'KL', 'CH'] },
];
command.__set__('Chants', Chants);
const getChant = command.__get__('getChant');
expect(getChant({ Character: Character, chant_name: 'test' })).toEqual(
expect.objectContaining({
Name: 'Testchant',
Level: 7,
Attributes: [
{ Level: 10, Name: 'MU' },
{ Level: 11, Name: 'KL' },
{ Level: 12, Name: 'CH' },
],
})
);
expect(getChant({ Character: Character, chant_name: 'Testchant' })).toEqual(
expect.objectContaining({
Name: 'Testchant',
Level: 7,
Attributes: [
{ Level: 10, Name: 'MU' },
{ Level: 11, Name: 'KL' },
{ Level: 12, Name: 'CH' },
],
})
);
expect(getChant({ Character: Character, chant_name: 'no-level' })).toEqual(
expect.objectContaining({
Name: 'No Level',
Level: 0,
Attributes: [
{ Level: 10, Name: 'MU' },
{ Level: 11, Name: 'KL' },
{ Level: 12, Name: 'CH' },
],
})
);
});
it('should not find the chant.', () => {
const Character = {
attributes: [
{ id: 'mut', level: 10 },
{ id: 'klugheit', level: 11 },
{ id: 'charisma', level: 12 },
],
chants: [{ id: 'test', level: 7 }],
};
const Chants = [{ id: 'test', name: 'Testchant', attributes: ['MU', 'KL', 'CH'] }];
command.__set__('Chants', Chants);
const getChant = command.__get__('getChant');
expect(getChant({ Character: Character, chant_name: 'well-hidden' })).toBeNull();
});
});

View File

@ -1,109 +0,0 @@
require('module-alias/register');
require('babel-plugin-rewire');
const command = require('@dsabot/getSpell');
describe('getSpell integration test', () => {
it('should not find an entry for a spell', () => {
const getSpell = command.__get__('getSpell');
expect(getSpell({ Character: { name: '' }, spell_name: 'test' })).toBeNull();
});
it('should return null if char has no spells.', () => {
const Character = {
attributes: [
{ id: 'mut', level: 10 },
{ id: 'klugheit', level: 11 },
{ id: 'charisma', level: 12 },
],
};
command.__set__('Spells', [
{ id: 'test', name: 'Test', attributes: ['MU', 'KL', 'CH'], modified_by: ['SK'] },
]);
const getSpell = command.__get__('getSpell');
expect(getSpell({ Character: Character, spell_name: 'test' })).toBeNull();
});
it('should return a correct spell result.', () => {
const Character = {
attributes: [
{ id: 'mut', level: 10 },
{ id: 'klugheit', level: 11 },
{ id: 'charisma', level: 12 },
],
spells: [{ id: 'test', level: 7 }, { id: 'no-level' }],
};
const Spells = [
{
id: 'test',
name: 'Testspell',
attributes: ['MU', 'KL', 'CH'],
modified_by: ['SK'],
},
{ id: 'no-level', name: 'No Level', attributes: ['MU', 'KL', 'CH'], modified_by: [] },
];
command.__set__('Spells', Spells);
const getSpell = command.__get__('getSpell');
expect(getSpell({ Character: Character, spell_name: 'test' })).toEqual(
expect.objectContaining({
Name: 'Testspell',
Level: 7,
Attributes: [
{ Level: 10, Name: 'MU' },
{ Level: 11, Name: 'KL' },
{ Level: 12, Name: 'CH' },
],
ModifiedBy: ['SK'],
})
);
expect(getSpell({ Character: Character, spell_name: 'Testspell' })).toEqual(
expect.objectContaining({
Name: 'Testspell',
Level: 7,
Attributes: [
{ Level: 10, Name: 'MU' },
{ Level: 11, Name: 'KL' },
{ Level: 12, Name: 'CH' },
],
ModifiedBy: ['SK'],
})
);
expect(getSpell({ Character: Character, spell_name: 'no-level' })).toEqual(
expect.objectContaining({
Name: 'No Level',
Level: 0,
Attributes: [
{ Level: 10, Name: 'MU' },
{ Level: 11, Name: 'KL' },
{ Level: 12, Name: 'CH' },
],
ModifiedBy: [],
})
);
});
it('should not find the spell.', () => {
const Character = {
attributes: [
{ id: 'mut', level: 10 },
{ id: 'klugheit', level: 11 },
{ id: 'charisma', level: 12 },
],
spells: [{ id: 'test', level: 7 }],
};
const Spells = [{ id: 'test', name: 'Testspell', attributes: ['MU', 'KL', 'CH'] }];
command.__set__('Spells', Spells);
const getSpell = command.__get__('getSpell');
expect(getSpell({ Character: Character, spell_name: 'well-hidden' })).toBeNull();
});
});

View File

@ -1,12 +0,0 @@
require('module-alias/register');
const { isEmpty } = require('@dsabot/isEmpty');
it('should return true statements', () => {
expect(isEmpty({})).toBeTruthy();
expect(isEmpty()).toBeTruthy();
expect(isEmpty('')).toBeTruthy();
expect(isEmpty([])).toBeTruthy();
expect(isEmpty({ key: 'value' })).toBeFalsy();
expect(isEmpty([null])).toBeFalsy();
expect(isEmpty([''])).toBeFalsy();
});

View File

@ -1,12 +0,0 @@
require('module-alias/register');
const { isString } = require('@dsabot/isString');
it('should return true statements', () => {
expect(isString({})).toBeFalsy();
expect(isString()).toBeFalsy();
expect(isString('')).toBeTruthy();
expect(isString([])).toBeFalsy();
expect(isString({ key: 'value' })).toBeFalsy();
expect(isString([null])).toBeFalsy();
expect(isString([''])).toBeFalsy();
});

View File

@ -1,16 +0,0 @@
module.exports = {
plugins: [
'babel-plugin-rewire',
[
'module-resolver',
{
root: ['.'],
alias: {
'@Lib': './lib',
'@dsabot': './functions',
'@Commands': './commands',
},
},
],
],
};

View File

@ -1,146 +1,8 @@
require('module-alias/register');
const { roll } = require('@dsabot/Roll');
const globals = require('../globals');
const db = globals.db;
const Random = require('random');
//const { roll } = require('@dsabot/Roll');
const { findMessage }= require('@dsabot/findMessage');
const { isEmpty } = require('@dsabot/isEmpty');
const { db } = require('../globals');
const { CombatTechniques } = require('../globals');
const { Werte } = require('../globals');
const { Weapons } = require('../globals');
const { MeleeWeapons } = require('../globals');
function getCombatTechnique(Weapon) {
if (Weapon) return CombatTechniques.find(technique => technique.id === Weapon.combattechnique);
return null;
}
function getAttribute(abbr) {
return Werte.find(attribute => attribute.kuerzel === abbr);
}
function CompareAttackResult(dice = [8, 8], Comparison = 6) {
let ok = false;
let crit = false;
let dd = false;
let fumble = false;
dice.forEach((val, index) => {
if (index === 0) {
ok = val <= Comparison ? true : false;
crit = val === 1 ? true : false;
fumble = val === 20 ? true : false;
if ((ok && !crit) || (!ok && !fumble)) {
dice.pop();
}
}
if (index === 1) {
dd = crit && val < Comparison ? true : false;
fumble = !crit && val > Comparison ? true : false;
}
});
return {
Ok: ok,
Patzer: fumble,
CriticalHit: crit,
DoubleDamage: dd,
Dice: dice,
};
}
function getAttributeLevel(Player = {}, Attribute = '') {
return Player.attributes.find(a => a.id === Attribute).level;
}
function getCombatTechniqueLevel(Player = {}, CombatTechnique = {}) {
if (Player && CombatTechnique) {
const p = Player.combattechniques.find(technique => technique.id === CombatTechnique.id);
return {
id: CombatTechnique.id,
name: CombatTechnique.name,
level: p ? p.level : 6,
Leiteigenschaft: CombatTechnique.Leiteigenschaft,
};
}
return null;
}
function getWeapon(Weapon = '') {
return Weapons.find(
w => w.id === Weapon.toLowerCase() || w.name.toLowerCase() === Weapon.toLowerCase()
);
}
function isMeleeWeapon(Weapon) {
if (MeleeWeapons.find(MeleeWeapon => MeleeWeapon.id === Weapon.id)) return true;
return false;
}
function handleAttack(doc, { message, args }) {
if (isEmpty(doc)) {
return message.reply(findMessage('NOENTRY'));
}
const Player = doc.character;
const Weapon = getWeapon(args[0]);
if (!Weapon) {
return message.reply(findMessage('NO_SUCH_WEAPON'));
}
// Determining Both Attack and Ranged Attack Values.
const CombatTechnique = getCombatTechniqueLevel(Player, getCombatTechnique(Weapon)); //?+
const Attribute = isMeleeWeapon(Weapon)
? getAttributeLevel(Player, 'mut')
: getAttributeLevel(Player, 'fingerfertigkeit');
let AttackValue = isMeleeWeapon(Weapon)
? CombatTechnique.level + Weapon.at_mod
: CombatTechnique.level;
AttackValue += Math.floor((Attribute - 8) / 3);
const { dice } = roll(2, 20);
const Bonus = parseInt(args[1], 10) || 0;
const Comparison = Math.floor(AttackValue + Bonus);
const AttackResult = CompareAttackResult(dice, Comparison);
let Reply = `Du greifst mit ${Weapon.name} an.\n Dein Angriffswert für ${CombatTechnique.name} ist ${AttackValue} (KtW: ${CombatTechnique.level})\n`;
Reply += `Deine 🎲: \` ${AttackResult.Dice.join(', ')} \`\n\n`;
Reply += !AttackResult.Ok ? findMessage('COMBAT_FAIL') : findMessage('COMBAT_SUCCESS');
Reply += AttackResult.Patzer ? findMessage('COMBAT_CRIT_FAIL') : '';
Reply += AttackResult.CriticalHit ? findMessage('COMBAT_CRIT_SUCCESS') : '';
Reply += AttackResult.DoubleDamage ? findMessage('COMBAT_DOUBLEDAMAGE') : '';
if (AttackResult.Ok) {
// adding 1 to damage for every point above weapon's "Leiteigenschaft"
// applies only to Melee Weapons.
let AttackBonus = 0;
if (isMeleeWeapon(Weapon) && Weapon.DmgThreshold) {
CombatTechnique.Leiteigenschaft.forEach(abbr => {
const attrib = getAttribute(abbr);
const AttributeValue = getAttributeLevel(Player, attrib.id);
if (Weapon.DmgThreshold < AttributeValue) {
AttackBonus += Math.floor(AttributeValue - Weapon.DmgThreshold);
}
});
}
const DamageDice = roll(1, 6).dice;
let Damage = Weapon.diemodificator + AttackBonus + DamageDice.reduce((p, v) => p + v);
Damage = AttackResult.DoubleDamage ? (Damage *= 2) : Damage;
Reply += '\n\nHier aufklappen, wenn der Gegner nicht parieren/Ausweichen konnte:\n';
Reply += `||\n`;
Reply += ` ${Weapon.name} (${Weapon.dice}W6+${
Weapon.diemodificator
}) richtet ${Damage} schaden an. ${
AttackBonus ? `(+${AttackBonus} Bonus auf Leiteigenschaft)` : ''
}`;
Reply += `\nDeine 🎲: ${DamageDice.join(', ')}\n||\n`;
}
return message.reply(Reply);
}
module.exports = {
name: 'attack',
@ -150,13 +12,113 @@ module.exports = {
needs_args: true,
async exec(message, args) {
db.findOne({ user: message.author.tag })
.then(doc => {
handleAttack(doc, { message, args });
})
.catch(err => {
message.reply(findMessage('ERROR'));
throw new Error(err);
try {
db.find({
user: message.author.tag,
}, function(err, docs) {
if (docs.length === 0) {
return message.reply(findMessage('NOENTRY'));
}
else {
Random.use(message.author.tag);
const Player = docs[0].character;
const Weapon = globals.Weapons.find(w => w.id === args[0].toLowerCase());
if(!Weapon) { return message.reply(globals.Replies.find(r => r.id === 'NO_SUCH_WEAPON').string); }
// Determining Both Attack and Ranged Attack Values.
const CombatTechnique = globals.CombatTechniques.find(technique => technique.id === Weapon.combattechnique);
let PlayerCombatTechnique = Player.combattechniques.find(technique => technique.id === CombatTechnique.id);
let CombatTechniqueValue = null;
if (PlayerCombatTechnique) { CombatTechniqueValue = PlayerCombatTechnique.level; }
if(!CombatTechniqueValue) { CombatTechniqueValue = 6; }
let Attribute;
let AttackValue = CombatTechniqueValue;
if (globals.MeleeWeapons.find(MeleeWeapon => MeleeWeapon.id === Weapon.id)) {
// For melee combat, MU is used for determining the Attack Value. Also, any weapon-based attack modifiers apply.
Attribute = Player.attributes.find(a => a.id === 'mut').level;
AttackValue += Weapon.at_mod;
}
else {
// For ranged combat, FF is used for determining Attack Value
Attribute = Player.attributes.find(a => a.id === 'fingerfertigkeit').level;
}
AttackValue += Math.floor((Attribute - 8)/3);
let dice = [];
let Bonus = 0;
if(args[1] && !isNaN(parseInt(args[1]))) { Bonus = parseInt(args[1]); }
let Comparison = Math.floor(AttackValue + Bonus);
let CriticalHit = false;
let Patzer = false;
let Ok = false;
let DoubleDamage = false;
for (let i = 0; i < 2; i++) {
dice.push(Random.int(1,20));
}
// If there is a cleaner way to do these checks, I'm all into it.
if((dice[0] == 1) && dice[1] <= Comparison) { CriticalHit = true; DoubleDamage = true; Ok = true; }
else if((dice[0] == 1) && dice[1] > Comparison) { CriticalHit = true; Ok = true; }
else if((dice[0] == 20) && dice[1] > Comparison) { Patzer = true; }
else if(dice[0] <= Comparison && !CriticalHit) { Ok = true; dice.pop(); }
else if(dice[0] > Comparison ) { dice.pop(); }
let Reply = 'Du greifst mit ' + globals.Declination[Weapon.article] + ' ' + Weapon.name + ' an.\n';
Reply += 'Dein Angriffswert für ' + CombatTechnique.name + ' ist ' + Math.floor(((Attribute - 8)/3) + CombatTechniqueValue) + '. (KtW: ' + CombatTechniqueValue + ')\n';
Reply += 'Deine 🎲: ` ' + dice.join(', ') + ' `.\n\n';
if(!Ok) {
Reply += globals.Replies.find(reply => reply.id === 'COMBAT_FAIL').string;
if(Patzer) { Reply += globals.Replies.find(reply => reply.id === 'COMBAT_CRIT_FAIL').string; }
}
else {
if(CriticalHit) { Reply += globals.Replies.find(reply => reply.id === 'COMBAT_CRIT_SUCCESS').string; }
if(DoubleDamage) { Reply += globals.Replies.find(reply => reply.id === 'COMBAT_DOUBLEDAMAGE').string; }
if(!CriticalHit) { Reply += globals.Replies.find(reply => reply.id === 'COMBAT_SUCCESS').string; }
// adding 1 to damage for every point above weapon's "Leiteigenschaft"
// applies only to Melee Weapons.
let AttackBonus = 0;
if (globals.MeleeWeapons.find(MeleeWeapon => MeleeWeapon.id === Weapon.id))
{
if(Weapon.DmgThreshold) {
CombatTechnique.Leiteigenschaft.forEach(LEKuerzel => {
let Leiteigenschaft = globals.Werte.find(attribute => attribute.kuerzel === LEKuerzel);
let DmgThreshold = Weapon.DmgThreshold;
let AttributeValue = Player.attributes.find(attribute => attribute.id === Leiteigenschaft.id).level;
if(DmgThreshold<AttributeValue) {
AttackBonus += Math.floor(AttributeValue - DmgThreshold);
}
});
}
}
const DieModificator = Weapon.diemodificator;
let Damage = DieModificator + AttackBonus;
let DamageDice = [];
for (let i = 0; i < Weapon.dice; i++) {
DamageDice.push(Random.int(1,6));
}
DamageDice.forEach(result => {
Damage += result;
});
if(DoubleDamage) { Damage *= 2; }
Reply += '\n\nHier aufklappen, wenn der Gegner nicht parieren/Ausweichen konnte:\n';
Reply += '||' + globals.Articles[Weapon.article] + ' ' + Weapon.name + ' (' + Weapon.dice + 'W6+' + Weapon.diemodificator +') erzielt ` ' + Damage + ' ` Schaden.';
Reply += '\nDeine 🎲: ` ' + DamageDice.join(',') + ' `.||\n';
}
return message.reply( Reply );
}
});
}
catch (e) {
throw e;
}
},
};

View File

@ -1,77 +1,9 @@
require('module-alias/register');
const { roll } = require('@dsabot/Roll');
const globals = require('../globals');
const { CountOccurences } = require('@dsabot/CountOccurences');
const { findMessage } = require('@dsabot/findMessage');
const { CompareResults } = require('@dsabot/CompareResults');
const { isEmpty } = require('@dsabot/isEmpty');
const { isString } = require('@dsabot/isString');
const { db } = require('../globals');
const { Werte } = require('../globals');
const Random = require('random');
const db = globals.db;
function getAttributeLevel(Character = {}, Attribute = {}) {
return Character.attributes.find(attribute => attribute.id === Attribute.id).level;
}
function getAttribute(attribute = '') {
return attribute.length === 2
? Werte.find(a => a.kuerzel === attribute.toUpperCase())
: Werte.find(a => a.name.toLowerCase() === attribute.toLowerCase());
}
function HandleNamedAttributes({ Character = {}, args = [] } = {}) {
const Attribute = getAttribute(args[0]);
const Level = getAttributeLevel(Character, Attribute) || 8;
return {
Name: Attribute.name,
Level,
};
}
function handleAttributeCheck(doc, { message, args }) {
if (isEmpty(doc)) {
return message.reply(findMessage('NOENTRY'));
}
const Attribute = isString(args[0])
? HandleNamedAttributes({ Character: doc.character, args: args })
: null;
const Level = Attribute ? Attribute.Level : args[0] || 8;
const Bonus = parseInt(args[1], 10) || 0;
const { dice } = roll(2, 20, message.author.tag);
const Result = CompareResults(dice, [Level, Level], Bonus);
// handle crits
if (Result.CriticalHit === 2) {
return message.reply(
`${findMessage('TITLE_CRIT_SUCCESS')}\n${findMessage('MSG_CRIT_SUCCESS')}`
);
}
if (Result.Fumbles === 2) {
return message.reply(
`${findMessage('TITLE_CRIT_FAILURE')}\n${findMessage('MSG_CRIT_FAILURE')}`
);
}
// every
if (dice[0] + Bonus > Level) {
return message.reply(
`Du hast die Probe (Stufe ${Level}) leider nicht bestanden 😢.\nDeine 🎲: ${dice[0]} ${
Bonus ? `+${Bonus}` : ''
}`
);
}
if (Attribute) {
return message.reply(
`Du hast die Probe auf ${Attribute.Name} (Stufe ${
Attribute.Level
}) bestanden. Deine 🎲: ${dice[0]} ${Bonus ? `+${Bonus}` : ''}`
);
}
return message.reply(
`Du hast die Probe (Stufe ${Level}) bestanden. Deine 🎲: ${dice[0]} ${
Bonus ? `+${Bonus}` : ''
}`
);
}
module.exports = {
name: 'attribute',
description: '',
@ -79,11 +11,86 @@ module.exports = {
usage: '<Eigenschaft> / <Eigenschaftswert>',
needs_args: true,
async exec(message, args) {
db.findOne({ user: message.author.tag })
.then(doc => handleAttributeCheck(doc, { message, args }))
.catch(err => {
message.reply(findMessage('ERROR'));
throw new Error(err);
try {
let Attribute;
let AttributeName;
let Level = 8;
await db.find({
user: message.author.tag,
}, async (err, docs) => {
// user calls with text, let's look him up in the database.
if (isNaN(args[0])) {
Attribute = HandleNamedAttributes({
Character: docs[0].character,
args: args
});
AttributeName = Attribute.Name;
Level = Attribute.Level;
} else {
Level = args[0];
}
Random.use(message.author.tag);
const dice = [];
dice.push(Random.int(1, 20));
if (dice[0] == 1 || dice[0] == 20) {
dice.push(Random.int(1, 20));
}
// handle crits
if (CountOccurences(dice, 1) == 2) {
message.reply('Du hast einen kritischen Erfolg erzielt (' + dice.join(', ') + ')! 🎉🥳🎆');
return;
} else if (CountOccurences(dice, 20) == 2) {
message.reply('Du hast einen Patzer (' + dice.join(', ') + ')! 😭 Viel Erfolg beim nächsten mal!');
return;
}
if ((dice.length == 2 && dice[0] != 20 && dice[1] <= Level) || (dice.length == 1 && dice[0] <= Level)) {
if (AttributeName) {
message.reply('Du hast die Probe auf ' + AttributeName + ' (Stufe ' + Level + ') bestanden.\n' +
'Deine 🎲: ' + dice.join(', '));
} else {
message.reply('Du hast die Probe (Stufe ' + Level + ') bestanden.\n' +
'Deine 🎲: ' + dice.join(', '));
}
} else if (AttributeName) {
message.reply('Du hast die Probe auf ' + AttributeName + ' (Stufe ' + Level + ') leider nicht bestanden 😢.\n' +
'Deine 🎲: ' + dice.join(', '));
} else {
message.reply('Du hast die Probe (Stufe ' + Level + ') leider nicht bestanden 😢.\n' +
'Deine 🎲: ' + dice.join(', '));
}
});
} catch (e) {
throw e;
}
},
};
const HandleCrits = (dice) => {
};
const HandleNamedAttributes = ({Character: Character = [], args: args = []} = {}) => {
let Attributes = globals.Werte;
let Level = 8; // This is the minimum attributes value.
let AttributeName;
let AttributeId;
if (args[0].length == 2) {
AttributeId = Attributes.find(attribute => attribute.kuerzel === args[0].toUpperCase()).id;
} else {
AttributeId = args[0].toLowerCase() ||
Attributes.find(attribute => attribute.name.toLowerCase() === args[0].toLowerCase()).id;
}
Level = Character.attributes.find(attribute => attribute.id === AttributeId).level;
AttributeName = Attributes.find(attribute => attribute.id === AttributeId).name;
return {
Name: AttributeName,
Level: Level
};
};

View File

@ -1,16 +1,12 @@
const globals = require('../globals');
const Discord = require('discord.js');
const db = globals.db;
const { roll } = require('@dsabot/Roll');
const { findMessage } = require('@dsabot/findMessage');
const { getSpell } = require('@dsabot/getSpell');
const { CalculateQuality } = require('@dsabot/CalculateQuality');
const { CompareResults } = require('@dsabot/CompareResults');
const { CreateResultTable, f } = require('@dsabot/CreateResultTable');
const { isEmpty } = require('@dsabot/isEmpty');
const { isString } = require('@dsabot/isString');
const { db } = require('../globals');
module.exports = {
name: 'cast',
description:
@ -21,33 +17,25 @@ module.exports = {
usage: '<Zaubern> [<-Erschwernis> / <+Erleichterung>]',
needs_args: false,
async exec(message, args) {
db.findOne({ user: message.author.tag })
.then(doc => {
if (isEmpty(doc)) {
db.find({ user: message.author.tag }, (err, docs) => {
if (docs.length === 0) {
return message.reply(findMessage('NOENTRY'));
}
if (!doc.character.hasOwnProperty('spells'))
return message.reply(findMessage('NO_SPELLS'));
if (!isString(args[0])) {
if (!docs[0].character.hasOwnProperty('spells')) return message.reply(findMessage('NO_SPELLS'));
if (!isNaN(args[0])) {
return message.reply(findMessage('WRONG_ARGUMENTS'));
}
const Spell = getSpell({ Character: doc.character, spell_name: args[0] });
const Spell = getSpell({ Character: docs[0].character, spell_name: args[0] });
if (!Spell) {
return message.reply(findMessage('SPELL_UNKNOWN'));
}
if (!Spell.Level || !Spell.Attributes) {
return null;
return;
}
const { Attributes } = Spell;
const Attributes = Spell.Attributes;
const DiceThrow = roll(3, 20, message.author.tag).dice;
const Bonus = parseInt(args[1], 10) || 0;
const {
Passed,
CriticalHit,
Fumbles,
PointsUsed,
PointsRemaining,
} = CompareResults(
const Bonus = parseInt(args[1]) || 0;
let { Passed, CriticalHit, Fumbles, PointsUsed, PointsRemaining } = CompareResults(
DiceThrow,
Attributes.map(attr => attr.Level),
Bonus,
@ -83,26 +71,20 @@ module.exports = {
} else if (Passed < 3) {
Reply.addFields({
name: findMessage('TITLE_FAILURE'),
value: `${
Passed === 0 ? 'Keine Probe' : `nur ${Passed}/3 Proben`
} erfolgreich. 😪`,
value: `${Passed === 0 ? 'Keine Probe' : `nur ${Passed}/3 Proben`} erfolgreich. 😪`,
inline: false,
});
} else {
Reply.addFields({
name: findMessage('TITLE_SUCCESS'),
value: `Dein verbleibender Bonus: ${PointsRemaining}/${
Spell.Level
} (QS${CalculateQuality(PointsRemaining)})`,
value: `Dein verbleibender Bonus: ${PointsRemaining}/${Spell.Level} (QS${CalculateQuality(
PointsRemaining
)})`,
inline: false,
});
}
return message.reply(Reply);
})
.catch(err => {
message.reply(findMessage('ERROR'));
throw new Error(err);
message.reply(Reply);
});
},
};

View File

@ -1,15 +1,12 @@
const globals = require('../globals');
const Discord = require('discord.js');
const db = globals.db;
const { roll } = require('@dsabot/Roll');
const { findMessage } = require('@dsabot/findMessage');
const { getChant } = require('@dsabot/getChant');
const { CalculateQuality } = require('@dsabot/CalculateQuality');
const { CompareResults } = require('@dsabot/CompareResults');
const { CreateResultTable, f } = require('@dsabot/CreateResultTable');
const { isEmpty } = require('@dsabot/isEmpty');
const { isString } = require('@dsabot/isString');
const { db } = require('../globals');
module.exports = {
name: 'chant',
description:
@ -20,33 +17,25 @@ module.exports = {
usage: '<Liturgie/Zeremonie> [<-Erschwernis> / <+Erleichterung>]',
needs_args: false,
async exec(message, args) {
db.findOne({ user: message.author.tag })
.then(doc => {
if (isEmpty(doc)) {
db.find({ user: message.author.tag }, (err, docs) => {
if (docs.length === 0) {
return message.reply(findMessage('NOENTRY'));
}
if (!doc.character.hasOwnProperty('chants'))
return message.reply(findMessage('NO_CHANTS'));
if (!isString(args[0])) {
if (!docs[0].character.hasOwnProperty('chants')) return message.reply(findMessage('NO_CHANTS'));
if (!isNaN(args[0])) {
return message.reply(findMessage('WRONG_ARGUMENTS'));
}
const Chant = getChant({ Character: doc.character, chant_name: args[0] });
const Chant = getChant({ Character: docs[0].character, chant_name: args[0] });
if (!Chant) {
return message.reply(findMessage('CHANT_UNKNOWN'));
}
if (!Chant.Level || !Chant.Attributes) {
return null;
return;
}
const { Attributes } = Chant;
const Attributes = Chant.Attributes;
const DiceThrow = roll(3, 20, message.author.tag).dice;
const Bonus = parseInt(args[1], 10) || 0;
const {
Passed,
CriticalHit,
Fumbles,
PointsUsed,
PointsRemaining,
} = CompareResults(
const Bonus = parseInt(args[1]) || 0;
let { Passed, CriticalHit, Fumbles, PointsUsed, PointsRemaining } = CompareResults(
DiceThrow,
Attributes.map(attr => attr.Level),
Bonus,
@ -82,25 +71,19 @@ module.exports = {
} else if (Passed < 3) {
Reply.addFields({
name: findMessage('TITLE_FAILURE'),
value: `${
Passed === 0 ? 'Keine Probe' : `nur ${Passed}/3 Proben`
} erfolgreich. 😪`,
value: `${Passed === 0 ? 'Keine Probe' : `nur ${Passed}/3 Proben`} erfolgreich. 😪`,
inline: false,
});
} else {
Reply.addFields({
name: findMessage('TITLE_SUCCESS'),
value: `Dein verbleibender Bonus: ${PointsRemaining}/${
Chant.Level
} (QS${CalculateQuality(PointsRemaining)})`,
value: `Dein verbleibender Bonus: ${PointsRemaining}/${Chant.Level} (QS${CalculateQuality(
PointsRemaining
)})`,
inline: false,
});
}
return message.reply(Reply);
})
.catch(err => {
message.reply(findMessage('ERROR'));
throw new Error(err);
message.reply(Reply);
});
},
};

View File

@ -1,35 +1,9 @@
require('module-alias/register');
//const globals = require('../globals');
const globals = require('../globals');
const Discord = require('discord.js');
const db = globals.db;
const { findMessage } = require('@dsabot/findMessage');
const { getChant } = require('@dsabot/getChant');
const { isEmpty } = require('@dsabot/isEmpty');
const { db } = require('../globals');
const createChantList = (Character = {}) => {
if (!Character || !Character.hasOwnProperty('chants')) return null;
const ChantList = [];
Character.chants.forEach(chant =>
ChantList.push(getChant({ Character: Character, chant_name: chant.id }))
);
return ChantList.filter(value => value !== undefined && value !== null);
};
const ReplyChantList = (ChantList = []) => {
if (!ChantList || ChantList.length === 0) return null;
return `${ChantList.map(chant => `${chant.Name} ${chant.Level ? `(${chant.Level})` : ''}`).join(
'\n'
)}`;
};
const ReplyChant = (Chant = {}) => {
if (!Chant || Object.keys(Chant).length === 0) return null;
return `Deine Werte für ${Chant.Name} ${Chant.Level ? `(${Chant.Level})` : ''} sind:
${Chant.Attributes.map(attribute => `${attribute.Name}: ${attribute.Level}`).join(' ')}
`;
};
module.exports = {
name: 'chants',
description: 'Zeigt dir deinen Fertigkeitswert im jeweiligen Magietalent (Götterwirken).',
@ -38,15 +12,12 @@ module.exports = {
needs_args: false,
async exec(message, args) {
db.findOne({ user: message.author.tag })
.then(doc => {
if (isEmpty(doc)) {
db.find({ user: message.author.tag }, (err, docs) => {
if (docs.length === 0) {
return message.reply(findMessage('NOENTRY'));
}
console.log(doc.character);
const Character = doc.character;
if (!Character.hasOwnProperty('chants'))
return message.reply(findMessage('NO_CHANTS'));
Character = docs[0].character;
if (!Character.hasOwnProperty('chants')) return message.reply(findMessage('NO_CHANTS'));
if (args.length === 0) {
const Embed = new Discord.MessageEmbed()
.setColor('#0099ff')
@ -63,10 +34,28 @@ module.exports = {
return message.reply(findMessage('SPELL_UNKNOWN'));
}
return message.reply(ReplyChant(Chant));
})
.catch(err => {
message.reply(findMessage('ERROR'));
throw new Error(err);
});
},
};
const createChantList = (Character = {}) => {
if (!Character || !Character.hasOwnProperty('chants')) return;
let ChantList = [];
// todo: send 'chant' to getChant() so we can filter out blessings.
Character.chants.forEach(chant => ChantList.push(getChant({ Character: Character, chant_name: chant.id })));
return ChantList.filter(value => value !== undefined);
};
const ReplyChantList = (ChantList = []) => {
if (!ChantList) return;
return `${ChantList.map(chant => `${chant.Name} ${chant.Level ? `(${chant.Level})` : ''}`).join('\n')}`;
};
const ReplyChant = (Chant = {}) => {
if (!Chant) return;
return `Deine Werte für ${Chant.Name} ${Chant.Level ? '(' + Chant.Level + ')' : ''} sind:
${Chant.Attributes.map(attribute => `${attribute.Name}: ${attribute.Level}`).join(' ')}
`;
};

View File

@ -1,6 +1,6 @@
const globals = require('../globals');
const { roll } = require('@dsabot/Roll');
const { findMessage }= require('@dsabot/findMessage');
const { Coin } = require('../globals');
module.exports = {
name: 'kopf',
@ -9,8 +9,8 @@ module.exports = {
usage: '',
needs_args: false,
async exec(message) {
const { dice } = roll(1, 2, message.author.tag);
message.reply(`${findMessage('HEADS_OR_TAILS')} **${Coin[dice - 1]}**.`);
async exec(message, args) {
const coin = roll(1,2,message.author.tag).dice;
message.reply(`${findMessage('HEADS_OR_TAILS')} **${globals.Coin[(coin-1)]}**.`);
},
};

View File

@ -1,5 +1,6 @@
const Discord = require('discord.js');
const prfx = process.env.CMDPREFIX || '!';
const cmdprefix = process.env.CMDPREFIX || '!';
module.exports = {
name: 'help',
@ -7,91 +8,74 @@ module.exports = {
aliases: ['hilfe'],
usage: '',
needs_args: false,
async exec(message) {
async exec(message, args) {
const Help = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle('Hilfe')
.setDescription(
'Das sind die Befehle, die du verwenden kannst.\n' +
'Werte in Klammern müssen nicht mit angegeben werden.'
)
.setDescription('Das sind die Befehle, die du verwenden kannst.\n' +
'Werte in Klammern müssen nicht mit angegeben werden.')
.addFields(
{
name: `${prfx}kopf`,
value: `Wirf eine Münze. Kopf oder Zahl?`,
.addFields({
name: cmdprefix + 'kopf',
value: 'Wirf eine Münze. Kopf oder Zahl?',
inline: false,
},
{
name: `${prfx}roll <Anzahl> W <Augenzahl>`,
value: `Lass die Würfel rollen. Benötigt wird die Anzahl sowie die Augenzahl auf den Würfeln.`,
}, {
name: cmdprefix + 'roll <Anzahl> W <Augenzahl>',
value: 'Lass die Würfel rollen. Benötigt wird die Anzahl sowie die Augenzahl auf den Würfeln.',
inline: false,
},
{
name: `${prfx}ep/ap <Eigenschaftswert>`,
value:
`Du machst eine Eigenschaftsprobe / Attributprobe.\n` +
` Du würfelst mit einem W20 auf deinen Eigenschaftswert.\n` +
` Bei einer 1 oder 20 wird der Bestätigungswurf ausgeführt.`,
}, {
name: cmdprefix + 'ep/ap <Eigenschaftswert>',
value: ' Du machst eine Eigenschaftsprobe / Attributprobe.\n' +
' Du würfelst mit einem W20 auf deinen Eigenschaftswert.\n' +
' Bei einer 1 oder 20 wird der Bestätigungswurf ausgeführt.',
inline: false,
},
{
name: `${prfx}tp/fp <Eigenschaftswert1> <Eigenschaftswert2> <Eigenschaftswert3> (Fertigkeitswert) (+Erleichtert/-Erschwert)`,
value:
` Du machst eine Fertigkeitsprobe.\n` +
` Es werden drei Würfel auf deine Eigenschaftswerte geworfen. Hast du Boni auf dein Talent und/oder` +
` ist der Wurf erleichtert oder erschwert, wird dies in die Berechnung einbezogen.`,
}, {
name: cmdprefix + 'tp/fp <Eigenschaftswert1> <Eigenschaftswert2> <Eigenschaftswert3> (Fertigkeitswert) (+Erleichtert/-Erschwert)',
value: ' Du machst eine Fertigkeitsprobe.\n' +
' Es werden drei Würfel auf deine Eigenschaftswerte geworfen. Hast du Boni auf dein Talent und/oder' +
' ist der Wurf erleichtert oder erschwert, wird dies in die Berechnung einbezogen.',
inline: false,
},
{
name: `${prfx}talents`,
value: `Du erhälst eine Liste mit den Talentnamen, die du für ${prfx}talent/${prfx}skill nutzen kannst.`,
}, {
name: cmdprefix + 'talents',
value: ' Du erhälst eine Liste mit den Talentnamen, die du für ' +
cmdprefix + 'talent/' + cmdprefix + 'skill nutzen kannst.',
inline: false,
},
{
name: `${prfx}weapons`,
value: `Du erhälst eine Liste mit den Waffen, die du für ${prfx}attack/${prfx}angriff nutzen kannst.`,
}, {
name: cmdprefix + 'weapons',
value: ' Du erhälst eine Liste mit den Waffen, die du für ' +
cmdprefix + 'attack/' + cmdprefix + 'angriff nutzen kannst.',
inline: false,
},
{
}, {
name: '\u200B',
value: '\u200B',
},
{
}, {
name: '\u200B',
value: 'Wenn du mir deine .tdc Datei zusendest, kannst du folgendes nutzen:',
},
{
name: `${prfx}attack [Waffe] (+Erleichtert/-Erschwert)`,
value: `Du greifst mit deiner Waffe an. Es wird gleichzeitig Schaden gewürfelt, sofern dein Gegner den Schaden nicht abwenden kann.`,
}, {
name: cmdprefix + 'attack [Waffe] (+Erleichtert/-Erschwert)',
value: 'Du greifst mit deiner Waffe an. Es wird gleichzeitig Schaden gewürfelt, sofern dein Gegner den Schaden nicht abwenden kann.',
inline: false,
},
{
name: `${prfx}parry [Waffe] (+Erleichtert/-Erschwert)`,
value: `Du versuchst, mit der gewählten Waffe zu parieren.`,
}, {
name: cmdprefix + 'parry [Waffe] (+Erleichtert/-Erschwert)',
value: 'Du versuchst, mit der gewählten Waffe zu parieren.',
inline: false,
},
{
name: `${prfx}ep/ap [Klugheit] oder ${prfx}ep/ap [FF]`,
value: `siehe oben. Du brauchst deinen Wert nicht wissen.`,
},{
name: cmdprefix + 'ep/ap [Klugheit] oder ' + cmdprefix + 'ep/ap [FF]',
value: 'siehe oben. Du brauchst deinen Wert nicht wissen.',
inline: false,
},
{
name: `${prfx}talent <Talentname> (+Erleichtert/-Erschwert)`,
value: `siehe tp. Allerdings musst du deine Werte nicht wissen.`,
}, {
name: cmdprefix + 'talent <Talentname> (+Erleichtert/-Erschwert)',
value: 'siehe tp. Allerdings musst du deine Werte nicht wissen.',
inline: false,
},
{
name: `${prfx}skill <Talentname>`,
value: `Zeigt dir deinen Fertigkeitswert im jeweiligen Talent.`,
}, {
name: cmdprefix + 'skill <Talentname>',
value: 'Zeigt dir deinen Fertigkeitswert im jeweiligen Talent.',
inline: false,
},
{
name: `${prfx}remove`,
value: `Löscht deinen Charakter aus der Datenbank. Sinnvoll, wenn du mir eine neue zusenden möchtest.`,
}, {
name: cmdprefix + 'remove',
value: 'Löscht deinen Charakter aus der Datenbank. Sinnvoll, wenn du mir eine neue zusenden möchtest.',
inline: false,
}
);
});
message.author.send(Help);
},
};

View File

@ -1,114 +0,0 @@
require('module-alias/register');
const { findMessage } = require('@dsabot/findMessage');
const { isEmpty } = require('@dsabot/isEmpty');
const { db } = require('../globals');
const { Werte } = require('../globals');
function printHeader(attributes) {
if (!attributes) return null;
return `${''.padStart(31)}${attributes
.map(a => `${a.Short}`.padEnd(4).padStart(6))
.join('|')}\n`.toString();
}
function listStats(attributes) {
return `${attributes.map(a => `${a.Level}`.padEnd(4).padStart(6)).join('|')}\n`;
}
function getAttribute(attribute_request = { id: 'mut', level: 9 }) {
const Attribute = Werte.find(a => a.id === attribute_request.id);
return {
id: Attribute.id,
Name: Attribute.name,
Short: Attribute.kuerzel,
Level: attribute_request.level,
};
}
function getStats(user) {
const Attributes = [];
user.character.attributes.forEach(attribute => {
Attributes.push(getAttribute(attribute));
});
Attributes.sort((a, b) => (a.id > b.id ? 1 : -1));
return Attributes;
}
function returnResult(message, Characters) {
if (isEmpty(Characters)) return message.reply(findMessage('NO_CHARACTERS'));
Characters.sort((a, b) => (a.Name > b.Name ? 1 : -1));
let Reply = `\`\`\`\n${printHeader(Characters[0].Attributes)}`;
Characters.forEach(c => {
Reply += `${c.Name.toString().padEnd(30)} ${listStats(c.Attributes)}`;
});
Reply += `\`\`\``;
return message.reply(Reply);
}
async function findUser(request = '') {
return db
.findOne({
$or: [
{ user: request.replace('@', '') },
{ uid: request.replaceAll(/[<>!@]/gi, '') },
{ character: { name: request } },
],
})
.then(doc => doc);
}
async function findUsers(message) {
const Characters = [];
db.find({})
.limit(10)
.then(users => {
users.forEach(user => {
Characters.push({
Name: user.character.name,
Attributes: getStats(user),
});
});
})
.then(() => returnResult(message, Characters));
}
module.exports = {
name: 'list',
description: 'Gibt eine Liste von Mitspielern aus.',
aliases: ['liste'],
usage: '[@Mention / Benutzername]',
needs_args: false,
exec: async (message, args) => {
if (!args) return null;
if (args[0] === '--all') {
return findUsers(message);
}
const Characters = []; //?+
Promise.all(
args
.map(arg => findUser(arg))
.then(user => {
if (!isEmpty(user)) {
Characters.push({
Name: user.character.name,
Attributes: getStats(user),
});
}
})
).then(() => returnResult(message, Characters));
return null;
},
};
/*
(async () => {
db.loadDatabase();
const l = require('./List');
const msg = { author: { tag: 'tagged!' }, reply: e => console.log(e) };
l.exec(msg, ['tobenderzephyr#2509', 'ElManu#8438']);
})();
*/

View File

@ -1,11 +1,6 @@
const { findMessage } = require('@dsabot/findMessage');
const { isEmpty } = require('@dsabot/isEmpty');
const { Random } = require('@dsabot/Random');
const { db } = require('../globals');
const { Werte } = require('../globals');
const { Weapons } = require('../globals');
const { CombatTechniques } = require('../globals');
const { MeleeWeapons } = require('../globals');
const globals = require('../globals');
const db = globals.db;
const Random = require('random');
module.exports = {
name: 'parry',
@ -15,90 +10,76 @@ module.exports = {
needs_args: true,
async exec(message, args) {
db.find({ user: message.author.tag }).then(docs => {
if (isEmpty(docs)) {
return message.reply(findMessage('NOENTRY'));
try {
db.find({
user: message.author.tag,
}, function(err, docs) {
if (docs.length === 0) {
return message.reply(globals.Replies.find(r => r.id === 'NOENTRY').string);
}
else {
Random.use(message.author.tag);
const Player = docs[0].character;
const Weapon = Weapons.find(w => w.id === args[0].toLowerCase());
if (!Weapon) {
return message.reply(findMessage('NO_SUCH_WEAPON'));
}
const Weapon = globals.Weapons.find(w => w.id === args[0].toLowerCase());
if(!Weapon) { return message.reply(globals.Replies.find(r => r.id === 'NO_SUCH_WEAPON').string);}
if (!MeleeWeapons.find(MeleeWeapon => MeleeWeapon.id === Weapon.id)) {
return message.reply(findMessage('PARRY_WRONG_WEAPON'));
if(!globals.MeleeWeapons.find(MeleeWeapon => MeleeWeapon.id === Weapon.id)) {
return message.reply(globals.Replies.find(r => r.id === 'PARRY_WRONG_WEAPON').string);
}
const CombatTechnique = CombatTechniques.find(
technique => technique.id === Weapon.combattechnique
);
const PlayerCombatTechnique = Player.combattechniques.find(
technique => technique.id === CombatTechnique.id
);
const CombatTechnique = globals.CombatTechniques.find(technique => technique.id === Weapon.combattechnique);
let PlayerCombatTechnique = Player.combattechniques.find(technique => technique.id === CombatTechnique.id);
let CombatTechniqueValue = null;
if (PlayerCombatTechnique) {
CombatTechniqueValue = PlayerCombatTechnique.level;
}
if (!CombatTechniqueValue) {
CombatTechniqueValue = 6;
}
if (PlayerCombatTechnique) { CombatTechniqueValue = PlayerCombatTechnique.level; }
if(!CombatTechniqueValue) { CombatTechniqueValue = 6; }
let ParryValue = Math.ceil(CombatTechniqueValue/2);
CombatTechniqueValue.Leiteigenschaft.forEach( Property => {
const Attribute = Werte.find(a => a.kuerzel === Property.id);
ParryValue += Math.floor(
(Player.attributes.find(a => a.id === Attribute).level - 8) / 3
);
let Attribute = globals.Werte.find(a => a.kuerzel === Property.id);
ParryValue += Math.floor((Player.attributes.find(a => a.id === Attribute).level - 8)/3);
});
ParryValue += Weapon.pa_mod;
const dice = [];
const Bonus = parseInt(args[1], 10) || 0;
const Comparison = Math.floor(ParryValue + Bonus);
let dice = [];
let Bonus = 0;
if(args[1] && !isNaN(parseInt(args[1]))) { Bonus = parseInt(args[1]); }
let Comparison = Math.floor(ParryValue + Bonus);
let Patzer = false;
let Critical = false;
let Ok = false;
for (let i = 0; i < 2; i += 1) {
for (let i = 0; i < 2; i++) {
dice.push(Random.int(1,20));
}
// If there is a cleaner way to do these checks, I'm all into it.
if (dice[0] === 1 && dice[1] <= Comparison) {
Critical = true;
Ok = true;
} else if (dice[0] <= Comparison && !Critical) {
Ok = true;
dice.pop();
} else if (dice[0] === 20 && dice[1] > Comparison) {
Patzer = true;
} else if (dice[0] > Comparison) {
dice.pop();
}
if((dice[0] == 1) && dice[1] <= Comparison) { Critical = true; Ok = true; }
else if(dice[0] <= Comparison && !Critical) { Ok = true; dice.pop(); }
else if((dice[0] == 20) && dice[1] > Comparison) { Patzer = true; }
else if(dice[0] > Comparison ) { dice.pop(); }
let Reply = `Du versuchst, mit ${Weapon.name} zu parieren.\n`;
Reply += `Dein Paradewert für ${CombatTechnique.name} ist ${Math.floor(
ParryValue - Weapon.pa_mod
)}. (Waffe ${Weapon.pa_mod})\n`;
Reply += `Deine 🎲: ${dice.join(', ')}\n\n`;
let Reply = 'Du versuchst, mit ' + globals.Declination[Weapon.article] + ' ' + Weapon.name + ' zu parieren.\n';
Reply += 'Dein Paradewert für ' + CombatTechnique.name + ' ist ' + Math.floor(ParryValue - Weapon.pa_mod) + '. (Waffe: ' + Weapon.pa_mod + ')\n';
Reply += 'Deine 🎲: ` ' + dice.join(', ') + ' `.\n\n';
if(!Ok) {
Reply += findMessage('PARRY_FAIL');
if (Patzer) {
Reply += findMessage('PARRY_CRIT_FAIL');
}
} else {
if (Critical) {
Reply += findMessage('PARRY_CRIT_SUCCESS');
}
if (!Critical) {
Reply += findMessage('PARRY_SUCCESS');
Reply += globals.Replies.find(reply => reply.id === 'PARRY_FAIL').string;
if(Patzer) { Reply += globals.Replies.find(reply => reply.id === 'PARRY_CRIT_FAIL').string; }
}
else {
if(Critical) { Reply += globals.Replies.find(reply => reply.id === 'PARRY_CRIT_SUCCESS').string; }
if(!Critical) { Reply += globals.Replies.find(reply => reply.id === 'PARRY_SUCCESS').string; }
}
return message.reply( Reply );
}
});
}
catch (e) {
throw e;
}
},
};

View File

@ -1,20 +1,17 @@
const { findMessage }= require('@dsabot/findMessage');
const { db } = require('../globals');
const globals = require('../globals');
const db = globals.db;
module.exports = {
name: 'remove',
description:
'Löscht deinen Charakter aus der Datenbank. Sinnvoll, wenn du mir eine neue zusenden möchtest.',
description: 'Löscht deinen Charakter aus der Datenbank. Sinnvoll, wenn du mir eine neue zusenden möchtest.',
aliases: [],
usage: '',
needs_args: false,
// eslint-disable-next-line no-unused-vars
async exec(message) {
db.remove({ user: message.author.tag })
.then(() => message.reply(findMessage('DELETED_DATA')))
.catch(err => {
message.reply(findMessage('ERROR'));
throw new Error(err);
async exec(message, args) {
db.remove({
user: message.author.tag,
}, {}, function(err, numRemoved) {
return message.reply(findMessage('DELETED_DATA'));
});
},
};

View File

@ -1,28 +1,24 @@
// eslint-disable-next-line no-unused-vars
const globals = require('../globals');
const { roll } = require('@dsabot/Roll');
const { findMessage }= require('@dsabot/findMessage');
const { DiceRegex } = require('../globals');
module.exports = {
name: 'roll',
description:
'Lass die Würfel rollen. Benötigt wird die Anzahl sowie die Augenzahl auf den Würfeln.',
description: 'Lass die Würfel rollen. Benötigt wird die Anzahl sowie die Augenzahl auf den Würfeln.',
aliases: ['r'],
usage: '<Anzahl> w <Augenzahl>',
needs_args: true,
async exec(message, args) {
const params = args.join('').split(DiceRegex);
let params = args.join('').split(globals.DiceRegex);
if ( params.length >= 2 ) {
const Bonus = parseInt(params[2], 10) || 0;
const numberOfDice = parseInt(params[0], 10);
const diceValues = parseInt(params[1], 10);
const Bonus = parseInt(params[2]) || 0;
const numberOfDice = parseInt( params[0] );
const diceValues = parseInt( params[1] );
const result = roll( numberOfDice, diceValues, message.author.tag );
const total = Bonus ? Bonus + result.sum : result.sum;
message.reply(
`${findMessage('ROLL')} \` ${result.dice.join(' `, ` ')} \`` +
` (Gesamt: ${result.sum}${Bonus ? `+${Bonus}=${total}` : ``})`
);
let total = (Bonus ? Bonus + result.sum : result.sum)
message.reply(`${findMessage('ROLL')} ${result.dice.join(', ')} `+
`(Gesamt: ${result.sum}${Bonus ? `+${Bonus}=${total}` : ``})` );
}
},
};

View File

@ -1,8 +1,8 @@
// eslint-disable-next-line no-unused-vars
const globals = require('../globals');
const Discord = require('discord.js');
const db = globals.db;
const { findMessage }= require('@dsabot/findMessage');
const { isEmpty } = require('@dsabot/isEmpty');
const { db } = require('../globals');
module.exports = {
name: 'show',
@ -11,29 +11,31 @@ module.exports = {
usage: '',
needs_args: false,
async exec(message) {
db.find({ user: message.author.tag })
.then(docs => {
if (isEmpty(docs)) {
async exec(message, args) {
try {
db.find({
user: message.author.tag,
}, function(err, docs) {
if (docs.length === 0) {
return message.reply(findMessage('NOENTRY'));
}
else {
const Character = docs[0].character;
const Gender = Character.sex === 'female' ? '♀️' : '';
let Gender;
if (Character.sex == 'female') { Gender = ''; }
else { Gender = '♂️'; }
const Reply = new Discord.MessageEmbed();
Reply.setColor('#0099ff');
Reply.setTitle(`${Gender} ${Character.name}`);
Reply.setDescription(
`${Character.age} Jahre, ${Character.race}/${Character.culture}`
);
Reply.setDescription(`${Character.age} Jahre, ${Character.race}/${Character.culture}`);
Reply.addField(Character.professionname, Character.xp.startinglevel);
return message.reply(Reply);
})
.catch(err => {
message.reply(findMessage('ERROR'));
throw new Error(err);
message.reply( Reply );
}
});
}
catch (e) {
throw e;
}
},
};

View File

@ -1,8 +1,7 @@
const globals = require('../globals');
const db = globals.db;
const { findMessage } = require('@dsabot/findMessage');
const { getSkill } = require('@dsabot/getSkill');
const { isEmpty } = require('@dsabot/isEmpty');
const { db } = require('../globals');
module.exports = {
name: 'skill',
description: 'Zeigt dir deinen Fertigkeitswert im jeweiligen Talent.',
@ -11,9 +10,8 @@ module.exports = {
needs_args: true,
async exec(message, args) {
db.find({ user: message.author.tag })
.then(docs => {
if (isEmpty(docs)) {
db.find({ user: message.author.tag }, (err, docs) => {
if (docs.length === 0) {
return message.reply(findMessage('NOENTRY'));
}
const Skill = getSkill({ Character: docs[0].character, args: args });
@ -21,10 +19,6 @@ module.exports = {
return message.reply(findMessage('TALENT_UNKNOWN'));
}
return message.reply(`Du hast folgenden Wert in **${Skill.Name}**: ${Skill.Level}`);
})
.catch(err => {
message.reply(findMessage('ERROR'));
throw new Error(err);
});
},
};

View File

@ -1,31 +1,9 @@
//const globals = require('../globals');
const globals = require('../globals');
const db = globals.db;
const Discord = require('discord.js');
const { findMessage } = require('@dsabot/findMessage');
const { getSpell } = require('@dsabot/getSpell');
const { db } = require('../globals');
const { isEmpty } = require('@dsabot/isEmpty');
const ReplySpellList = (SpellList = []) => {
if (isEmpty(SpellList)) return findMessage('NO_SPELLS');
return `${SpellList.map(s => `${s.Name} (${s.Level})`).join('\n')}`;
};
const ReplySpell = (Spell = {}) => {
if (isEmpty(Spell)) return null;
return `Deine Werte für ${Spell.Name} (${Spell.Level}) sind:
${Spell.Attributes.map(attribute => `${attribute.Name}: ${attribute.Level}`).join(' ')}
`;
};
const createSpellList = (Character = {}) => {
if (!Character || !Character.hasOwnProperty('spells')) return null;
const SpellList = [];
Character.spells.forEach(spell =>
SpellList.push(getSpell({ Character: Character, spell_name: spell.id }))
);
return SpellList.filter(value => value !== undefined && value !== null); //?+
};
module.exports = {
name: 'spells',
description: 'Zeigt dir deinen Fertigkeitswert im jeweiligen Magietalent.',
@ -34,14 +12,12 @@ module.exports = {
needs_args: false,
async exec(message, args) {
db.find({ user: message.author.tag })
.then(docs => {
db.find({ user: message.author.tag }, (err, docs) => {
if (docs.length === 0) {
return message.reply(findMessage('NOENTRY'));
}
const Character = docs[0].character;
if (!Character.hasOwnProperty('spells'))
return message.reply(findMessage('NO_SPELLS'));
Character = docs[0].character;
if (!Character.hasOwnProperty('spells')) return message.reply(findMessage('NO_SPELLS'));
if (args.length === 0) {
const Embed = new Discord.MessageEmbed()
.setColor('#0099ff')
@ -56,10 +32,26 @@ module.exports = {
});
if (!Spell) return message.reply(findMessage('SPELL_UNKNOWN'));
return message.reply(ReplySpell(Spell));
})
.catch(err => {
message.reply(findMessage('ERROR'));
throw new Error(err);
});
},
};
const ReplySpellList = (SpellList = []) => {
if (!SpellList) return findMessage('NO_SPELLS');
return `${SpellList.map(s => `${s.Name} (${s.Level})`).join('\n')}`;
};
const ReplySpell = (Spell = {}) => {
if (!Spell) return;
return `Deine Werte für ${Spell.Name} (${Spell.Level}) sind:
${Spell.Attributes.map(attribute => `${attribute.Name}: ${attribute.Level}`).join(' ')}
`;
};
const createSpellList = (Character = {}) => {
if (!Character || !Character.hasOwnProperty('spells')) return;
let SpellList = [];
Character.spells.forEach(spell => SpellList.push(getSpell({ Character: Character, spell_name: spell.id })));
return SpellList.filter(value => value !== undefined); //?+
};

View File

@ -1,13 +1,12 @@
const globals = require('../globals');
const Discord = require('discord.js');
const db = globals.db;
const { roll } = require('@dsabot/Roll');
const { findMessage } = require('@dsabot/findMessage');
const { getSkill } = require('@dsabot/getSkill');
const { CalculateQuality } = require('@dsabot/CalculateQuality');
const { CompareResults } = require('@dsabot/CompareResults');
const { CreateResultTable } = require('@dsabot/CreateResultTable');
const { isString } = require('@dsabot/isString');
const { db } = require('../globals');
module.exports = {
name: 'talent',
description:
@ -18,12 +17,11 @@ module.exports = {
usage: '<Talent> [<-Erschwernis> / <+Erleichterung>]',
needs_args: true,
async exec(message, args) {
db.find({ user: message.author.tag })
.then(docs => {
db.find({ user: message.author.tag }, (err, docs) => {
if (docs.length === 0) {
return message.reply(findMessage('NOENTRY'));
}
if (!isString(args[0])) {
if (!isNaN(args[0])) {
return message.reply(findMessage('WRONG_ARGUMENTS'));
}
@ -32,16 +30,10 @@ module.exports = {
return message.reply(findMessage('TALENT_UNKNOWN'));
}
const { Attributes } = Skill;
const Attributes = Skill.Attributes;
const DiceThrow = roll(3, 20, message.author.tag).dice;
const Bonus = parseInt(args[1], 10) || 0;
const {
Passed,
CriticalHit,
Fumbles,
PointsUsed,
PointsRemaining,
} = CompareResults(
const Bonus = parseInt(args[1]) || 0;
let { Passed, CriticalHit, Fumbles, PointsUsed, PointsRemaining } = CompareResults(
DiceThrow,
Attributes.map(attr => attr.Level),
Bonus,
@ -75,25 +67,19 @@ module.exports = {
} else if (Passed < 3) {
Reply.addFields({
name: findMessage('TITLE_FAILURE'),
value: `${
Passed === 0 ? 'Keine Probe' : `nur ${Passed}/3 Proben`
} erfolgreich. 😪`,
value: `${Passed === 0 ? 'Keine Probe' : `nur ${Passed}/3 Proben`} erfolgreich. 😪`,
inline: false,
});
} else {
Reply.addFields({
name: findMessage('TITLE_SUCCESS'),
value: `Dein verbleibender Bonus: ${PointsRemaining}/${
Skill.Level
} (QS${CalculateQuality(PointsRemaining)})`,
value: `Dein verbleibender Bonus: ${PointsRemaining}/${Skill.Level} (QS${CalculateQuality(
PointsRemaining
)})`,
inline: false,
});
}
return message.reply(Reply);
})
.catch(err => {
message.reply(findMessage('ERROR'));
throw new Error(err);
message.reply(Reply);
});
},
};

View File

@ -1,23 +1,6 @@
const globals = require('../globals');
const Discord = require('discord.js');
const { Capitalize } = require('@dsabot/Capitalize');
const { TalentKategorien } = require('../globals');
const { Talente } = require('../globals');
const GenerateTalentList = () => {
const TalentList = [];
TalentKategorien.forEach(Category => {
TalentList.push({
Category: Category,
Talents: Talente.filter(
Talent => Talent.categoryid === TalentKategorien.indexOf(Category)
)
.map(Talent => Capitalize(Talent.id))
.sort(),
});
});
return TalentList.sort();
};
module.exports = {
name: 'talents',
@ -26,17 +9,34 @@ module.exports = {
usage: '',
needs_args: false,
async exec(message) {
async exec(message, args) {
const Embed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle('Talentübersicht')
.setDescription('Das sind die Talente, die ich kenne:');
const TalentList = GenerateTalentList();
TalentList.forEach(Talent => {
for (let Talent of GenerateTalentList()) {
Embed.addField(Talent.Category, Talent.Talents.join('\n'), true);
});
return message.author.send(Embed);
}
message.author.send(
Embed,
);
},
};
const GenerateTalentList = () => {
const Categories = globals.TalentKategorien;
const Talents = globals.Talente;
const TalentList = [];
Categories.forEach(Category => {
TalentList.push({
Category: Category,
Talents: Talents.filter(Talent => Talent.categoryid === Categories.indexOf(Category))
.map(Talent => Capitalize(Talent.id))
.sort()
});
});
return TalentList.sort();
};

View File

@ -1,66 +1,85 @@
// eslint-disable-next-line no-unused-vars
const Random = require('random');
const globals = require('../globals');
const Discord = require('discord.js');
const { roll } = require('@dsabot/Roll');
const { findMessage }= require('@dsabot/findMessage');
const { CompareResults } = require('@dsabot/CompareResults');
module.exports = {
name: 'tp',
description:
'Du machst eine Fertigkeitsprobe.\n' +
description: 'Du machst eine Fertigkeitsprobe.\n' +
' Es werden drei Würfel auf deine Eigenschaftswerte geworfen. Hast du Boni auf dein Talent und/oder' +
' ist der Wurf erleichtert oder erschwert, wird dies in die Berechnung einbezogen.',
aliases: ['talentprobe'],
usage:
'<Eigenschaftswert1> <Eigenschaftswert2> <Eigenschaftswert3> [<Fertigkeitswert>] [<-Erschwernis> / <+Erleichterung>]',
usage: '<Eigenschaftswert1> <Eigenschaftswert2> <Eigenschaftswert3> [<Fertigkeitswert>] [<-Erschwernis> / <+Erleichterung>]',
needs_args: true,
async exec(message, args) {
if (Number.isNaN(args[0])) {
if(isNaN(args[0])) {
return message.reply(findMessage('WRONG_ARGUMENTS'));
}
const Bonus = parseInt(args[3], 10) || 0;
const Erschwernis = parseInt(args[4], 10) || 0;
//Random.use(message.author.tag);
//const dice = [];
let bonus = 0;
let bonus_orig = 0;
let erschwernis = 0;
if (args[3]) {
bonus_orig = parseInt(args[3]);
bonus = bonus_orig;
}
if (args[4]) {
erschwernis = parseInt(args[4]);
}
/*for (let i = 1; i <= 3; i++) {
roll.push(Random.int(1, 20));
}*/
const dice = roll(3,20,message.author.tag).dice;
const { dice } = roll(3, 20, message.author.tag);
const { Passed, CriticalHit, Fumbles, PointsRemaining } = CompareResults(
dice,
[parseInt(args[0], 10), parseInt(args[1], 10), parseInt(args[2], 10)],
Bonus,
Erschwernis
);
let ok = 0;
let patzer = 0;
let crit = 0;
for (let i = 0; i < 3; i++) {
if (Math.floor(parseInt(args[i]) + parseInt(erschwernis)) >= dice[i]) {
ok++;
} else if (
Math.floor(parseInt(args[i]) + parseInt(bonus) + parseInt(erschwernis)) >= dice[i]) {
ok++;
bonus = bonus - (dice[i] - parseInt(erschwernis) - parseInt(args[i]));
}
if (dice[i] == 1) {crit++;}
if (dice[i] == 20) {patzer++;}
}
const Reply = new Discord.MessageEmbed();
Reply.setTitle(`${findMessage('ROLL')} \` ${dice.join(' ` ` ')} \``);
if (Fumbles >= 2) {
Reply.setTitle(`${findMessage('ROLL')} ${dice.join(', ')}.`);
if (patzer >= 2) {
Reply.setColor('#900c3f');
Reply.addFields({
name: findMessage('TITLE_CRIT_FAILURE'),
value: findMessage('MSG_CRIT_FAILURE'),
inline: false,
inline: false
});
} else if (CriticalHit >= 2) {
} else if (crit >= 2) {
Reply.setColor('#1E8449');
Reply.addFields({
name: findMessage('TITLE_CRIT_SUCCESS'),
value: findMessage('MSG_CRIT_SUCCESS'),
inline: false,
inline: false
});
} else if (Passed < 3) {
} else if (ok < 3) {
Reply.addFields({
name: findMessage('TITLE_FAILURE'),
value: `${Passed ? `Nur ${Passed}/3 Proben` : `Keine Probe`} erfolgreich. 😪`,
inline: false,
value: 'Nur ' + ok + '/3 Proben erfolgreich. 😪',
inline: false
});
} else {
Reply.addFields({
name: findMessage('TITLE_SUCCESS'),
value: `${Passed}/3 Proben erfolgreich. Dein Bonus: ${PointsRemaining}/${Bonus}`,
inline: false,
value: ok + '/3 Proben erfolgreich. Dein Bonus: ' + bonus + '/' + bonus_orig + '.',
inline: false
});
}
return message.reply(Reply);
},
message.reply(Reply);
}
};

View File

@ -1,20 +1,7 @@
const globals = require('../globals');
const Discord = require('discord.js');
const { Capitalize } = require('@dsabot/Capitalize');
const { CombatTechniques } = require('../globals');
const { Weapons } = require('../globals');
const GenerateWeaponList = () => {
const WeaponList = [];
CombatTechniques.forEach(Technique => {
WeaponList.push({
Technique_Name: Technique.name,
Weapons: Weapons.filter(Weapon => Weapon.combattechnique === Technique.id).map(Weapon =>
Capitalize(Weapon.id)
),
});
});
return WeaponList.sort();
};
module.exports = {
name: 'weapons',
@ -23,16 +10,32 @@ module.exports = {
usage: '',
needs_args: false,
async exec(message) {
async exec(message, args) {
const Embed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle('Waffenübersicht')
.setDescription('Folgende Waffen können für einen Angriff genutzt werden:');
const WeaponList = GenerateWeaponList();
WeaponList.forEach(Technique => {
for (let Technique of GenerateWeaponList()) {
Embed.addField(Technique.Technique_Name, Technique.Weapons.join('\n'), true);
});
return message.author.send(Embed);
}
message.author.send(
Embed,
);
},
};
const GenerateWeaponList = () => {
let WeaponList = [];
const Techniques = globals.CombatTechniques;
const Weapons = globals.Weapons;
Techniques.forEach(Technique => {
WeaponList.push({
Technique_Name: Technique.name,
Weapons: Weapons.filter(Weapon => Weapon.combattechnique === Technique.id)
.map(Weapon => Capitalize(Weapon.id))
});
});
return WeaponList.sort();
};

0
data/dsabot.db Normal file
View File

View File

@ -1,9 +1,15 @@
const CalculateQuality = (PointsAvailable = 0) => {
if (PointsAvailable <= 3) return 1;
if (PointsAvailable > 3 && PointsAvailable <= 6) return 2;
if (PointsAvailable > 6 && PointsAvailable <= 9) return 3;
if (PointsAvailable > 9 && PointsAvailable <= 12) return 4;
if (PointsAvailable > 12 && PointsAvailable <= 15) return 5;
if (PointsAvailable <= 3)
return 1;
else if (PointsAvailable > 3 && PointsAvailable <= 6)
return 2;
else if (PointsAvailable > 6 && PointsAvailable <= 9)
return 3;
else if (PointsAvailable > 9 && PointsAvailable <= 12)
return 4;
else if (PointsAvailable > 12 && PointsAvailable <= 15)
return 5;
else if (PointsAvailable > 15)
return 6;
};
module.exports = { CalculateQuality };

View File

@ -1,3 +1,5 @@
const Capitalize = (Word = 'none') => `${Word[0].toUpperCase() + Word.substring(1)}`;
const Capitalize = (Word = 'none') => {
return Word[0].toUpperCase() + Word.substring(1);
};
module.exports = { Capitalize };

6
functions/Compare.js Normal file
View File

@ -0,0 +1,6 @@
const Compare = () => {
return { result };
};
module.exports = { Compare };

View File

@ -7,35 +7,39 @@
* @param {BigInt} Bonus=0
* @param {BigInt} PointsRemaining=0
*/
const CompareResults = (Throws = [], AttributeLevels = [8, 8, 8], Bonus = 0, Points = 0) => {
const CompareResults = (
Throws = [],
AttributeLevels = [8, 8, 8],
Bonus = 0,
PointsRemaining = 0
) => {
let Passed = 0;
let Fumbles = 0;
let CriticalHit = 0;
let PointsRemaining = Points;
const AllPointsUsed = [];
let AllPointsUsed = [];
Throws.forEach((Throw, key) => {
for (let i = 0; i < Throws.length; i++) {
let PointsUsed = 0;
const AttributeLevel = AttributeLevels.find((v, k) => key === k);
if (Math.floor(AttributeLevel + Bonus) >= Throw) {
Passed += 1;
} else if (Math.floor(AttributeLevel + PointsRemaining + Bonus) >= Throw) {
Passed += 1;
PointsUsed = Throw - Bonus - AttributeLevel;
if (Math.floor(AttributeLevels[i] + Bonus) >= Throws[i]) {
Passed++;
} else if (Math.floor(AttributeLevels[i] + PointsRemaining + Bonus) >= Throws[i]) {
Passed++;
PointsUsed = Throws[i] - Bonus - AttributeLevels[i];
PointsRemaining -= PointsUsed;
} else {
// We need to use all our points, so that next die/dice
// would not return a 'Passed'.
PointsUsed = PointsRemaining;
PointsRemaining -= PointsUsed;
}
if (Throw === 1) {
CriticalHit += 1;
if (Throws[i] == 1) {
CriticalHit++;
}
if (Throw === 20) {
Fumbles += 1;
if (Throws[i] == 20) {
Fumbles++;
}
AllPointsUsed.push(PointsUsed);
});
}
return {
Passed: Passed,
CriticalHit: CriticalHit,

View File

@ -1,3 +1,5 @@
const CountOccurences = (arr, value) => arr.filter(v => v === value).length;
const CountOccurences = (arr, value) => {
return arr.filter((v) => (v === value)).length;
};
module.exports = { CountOccurences };

View File

@ -1,13 +1,10 @@
function f(n) {
return (n > 0 ? '+' : '') + n;
}
const CreateResultTable = ({
Attributes: Attributes,
Throws: Throws,
PointsUsed: PointsUsed,
Bonus: Bonus = 0,
}) => `
}) => {
return `
\`\`\`
${''.padEnd(15)} ${Attributes.map(attr => `${attr.Name}`.padStart(6)).join('\t|\t')}\t|
${'Dein Wert'.padEnd(15)} ${Attributes.map(attr =>
@ -22,5 +19,10 @@ const CreateResultTable = ({
.padStart(6)}
\`\`\`
`;
};
const f = n => {
return (n > 0 ? '+' : '') + n;
};
module.exports = { CreateResultTable, f };

View File

@ -1,12 +1,13 @@
const Random = {int, use};
function int (min, max) {
if (!min || !max) {
return undefined;
}
if (!min || !max) { return; }
//return Math.floor(Math.random() * (Math.floor(max) - Math.ceil(min))) + min;
return Math.floor(Math.random() * (Math.floor(max) - Math.ceil(min) + 1)) + min;
}
function use() {
function use (str) {
return true;
}
const Random = { int, use };
module.exports = { Random };

View File

@ -1,17 +1,18 @@
const { Random } = require('@dsabot/Random');
const { Random } = require("@dsabot/Random");
//const Random = require('random');
const roll = (numberOfDice, numberOfEyes, tag) => {
const dice = [];
let dice = [];
let sum = 0;
if(tag) {
Random.use(tag);
}
for (let i = 0; i < numberOfDice; i += 1) {
const result = Random.int(1, numberOfEyes);
for (let i = 0; i<numberOfDice; i++ ) {
let result = Random.int(1,numberOfEyes);
dice.push(result);
sum += result;
}
return { dice, sum };
};
module.exports = { roll };

View File

@ -1,5 +1,7 @@
const { Replies } = require('../globals');
const globals = require('../globals');
const findMessage = value => Replies.find(r => r.id === value).string;
const findMessage = (value) => {
return globals.Replies.find(r => r.id === value).string;
};
module.exports = { findMessage };

View File

@ -1,13 +1,14 @@
const { Werte } = require('../globals');
const globals = require('../globals');
const getAttributeLevels = (Attributes = [], Character = {}) => {
const AttributeList = [];
Attributes.forEach(Attribute => {
const { id } = Werte.find(att => att.kuerzel === Attribute);
const { level } = Character.attributes.find(att => att.id === id);
AttributeList.push({ Name: Attribute, Level: level });
});
let AttributeId;
let AttributeLevel;
let AttributeList = [];
for (let Attribute of Attributes) {
AttributeId = globals.Werte.find((attribute) => attribute.kuerzel === Attribute).id;
AttributeLevel = Character.attributes.find((att) => att.id === AttributeId).level;
AttributeList.push({ Name: Attribute, Level: AttributeLevel });
}
return AttributeList;
};
module.exports = { getAttributeLevels};

View File

@ -1,20 +1,28 @@
require('module-alias/register');
const { getAttributeLevels } = require('@dsabot/getAttributeLevels');
const Chants = require('@Lib/Chants.json');
const { isEmpty } = require('@dsabot/isEmpty');
const getChant = ({ Character: Character = [], chant_name: chantName = '' } = {}) => {
if (!Character.hasOwnProperty('chants')) return null;
const chantEntry =
Chants.find(chant => chant.id.toLowerCase() === chantName.toLowerCase()) ||
Chants.find(chant => chant.name.toLowerCase() === chantName.toLowerCase());
const getChant = ({ Character: Character = [], chant_name: chant_name = '' } = {}) => {
//if (!Character.hasOwnProperty('chants')) return;
let chant_entry =
Chants.find(chant => chant.id.toLowerCase() === chant_name.toLowerCase()) ||
Chants.find(chant => chant.name.toLowerCase() === chant_name.toLowerCase());
// let us filter out blessings.
if (isEmpty(chantEntry)) return null;
const Chant = Character.chants.find(chant => chant.id === chantEntry.id); // || null;
const Level = Chant.hasOwnProperty('level') ? Chant.level : 0;
const Attributes = getAttributeLevels(chantEntry.attributes, Character);
if (!chant_entry) {
console.log(`getChant() Did not find entry for ${chant_name}`);
return;
}
return { Name: chantEntry.name, Level: Level, Attributes: Attributes };
let Level = 0; // This is the minimum attributes value.
let Chant = Character.chants.find(chant => chant.id === chant_entry.id) || {};
if (Chant && Chant.hasOwnProperty('level')) {
Level = Chant.level || 0;
}
let Attributes = getAttributeLevels(chant_entry.attributes, Character);
return {
Name: chant_entry.name,
Level: Level,
Attributes: Attributes,
};
};
module.exports = { getChant };

View File

@ -1,22 +1,22 @@
const globals = require('../globals');
const { getAttributeLevels } = require('@dsabot/getAttributeLevels');
const { Talente } = require('../globals');
const getSkill = ({ Character: Character = [], args: args = [] } = {}) => {
const skillEntry =
Talente.find(skill => skill.id.toLowerCase() === args[0].toLowerCase()) ||
Talente.find(skill => skill.name.toLowerCase() === args[0].toLowerCase());
let skill_entry =
globals.Talente.find(skill => skill.id.toLowerCase() === args[0].toLowerCase()) ||
globals.Talente.find(skill => skill.name.toLowerCase() === args[0].toLowerCase());
if (!skillEntry) {
return null;
if (!skill_entry) {
return;
}
let Level = 0; // This is the minimum attributes value.
const cSkill = Character.skills.find(skill => skill.id === skillEntry.id) || null;
let cSkill = Character.skills.find(skill => skill.id === skill_entry.id) || {};
if (cSkill) {
Level = cSkill.level || 0;
}
const Name = Talente.find(skill => skill.id === skillEntry.id).name;
const Attributes = getAttributeLevels(skillEntry.values, Character);
let Name = globals.Talente.find(skill => skill.id === skill_entry.id).name;
let Attributes = getAttributeLevels(skill_entry.values, Character);
return {
Name: Name,

View File

@ -1,21 +1,30 @@
const { getAttributeLevels } = require('@dsabot/getAttributeLevels');
const Spells = require('@Lib/Spells.json');
const { isEmpty } = require('@dsabot/isEmpty');
const getSpell = ({ Character: Character = [], spell_name: spellName = '' } = {}) => {
if (!Character.hasOwnProperty('spells')) return null;
const spellEntry =
Spells.find(spell => spell.id.toLowerCase() === spellName.toLowerCase()) ||
Spells.find(spell => spell.name.toLowerCase() === spellName.toLowerCase());
const getSpell = ({ Character: Character = [], spell_name: spell_name = '' } = {}) => {
const spell_entry =
Spells.find(spell => spell.id.toLowerCase() === spell_name.toLowerCase()) ||
Spells.find(spell => spell.name.toLowerCase() === spell_name.toLowerCase());
if (isEmpty(spellEntry)) return null;
if (!spell_entry) {
console.log(`getSpell() did not find entry for ${spell_name}`);
return;
}
const Spell = Character.spells.find(spell => spell.id === spellEntry.id); //?+
const Level = Spell.hasOwnProperty('level') ? Spell.level : 0;
let Level = 0; // This is the minimum attributes value.
if (!Character.hasOwnProperty('spells')) return;
let Spell = Character.spells.find(spell => spell.id === spell_entry.id) || {}; //?+
if (Spell && Spell.hasOwnProperty('level')) {
Level = Spell.level || 0;
}
let ModifiedBy = spell_entry.modified_by;
let Attributes = getAttributeLevels(spell_entry.attributes, Character);
const ModifiedBy = spellEntry.modified_by;
const Attributes = getAttributeLevels(spellEntry.attributes, Character);
return { Name: spellEntry.name, Level: Level, Attributes: Attributes, ModifiedBy: ModifiedBy };
return {
Name: spell_entry.name,
Level: Level,
Attributes: Attributes,
ModifiedBy: ModifiedBy,
};
};
module.exports = { getSpell };

View File

@ -1,6 +0,0 @@
function isEmpty(document = {}) {
if (!document) return true;
if (document.length === 0) return true;
return Object.keys(document).length === 0 ? true : false;
}
module.exports = { isEmpty };

View File

@ -1,4 +0,0 @@
function isString(str) {
return typeof str === 'string' || str instanceof String ? true : false;
}
module.exports = { isString };

View File

@ -1,12 +1,15 @@
const Discord = require('discord.js');
const Datastore = require('nedb-promises')
const db = Datastore.create({
const Datastore = require('nedb'),
db = new Datastore({
filename: 'data/dsabot.db',
autoload: false,
autoload: true,
});
const MessageEmbed = new Discord.MessageEmbed();
const DiceRegex = /\s?[DdWw]\s?|(?=-|\+)/;
const money = [{
'GD': 'Golddukaten',
'ST': 'Silbertaler',
}];
const DiceRegex = /\s?[DdWw]\s?|(?=\-|\+)/;
const Coin = ['Kopf', 'Zahl'];
const Werte = [
{ id: 'mut', kuerzel: 'MU', name: 'Mut' },
@ -144,8 +147,7 @@ const Replies = [
{ id: 'NO_CHANTS', string: 'Du kennst keine Liturgien.' },
{ id: 'CHANTS_TITLE', string: 'Liturgien'},
{ id: 'CHANTS_DESCRIPTION', string: 'Folgende Liturgien beherrschst du:' },
{ id: 'CHANT_UNKNOWN', string: 'Diese Liturgie kenne ich nicht.' },
{ id: 'NO_CHARACTERS', string: 'Keine Benutzer auf dieser Liste gefunden.'}
{ id: 'CHANT_UNKNOWN', string: 'Diese Liturgie kenne ich nicht.'}
];
const Declination = ['dem', 'der', 'dem', '']; // Maskulinum, Feminimum, Neutrum, None
const Articles = ['Der','Die','Das',''];
@ -231,4 +233,12 @@ const RangedWeapons = [
];
const Weapons = MeleeWeapons.concat(RangedWeapons);
const Advantages = [
{}
];
const Disadvantages = [
{}
];
module.exports = { Werte, Talente, Coin, TalentKategorien, DiceRegex, Discord, MessageEmbed, db, Replies, MeleeWeapons, Weapons, RangedWeapons, CombatTechniques, Articles, Declination };

123
index.js
View File

@ -1,66 +1,85 @@
require('module-alias/register');
require('dotenv').config();
const fs = require('fs');
const got = require('got');
const Discord = require('discord.js');
const { findMessage } = require('@dsabot/findMessage');
const { db } = require('./globals');
db.load();
const fetch = require('node-fetch');
const globals = require('./globals');
const db = globals.db;
const cmdprefix = process.env.CMDPREFIX || '!';
const Discord = require('discord.js');
const client = new Discord.Client();
async function CreateFromFile(message, data) {
db.find({
user: message.author.tag,
}).then(docs => {
if (docs.length === 0) {
db.insert({ uid: `${message.author.id}`, user: message.author.tag, character: data })
.then(() => message.reply(findMessage('SAVED_DATA')))
.catch(e => {
console.log(e);
message.reply(findMessage('ERROR'));
});
}
});
}
async function commandHandler(message) {
if (message.attachments.size > 0 && message.channel.type === 'dm' && !message.author.bot) {
try {
got(message.attachments.first().url).then(data => CreateFromFile(message, data.body));
} catch (e) {
console.log(e);
return message.reply(findMessage('ERROR'));
}
} else {
if (!message.content.startsWith(cmdprefix) || message.author.bot) {
return null;
}
const args = message.content.slice(cmdprefix.length).split(' ');
const commandName = args.shift().toLowerCase();
const command =
client.commands.get(commandName) ||
client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName));
if (!command) return null;
if (command.needs_args && !args.length) {
return message.reply(
`${findMessage('TOO_FEW_ARGS')}\n${cmdprefix}${commandName} ${command.usage}`
);
}
command.exec(message, args);
}
return null;
}
client.commands = new Discord.Collection();
client.on('message', commandHandler);
client.login(process.env.BOT_TOKEN);
client.once('ready', () => {
console.log('Ready!');
});
const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
commandFiles.forEach(file => {
const command = require(`./commands/${file}`); // eslint-disable-line global-require, import/no-dynamic-require
const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
async function commandHandler(message) {
//console.log(`${new Date().toUTCString()} ${message.author.tag} (size: ${message.attachments.size})`);
if ((message.attachments.size > 0) && message.channel.type == 'dm' && !message.author.bot) {
try {
const response = await fetch(message.attachments.first().url);
const data = await validateJSON(response);
if (data) await CreateFromFile(message, data);
} catch (e) {
console.log(e);
return message.reply(globals.Replies.find(x => x.id === 'ERROR').string);
}
} else {
if (!message.content.startsWith(cmdprefix) || message.author.bot) {
return;
}
const args = message.content.slice(cmdprefix.length).split(' ');
const commandName = args.shift().toLowerCase();
//if (!client.commands.has(commandName)) return;
try {
const command = client.commands.get(commandName) || client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName));
if (!command) return;
if (command.needs_args && !args.length) {
return message.reply(
globals.Replies.find(x => x.id === 'TOO_FEW_ARGS').string +
cmdprefix + commandName + ' ' + command.usage
);
} else {
command.exec(message, args);
}
} catch (e) {
message.reply(globals.Replies.find(x => x.id === 'ERROR').string);
}
}
}
function validateJSON(body) {
try {
const data = body.json();
return data;
} catch (e) {
return null;
}
}
async function CreateFromFile(message, data) {
try {
db.find({
user: message.author.tag,
}, function (err, docs) {
if (docs.length === 0) {
db.insert({
user: message.author.tag,
character: data,
}, function (err, docs) {
message.reply(globals.Replies.find(r => r.id === 'SAVED_DATA').string);
});
}
});
} catch (e) {
throw e;
}
}

View File

@ -5,6 +5,6 @@ module.exports = {
'@Commands/(.*)': '<rootDir>/commands/$1',
'@Root/(.*)': '<rootDir>/$1',
'@data/(.*)': '<rootDir>/data/$i',
'@Lib/(.*)': '<rootDir>/lib/$i',
'@lib/(.*)': '<rootDir>/lib/$i',
},
};

View File

@ -7,10 +7,10 @@
"@data/*": ["./data/*"],
"@Commands/*": ["./commands/*"],
"@Lib/*": ["./lib/*"]
}
},
},
"exclude": ["node_modules"],
"typeAcquisition": {
"exclude": [ "dotenv", "source-map" ]
}
},
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

10570
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,13 +1,12 @@
{
"name": "dsabot",
"version": "1.6.6",
"version": "1.5.0",
"description": "",
"main": "index.js",
"scripts": {
"lint": "eslint commands/",
"preinstall": "npx npm-force-resolutions",
"start": "node index.js",
"test": "jest --collectCoverage"
"test": "jest"
},
"_moduleAliases": {
"@dsabot": "functions",
@ -19,43 +18,13 @@
"license": "ISC",
"dependencies": {
"discord.js": "^12.5.3",
"dotenv": "^16.0.0",
"got": "^11.8.3",
"dotenv": "^8.2.0",
"module-alias": "^2.2.2",
"nedb-promises": "^6.0.3"
"nedb": "^1.8.0",
"node-fetch": "^2.6.1",
"random": "^3.0.6"
},
"devDependencies": {
"@types/jest": "^27.4.1",
"babel-jest": "^27.5.1",
"babel-plugin-module-resolver": "^4.1.0",
"babel-plugin-rewire": "^1.2.0",
"eslint": "^8.13.0",
"eslint-config-airbnb": "^19.0.2",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.0.0",
"jest": "^27.5.1"
},
"jest": {
"collectCoverage": true,
"collectCoverageFrom": [
"**/*.{js,jsx}",
"!**/node_modules/**",
"!**/vendor/**",
"!**/.github/**",
"!**/__tests__/**",
"!**/__mocks__/**"
],
"coveragePathIgnorePatterns": [
"/node_modules/",
"<rootDir>/__tests__/",
"<rootDir>/.github/",
"<rootDir>/coverage/",
"<rootDir>/__mocks__/"
],
"coverageDirectory": "coverage"
},
"resolutions": {
"normalize-url": ">=4.5.1",
"path-parse": ">=1.0.7"
"jest": "^26.6.3"
}
}

View File

@ -1,3 +0,0 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json"
}