refactoring (#4)

This commit is contained in:
2021-04-10 19:17:18 +02:00
committed by GitHub
parent 9cf66c7435
commit 24a07c4588
21 changed files with 240 additions and 173 deletions

2
.gitignore vendored
View File

@ -3,4 +3,6 @@ node_modules
.eslintrc.js .eslintrc.js
.eslintrc.json .eslintrc.json
.vscode .vscode
data/dsabot.db
data/data

View File

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

View File

@ -0,0 +1,10 @@
const Roll = require('@dsabot/Roll');
describe('Beware of a misunderstanding! A sequence of dice rolls', () => {
const expected = [1,2,3,4,5,6];
it('matches even with an unexpected number 7', () => {
expect(Roll(1,6)).not.toEqual(
expect.arrayContaining(expected),
);
});
});

View File

@ -1,6 +1,8 @@
const globals = require('../globals'); const globals = require('../globals');
const db = globals.db; const db = globals.db;
const Random = require('random'); const Random = require('random');
//const { roll } = require('@dsabot/Roll');
const { findMessage }= require('@dsabot/findMessage');
module.exports = { module.exports = {
name: 'attack', name: 'attack',
@ -15,7 +17,7 @@ module.exports = {
user: message.author.tag, user: message.author.tag,
}, function(err, docs) { }, function(err, docs) {
if (docs.length === 0) { if (docs.length === 0) {
return message.reply(globals.Replies.find(r => r.id === 'NOENTRY').string); return message.reply(findMessage('NOENTRY'));
} }
else { else {

View File

@ -1,4 +1,10 @@
const globals = require('../globals'); const globals = require('../globals');
const {
CountOccurences
} = require('@dsabot/CountOccurences');
const {
findMessage
} = require('@dsabot/findMessage');
const Random = require('random'); const Random = require('random');
const db = globals.db; const db = globals.db;
@ -15,47 +21,26 @@ module.exports = {
await db.find({ await db.find({
user: message.author.tag, user: message.author.tag,
}, async function(err, docs) { }, async function (err, docs) {
// user calls with text. need to gather info from database // user calls with text. need to gather info from database
if (isNaN(args[0])) { if (isNaN(args[0])) {
if (docs.length === 0) { HandleNamedAttributes();
message.reply(globals.Replies.find(r => r.id === 'NOENTRY').string); } else {
return;
}
else {
// try to get id of short formatted attributes.
if (args[0].length == 2) {
for (const i in globals.Werte) {
if (globals.Werte[i].kuerzel == args[0].toUpperCase()) {
attributename = globals.Werte[i].id;
}
}
}
else {
attributename = args[0].toLowerCase();
}
for (const i in docs[0].character.attributes) {
if (docs[0].character.attributes[i].id == attributename) level = docs[0].character.attributes[i].level;
}
}
}
else {
level = args[0]; level = args[0];
} }
Random.use(message.author.tag); Random.use(message.author.tag);
const countOccurrences = (arr, val) => arr.reduce((a, v) => (v === val ? a + 1 : a), 0);
const dice = []; const dice = [];
dice.push(Random.int(1, 20)); dice.push(Random.int(1, 20));
if (dice[0] == 1 || dice[0] == 20) { if (dice[0] == 1 || dice[0] == 20) {
dice.push(Random.int(1, 20)); dice.push(Random.int(1, 20));
} }
// handle crits // handle crits
if (countOccurrences(dice, 1) == 2) { if (CountOccurences(dice, 1) == 2) {
message.reply('Du hast einen kritischen Erfolg erzielt (' + dice.join(', ') + ')! 🎉🥳🎆'); message.reply('Du hast einen kritischen Erfolg erzielt (' + dice.join(', ') + ')! 🎉🥳🎆');
return; return;
} } else if (CountOccurences(dice, 20) == 2) {
else if (countOccurrences(dice, 20) == 2) {
message.reply('Du hast einen Patzer (' + dice.join(', ') + ')! 😭 Viel Erfolg beim nächsten mal!'); message.reply('Du hast einen Patzer (' + dice.join(', ') + ')! 😭 Viel Erfolg beim nächsten mal!');
return; return;
} }
@ -63,24 +48,47 @@ module.exports = {
if (attributename) { if (attributename) {
message.reply('Du hast die Probe auf ' + attributename + ' (Stufe ' + level + ') bestanden.\n' + message.reply('Du hast die Probe auf ' + attributename + ' (Stufe ' + level + ') bestanden.\n' +
'Deine 🎲: ' + dice.join(', ')); 'Deine 🎲: ' + dice.join(', '));
} } else {
else {
message.reply('Du hast die Probe (Stufe ' + level + ') bestanden.\n' + message.reply('Du hast die Probe (Stufe ' + level + ') bestanden.\n' +
'Deine 🎲: ' + dice.join(', ')); 'Deine 🎲: ' + dice.join(', '));
} }
} } else if (attributename) {
else if (attributename) {
message.reply('Du hast die Probe auf ' + attributename + ' (Stufe ' + level + ') leider nicht bestanden 😢.\n' + message.reply('Du hast die Probe auf ' + attributename + ' (Stufe ' + level + ') leider nicht bestanden 😢.\n' +
'Deine 🎲: ' + dice.join(', ')); 'Deine 🎲: ' + dice.join(', '));
} } else {
else {
message.reply('Du hast die Probe (Stufe ' + level + ') leider nicht bestanden 😢.\n' + message.reply('Du hast die Probe (Stufe ' + level + ') leider nicht bestanden 😢.\n' +
'Deine 🎲: ' + dice.join(', ')); 'Deine 🎲: ' + dice.join(', '));
} }
}); });
} } catch (e) {
catch (e) {
throw e; throw e;
} }
}, },
}; };
const HandleCrits = (dice) => {
};
const HandleNamedAttributes = () => {
if (docs.length === 0) {
message.reply(findMessage('NOENTRY'));
return;
} else {
// try to get id of short formatted attributes.
if (args[0].length == 2) {
for (const i in globals.Werte) {
if (globals.Werte[i].kuerzel == args[0].toUpperCase()) {
attributename = globals.Werte[i].id;
}
}
} else {
attributename = args[0].toLowerCase();
}
for (const i in docs[0].character.attributes) {
if (docs[0].character.attributes[i].id == attributename) level = docs[0].character.attributes[i].level;
}
}
};
//const docs = [];
//console.log(HandleNamedAttributes())

View File

@ -1,6 +1,7 @@
const globals = require('../globals'); const globals = require('../globals');
const Random = require('random'); //const Random = require('random');
const { roll } = require('@dsabot/Roll');
const { findMessage }= require('@dsabot/findMessage');
module.exports = { module.exports = {
name: 'kopf', name: 'kopf',
@ -10,8 +11,9 @@ module.exports = {
needs_args: false, needs_args: false,
async exec(message, args) { async exec(message, args) {
Random.use(message.author.tag); //Random.use(message.author.tag);
const coin = Random.int(0, 1); const coin = roll(1,2,message.author.tag).dice; //Random.int(0, 1);
message.reply('Die Münze bleibt auf **' + globals.Coin[coin] + '** liegen.'); // message.reply('Die Münze bleibt auf **' + globals.Coin[coin] + '** liegen.');
message.reply(`${findMessage('HEADS_OR_TAILS')} **${globals.Coin[(coin-1)]}**.`);
}, },
}; };

View File

@ -1,3 +1,4 @@
const { findMessage }= require('@dsabot/findMessage');
const globals = require('../globals'); const globals = require('../globals');
const db = globals.db; const db = globals.db;
module.exports = { module.exports = {
@ -10,7 +11,7 @@ module.exports = {
db.remove({ db.remove({
user: message.author.tag, user: message.author.tag,
}, {}, function(err, numRemoved) { }, {}, function(err, numRemoved) {
message.reply(globals.Replies.find(x => x.id === 'DELETED_DATA').string); return message.reply(findMessage('DELETED_DATA'));
}); });
}, },
}; };

View File

@ -1,7 +1,7 @@
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
const globals = require('../globals'); const globals = require('../globals');
const Random = require('random'); const { roll } = require('@dsabot/Roll');
const { findMessage }= require('@dsabot/findMessage');
module.exports = { module.exports = {
name: 'roll', name: 'roll',
@ -10,30 +10,17 @@ module.exports = {
usage: '<Anzahl> w <Augenzahl>', usage: '<Anzahl> w <Augenzahl>',
needs_args: true, needs_args: true,
async exec(message, args) { async exec(message, args) {
let params = args.join('').split(globals.DiceRegex);
Random.use(message.author.tag); if ( params.length >= 2 ) {
let msg;
let arguments = args.join('').split(globals.DiceRegex);
if (arguments.length >= 2) {
let bonus = 0; let bonus = 0;
const numberOfDice = parseInt(arguments[0]); const numberOfDice = parseInt( params[0] );
const diceValues = parseInt(arguments[1]); const diceValues = parseInt( params[1] );
if (arguments.length==3) { bonus = parseInt(arguments[2]); } if ( params.length == 3 ) {
let sum = bonus; bonus = parseInt( params[2] );
const roll = [];
for (let i = 0; i < numberOfDice; i++) {
const a = Random.int(1, diceValues);
roll.push(a);
sum += a;
} }
if (numberOfDice == 1) {
msg = 'n'; const result = roll( numberOfDice, diceValues, message.author.tag );
} message.reply(`${findMessage('ROLL')} ${result.dice.join(', ')} (Gesamt: ${result.sum} + ${bonus} = ${result.sum + bonus})` );
else {
msg = ' ' + numberOfDice;
}
//message.reply('Das sind deine Ergebnisse für deine' + msg + ' ' + diceValues + '-seitigen 🎲: ' + roll.join(', ') + '. (Gesamt: ' + roll.reduce((pv, cv) => pv + cv, 0) + ' + ' + bonus[1] + ' = ' + sum + ')');
message.reply(`Das sind die Ergebnisse für deine${msg} ${diceValues}-seitigen 🎲: ${roll.join(', ')}. (Gesamt: ${roll.reduce((pv, cv) => pv + cv, 0)} + ${bonus} = ${sum})`);
} }
}, },
}; };

View File

@ -2,6 +2,7 @@
const globals = require('../globals'); const globals = require('../globals');
const Discord = require('discord.js'); const Discord = require('discord.js');
const db = globals.db; const db = globals.db;
const { findMessage }= require('@dsabot/findMessage');
module.exports = { module.exports = {
name: 'show', name: 'show',
@ -16,7 +17,7 @@ module.exports = {
user: message.author.tag, user: message.author.tag,
}, function(err, docs) { }, function(err, docs) {
if (docs.length === 0) { if (docs.length === 0) {
return message.reply(globals.Replies.find(r => r.id === 'NOENTRY').string); return message.reply(findMessage('NOENTRY'));
} }
else { else {
let gender; let gender;

View File

@ -1,5 +1,6 @@
const globals = require('../globals'); const globals = require('../globals');
const db = globals.db; const db = globals.db;
const { findMessage }= require('@dsabot/findMessage');
module.exports = { module.exports = {
name: 'skill', name: 'skill',
description: 'Zeigt dir deinen Fertigkeitswert im jeweiligen Talent.', description: 'Zeigt dir deinen Fertigkeitswert im jeweiligen Talent.',
@ -13,13 +14,18 @@ module.exports = {
user: message.author.tag, user: message.author.tag,
}, function(err, docs) { }, function(err, docs) {
if (docs.length === 0) { if (docs.length === 0) {
return message.reply(globals.Replies.find(r => r.id === 'NOENTRY').string); return message.reply(findMessage('NOENTRY'));
} }
else { else {
let level = 0; let level = 0;
/*
for (let i in docs[0].character.skills) { for (let i in docs[0].character.skills) {
if (docs[0].character.skills[i].id == args[0]) level = docs[0].character.skills[i].level; if (docs[0].character.skills[i].id == args[0]) {
level = docs[0].character.skills[i].level;
}
} }
*/
level = docs[0].character.skills.find(skill => skill.id === args[0]).level;
message.reply('Du hast folgenden Talentwert in ' + args[0] + ': ' + level); message.reply('Du hast folgenden Talentwert in ' + args[0] + ': ' + level);
} }
}); });

View File

@ -1,13 +1,18 @@
const globals = require('../globals'); const globals = require('../globals');
const Random = require('random');
const Discord = require('discord.js'); const Discord = require('discord.js');
const db = globals.db; const db = globals.db;
const {
roll
} = require('@dsabot/Roll');
const {
findMessage
} = require('@dsabot/findMessage');
module.exports = { module.exports = {
name: 'talent', name: 'talent',
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' + ' 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.', ' ist der Wurf erleichtert oder erschwert, wird dies in die Berechnung einbezogen.',
aliases: ['t'], aliases: ['t'],
usage: '<Talent> [<-Erschwernis> / <+Erleichterung>]', usage: '<Talent> [<-Erschwernis> / <+Erleichterung>]',
needs_args: true, needs_args: true,
@ -15,108 +20,91 @@ module.exports = {
try { try {
db.find({ db.find({
user: message.author.tag, user: message.author.tag,
}, function(err, docs) { }, function (err, docs) {
if (docs.length === 0) { if (docs.length === 0) {
return message.reply(globals.Replies.find(r => r.id === 'NOENTRY').string); return message.reply(findMessage('NOENTRY'));
} }
if(!isNaN(args[0])) { if (!isNaN(args[0])) {
return message.reply(globals.Replies.find(x => x.id === 'WRONG_ARGUMENTS').string); return message.reply(findMessage('WRONG_ARGUMENTS'));
} } else {
else { const Character = docs[0].character;
Random.use(message.author.tag);
const values = []; const values = [];
const roll = [];
let found = false; const erschwernis = parseInt(args[1]) || 0;
let talent; const talent = globals.Talente.find(talent => talent.id.toLocaleLowerCase() === args[0].toLowerCase());
let bonus = 0;
if (!talent) {
return message.reply(findMessage('TALENT_UNKNOWN'));
}
let bonus = Character.skills.find(skill => skill.id === talent.id).level || 0;
const bonus_orig = bonus;
talent.values.forEach(v => {
let abbr = globals.Werte.find(wert => wert.kuerzel === v);
values.push((Character.attributes.find(attr => attr.id === abbr.id)).level);
});
const dice = roll(3, 20, message.author.tag).dice;
let ok = 0; let ok = 0;
let patzer = 0; let patzer = 0;
let crit = 0; let crit = 0;
let erschwernis = 0;
if (args[1]) {
erschwernis = parseInt(args[1]);
}
for (let i in globals.Talente) {
if (globals.Talente[i].id.toLowerCase() == args[0].toLowerCase() || globals.Talente[i].name.toLowerCase() == args[0].toLowerCase()) {
found = true;
talent = globals.Talente[i].id;
break;
}
}
if (!found) {
message.reply(globals.Replies.find(x => x.id === 'TALENT_UNKNOWN').string);
return;
}
for (let i in docs[0].character.skills) {
if (docs[0].character.skills[i].id == talent) {
bonus = docs[0].character.skills[i].level;
found = true;
}
}
const bonus_orig = bonus;
const result = globals.Talente.find(t => t.id === talent);
result.values.forEach(value => {
let kuerzel = globals.Werte.find(wert => wert.kuerzel === value);
docs[0].character.attributes.forEach(attr => {
if (attr == kuerzel.id) { values.push(attr.level);}
});
});
for (let i = 1; i <= 3; i++) {
roll.push(Random.int(1, 20));
}
// compare results // compare results
for (let i = 0; i < 3; i++) { for (let i = 0; i < dice.length; i++) {
if (Math.floor(values[i] + parseInt(erschwernis)) >= roll[i]) { if (Math.floor(values[i] + erschwernis) >= dice[i]) {
ok++; ok++;
} } else if (Math.floor(values[i] + bonus + erschwernis) >= dice[i]) {
else if ((Math.floor(values[i]) + parseInt(bonus) + parseInt(erschwernis)) >= roll[i]) {
ok++; ok++;
bonus = bonus - (roll[i] - parseInt(erschwernis) - values[i]); bonus -= (dice[i] - erschwernis - values[i]);
}
if (dice[i] == 1) {
crit++;
}
if (dice[i] == 20) {
patzer++;
} }
if (roll[i] == 1) crit++;
if (roll[i] == 20) patzer++;
} }
const Reply = new Discord.MessageEmbed(); const Reply = new Discord.MessageEmbed();
Reply.setTitle('Du würfelst auf das Talent ' + result.name + '.'); Reply.setTitle('Du würfelst auf das Talent ' + talent.name + '. (v2)');
Reply.setDescription('Deine Werte für ' + result.values.join(', ') + ' sind ' + values.join(', ') + '. (Bonus: ' + bonus_orig + ')'); Reply.setDescription('Deine Werte für ' + talent.values.join(', ') + ' sind ' + values.join(', ') + '. (Bonus: ' + bonus_orig + ')');
Reply.addFields({ Reply.addFields({
name: 'Deine 🎲: ' + roll.join(', ') + '.', name: 'Deine 🎲: ' + dice.join(', ') + '.',
value: '\u200B', inline: false}); value: '\u200B',
inline: false
});
if (patzer >= 2) { if (patzer >= 2) {
Reply.setColor('#900c3f'); Reply.setColor('#900c3f');
Reply.addFields({ Reply.addFields({
name: globals.Replies.find(x => x.id === 'TITLE_CRIT_FAILURE').string, name: findMessage('TITLE_CRIT_FAILURE'),
value: globals.Replies.find(x => x.id === 'MSG_CRIT_FAILURE').string, value: findMessage('MSG_CRIT_FAILURE'),
inline: false}); inline: false
} });
else if (crit >= 2) { } else if (crit >= 2) {
Reply.setColor('#1E8449'); Reply.setColor('#1E8449');
Reply.addFields({ Reply.addFields({
name: globals.Replies.find(x => x.id === 'TITLE_CRIT_SUCCESS').string, name: findMessage('TITLE_CRIT_SUCCESS'),
value:globals.Replies.find(x => x.id === 'MSG_CRIT_SUCCESS').string, value: findMessage('MSG_CRIT_SUCCESS'),
inline: false}); inline: false
} });
else if (ok < 3) { } else if (ok < 3) {
Reply.addFields({name: globals.Replies.find(x => x.id === 'TITLE_FAILURE').string, Reply.addFields({
value: 'nur ' + ok + '/3 Proben erfolgreich. 😪', name: findMessage('TITLE_FAILURE'),
inline: false}); value: 'nur ' + ok + '/3 Proben erfolgreich. 😪',
} inline: false
else { });
Reply.addFields({name: globals.Replies.find(x => x.id === 'TITLE_SUCCESS').string, } else {
value: ok + '/3 Proben erfolgreich. Dein Bonus: ' + bonus + '/' + bonus_orig + '.', Reply.addFields({
inline: false}); name: findMessage('TITLE_SUCCESS'),
value: ok + '/3 Proben erfolgreich. Dein Bonus: ' + bonus + '/' + bonus_orig + '.',
inline: false
});
} }
message.reply(Reply); message.reply(Reply);
} }
}); });
} } catch (e) {
catch (e) {
throw e; throw e;
} }
}, },

View File

@ -2,7 +2,8 @@
const Random = require('random'); const Random = require('random');
const globals = require('../globals'); const globals = require('../globals');
const Discord = require('discord.js'); const Discord = require('discord.js');
const { roll } = require('@dsabot/Roll');
const { findMessage }= require('@dsabot/findMessage');
module.exports = { module.exports = {
name: 'tp', name: 'tp',
description: 'Du machst eine Fertigkeitsprobe.\n' + description: 'Du machst eine Fertigkeitsprobe.\n' +
@ -15,11 +16,11 @@ module.exports = {
async exec(message, args) { async exec(message, args) {
if(isNaN(args[0])) { if(isNaN(args[0])) {
return message.reply(globals.Replies.find(x => x.id === 'WRONG_ARGUMENTS').string); return message.reply(findMessage('WRONG_ARGUMENTS'));
} }
Random.use(message.author.tag); //Random.use(message.author.tag);
const roll = []; //const dice = [];
let bonus = 0; let bonus = 0;
let bonus_orig = 0; let bonus_orig = 0;
let erschwernis = 0; let erschwernis = 0;
@ -30,50 +31,51 @@ module.exports = {
if (args[4]) { if (args[4]) {
erschwernis = parseInt(args[4]); erschwernis = parseInt(args[4]);
} }
for (let i = 1; i <= 3; i++) { /*for (let i = 1; i <= 3; i++) {
roll.push(Random.int(1, 20)); roll.push(Random.int(1, 20));
} }*/
const dice = roll(3,20,message.author.tag).dice;
let ok = 0; let ok = 0;
let patzer = 0; let patzer = 0;
let crit = 0; let crit = 0;
for (let i = 0; i < 3; i++) { for (let i = 0; i < 3; i++) {
if (Math.floor(parseInt(args[i]) + parseInt(erschwernis)) >= roll[i]) { if (Math.floor(parseInt(args[i]) + parseInt(erschwernis)) >= dice[i]) {
ok++; ok++;
} else if ( } else if (
Math.floor(parseInt(args[i]) + parseInt(bonus) + parseInt(erschwernis)) >= roll[i]) { Math.floor(parseInt(args[i]) + parseInt(bonus) + parseInt(erschwernis)) >= dice[i]) {
ok++; ok++;
bonus = bonus - (roll[i] - parseInt(erschwernis) - parseInt(args[i])); bonus = bonus - (dice[i] - parseInt(erschwernis) - parseInt(args[i]));
} }
if (roll[i] == 1) crit++; if (dice[i] == 1) {crit++;}
if (roll[i] == 20) patzer++; if (dice[i] == 20) {patzer++;}
} }
const Reply = new Discord.MessageEmbed(); const Reply = new Discord.MessageEmbed();
//Reply.setTitle('Du würfelst auf ' + args[0] + ' ' + args[1] + ' ' + args[2] + ' (Bonus: ' + bonus_orig + ')') Reply.setTitle(`${findMessage('ROLL')} ${dice.join(', ')}.`);
Reply.setTitle('Deine 🎲: ' + roll.join(', ') + '.');
if (patzer >= 2) { if (patzer >= 2) {
Reply.setColor('#900c3f'); Reply.setColor('#900c3f');
Reply.addFields({ Reply.addFields({
name: globals.Replies.find(x => x.id === 'TITLE_CRIT_FAILURE').string, name: findMessage('TITLE_CRIT_FAILURE'),
value: globals.Replies.find(x => x.id === 'MSG_CRIT_FAILURE').string, value: findMessage('MSG_CRIT_FAILURE'),
inline: false inline: false
}); });
} else if (crit >= 2) { } else if (crit >= 2) {
Reply.setColor('#1E8449'); Reply.setColor('#1E8449');
Reply.addFields({ Reply.addFields({
name: globals.Replies.find(x => x.id === 'TITLE_CRIT_SUCCESS').string, name: findMessage('TITLE_CRIT_SUCCESS'),
value: globals.Replies.find(x => x.id === 'MSG_CRIT_SUCCESS').string, value: findMessage('MSG_CRIT_SUCCESS'),
inline: false inline: false
}); });
} else if (ok < 3) { } else if (ok < 3) {
Reply.addFields({ Reply.addFields({
name: globals.Replies.find(x => x.id === 'TITLE_FAILURE').string, name: findMessage('TITLE_FAILURE'),
value: 'Nur ' + ok + '/3 Proben erfolgreich. 😪', value: 'Nur ' + ok + '/3 Proben erfolgreich. 😪',
inline: false inline: false
}); });
} else { } else {
Reply.addFields({ Reply.addFields({
name: globals.Replies.find(x => x.id === 'TITLE_SUCCESS').string, name: findMessage('TITLE_SUCCESS'),
value: ok + '/3 Proben erfolgreich. Dein Bonus: ' + bonus + '/' + bonus_orig + '.', value: ok + '/3 Proben erfolgreich. Dein Bonus: ' + bonus + '/' + bonus_orig + '.',
inline: false inline: false
}); });

6
functions/Compare.js Normal file
View File

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

View File

@ -0,0 +1,7 @@
const CountOccurences = (arr, value) => {
return arr.filter((v) => (v === value)).length;
};
module.exports = { CountOccurences };
//console.log(countOccurrences([1,2,3,4,3,2,3,3,2],2));

15
functions/Roll.js Normal file
View File

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

7
functions/findMessage.js Normal file
View File

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

View File

@ -138,7 +138,9 @@ const Replies = [
{ id: 'PARRY_FAIL', string: 'Deine Parade schlägt fehl.'}, { id: 'PARRY_FAIL', string: 'Deine Parade schlägt fehl.'},
{ id: 'PARRY_CRIT_FAIL', string: 'Kritischer Fehlschlag! Du erleidest zusätzlich 1W6+2 Schadenspunkte!'}, { id: 'PARRY_CRIT_FAIL', string: 'Kritischer Fehlschlag! Du erleidest zusätzlich 1W6+2 Schadenspunkte!'},
{ id: 'PARRY_SUCCESS', string: 'Parade erfolgreich.'}, { id: 'PARRY_SUCCESS', string: 'Parade erfolgreich.'},
{ id: 'PARRY_CRIT_SUCCESS', string: 'Kritischer Erfolg! Du darfst einen Passierschlag ausführen!'} { id: 'PARRY_CRIT_SUCCESS', string: 'Kritischer Erfolg! Du darfst einen Passierschlag ausführen!'},
{ id: 'ROLL', string: 'Du würfelst:'},
{ id: 'HEADS_OR_TAILS', string: 'Die Münze landet auf '}
]; ];
const Declination = ['dem', 'der', 'dem', '']; // Maskulinum, Feminimum, Neutrum, None const Declination = ['dem', 'der', 'dem', '']; // Maskulinum, Feminimum, Neutrum, None
const Articles = ['Der','Die','Das','']; const Articles = ['Der','Die','Das',''];

3
jest.config.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = {
testEnvironment: 'node'
};

9
jsconfig.json Normal file
View File

@ -0,0 +1,9 @@
{
"compilerOptions": {
"baseUrl": "./",
"paths": {
"@dsabot/*": ["functions/*"],
"@globals": ["./globals"]
}
}
}

1
package-lock.json generated
View File

@ -7,6 +7,7 @@
"": { "": {
"name": "dsabot", "name": "dsabot",
"version": "1.0.0", "version": "1.0.0",
"hasInstallScript": true,
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"discord.js": "^12.5.0", "discord.js": "^12.5.0",

View File

@ -1,11 +1,15 @@
{ {
"name": "dsabot", "name": "dsabot",
"version": "1.0.0", "version": "1.1.0",
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"lint": "eslint commands/", "lint": "eslint commands/",
"start": "node index.js" "start": "node index.js",
"test": "jest"
},
"_moduleAliases": {
"@dsabot": "functions"
}, },
"author": "", "author": "",
"license": "ISC", "license": "ISC",