refactoring (#4)
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@ -3,4 +3,6 @@ node_modules
|
||||
.eslintrc.js
|
||||
.eslintrc.json
|
||||
.vscode
|
||||
data/dsabot.db
|
||||
data/data
|
||||
|
||||
|
4
__tests__/functions/CountOccurences.js
Normal file
4
__tests__/functions/CountOccurences.js
Normal file
@ -0,0 +1,4 @@
|
||||
const CountOccurrences = require('@dsabot/CountOccurences');
|
||||
test('Counting Occurences', () => {
|
||||
expect(CountOccurrences([1, 2, 3, 4, 1],1)).toBe(2);
|
||||
});
|
10
__tests__/functions/Roll.js
Normal file
10
__tests__/functions/Roll.js
Normal 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),
|
||||
);
|
||||
});
|
||||
});
|
@ -1,6 +1,8 @@
|
||||
const globals = require('../globals');
|
||||
const db = globals.db;
|
||||
const Random = require('random');
|
||||
//const { roll } = require('@dsabot/Roll');
|
||||
const { findMessage }= require('@dsabot/findMessage');
|
||||
|
||||
module.exports = {
|
||||
name: 'attack',
|
||||
@ -15,7 +17,7 @@ module.exports = {
|
||||
user: message.author.tag,
|
||||
}, function(err, docs) {
|
||||
if (docs.length === 0) {
|
||||
return message.reply(globals.Replies.find(r => r.id === 'NOENTRY').string);
|
||||
return message.reply(findMessage('NOENTRY'));
|
||||
}
|
||||
else {
|
||||
|
||||
|
@ -1,4 +1,10 @@
|
||||
const globals = require('../globals');
|
||||
const {
|
||||
CountOccurences
|
||||
} = require('@dsabot/CountOccurences');
|
||||
const {
|
||||
findMessage
|
||||
} = require('@dsabot/findMessage');
|
||||
const Random = require('random');
|
||||
const db = globals.db;
|
||||
|
||||
@ -15,47 +21,26 @@ module.exports = {
|
||||
|
||||
await db.find({
|
||||
user: message.author.tag,
|
||||
}, async function(err, docs) {
|
||||
}, async function (err, docs) {
|
||||
|
||||
// user calls with text. need to gather info from database
|
||||
if (isNaN(args[0])) {
|
||||
if (docs.length === 0) {
|
||||
message.reply(globals.Replies.find(r => r.id === 'NOENTRY').string);
|
||||
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 {
|
||||
HandleNamedAttributes();
|
||||
} else {
|
||||
level = args[0];
|
||||
}
|
||||
Random.use(message.author.tag);
|
||||
const countOccurrences = (arr, val) => arr.reduce((a, v) => (v === val ? a + 1 : a), 0);
|
||||
|
||||
const dice = [];
|
||||
dice.push(Random.int(1, 20));
|
||||
if (dice[0] == 1 || dice[0] == 20) {
|
||||
dice.push(Random.int(1, 20));
|
||||
}
|
||||
// handle crits
|
||||
if (countOccurrences(dice, 1) == 2) {
|
||||
if (CountOccurences(dice, 1) == 2) {
|
||||
message.reply('Du hast einen kritischen Erfolg erzielt (' + dice.join(', ') + ')! 🎉🥳🎆');
|
||||
return;
|
||||
}
|
||||
else if (countOccurrences(dice, 20) == 2) {
|
||||
} else if (CountOccurences(dice, 20) == 2) {
|
||||
message.reply('Du hast einen Patzer (' + dice.join(', ') + ')! 😭 Viel Erfolg beim nächsten mal!');
|
||||
return;
|
||||
}
|
||||
@ -63,24 +48,47 @@ module.exports = {
|
||||
if (attributename) {
|
||||
message.reply('Du hast die Probe auf ' + attributename + ' (Stufe ' + level + ') bestanden.\n' +
|
||||
'Deine 🎲: ' + dice.join(', '));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
message.reply('Du hast die Probe (Stufe ' + level + ') bestanden.\n' +
|
||||
'Deine 🎲: ' + dice.join(', '));
|
||||
}
|
||||
}
|
||||
else if (attributename) {
|
||||
} else if (attributename) {
|
||||
message.reply('Du hast die Probe auf ' + attributename + ' (Stufe ' + level + ') leider nicht bestanden 😢.\n' +
|
||||
'Deine 🎲: ' + dice.join(', '));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
message.reply('Du hast die Probe (Stufe ' + level + ') leider nicht bestanden 😢.\n' +
|
||||
'Deine 🎲: ' + dice.join(', '));
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (e) {
|
||||
} catch (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())
|
@ -1,6 +1,7 @@
|
||||
const globals = require('../globals');
|
||||
const Random = require('random');
|
||||
|
||||
//const Random = require('random');
|
||||
const { roll } = require('@dsabot/Roll');
|
||||
const { findMessage }= require('@dsabot/findMessage');
|
||||
|
||||
module.exports = {
|
||||
name: 'kopf',
|
||||
@ -10,8 +11,9 @@ module.exports = {
|
||||
needs_args: false,
|
||||
|
||||
async exec(message, args) {
|
||||
Random.use(message.author.tag);
|
||||
const coin = Random.int(0, 1);
|
||||
message.reply('Die Münze bleibt auf **' + globals.Coin[coin] + '** liegen.');
|
||||
//Random.use(message.author.tag);
|
||||
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(`${findMessage('HEADS_OR_TAILS')} **${globals.Coin[(coin-1)]}**.`);
|
||||
},
|
||||
};
|
@ -1,3 +1,4 @@
|
||||
const { findMessage }= require('@dsabot/findMessage');
|
||||
const globals = require('../globals');
|
||||
const db = globals.db;
|
||||
module.exports = {
|
||||
@ -10,7 +11,7 @@ module.exports = {
|
||||
db.remove({
|
||||
user: message.author.tag,
|
||||
}, {}, function(err, numRemoved) {
|
||||
message.reply(globals.Replies.find(x => x.id === 'DELETED_DATA').string);
|
||||
return message.reply(findMessage('DELETED_DATA'));
|
||||
});
|
||||
},
|
||||
};
|
@ -1,7 +1,7 @@
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const globals = require('../globals');
|
||||
const Random = require('random');
|
||||
|
||||
const { roll } = require('@dsabot/Roll');
|
||||
const { findMessage }= require('@dsabot/findMessage');
|
||||
|
||||
module.exports = {
|
||||
name: 'roll',
|
||||
@ -10,30 +10,17 @@ module.exports = {
|
||||
usage: '<Anzahl> w <Augenzahl>',
|
||||
needs_args: true,
|
||||
async exec(message, args) {
|
||||
|
||||
Random.use(message.author.tag);
|
||||
let msg;
|
||||
let arguments = args.join('').split(globals.DiceRegex);
|
||||
if (arguments.length >= 2) {
|
||||
let params = args.join('').split(globals.DiceRegex);
|
||||
if ( params.length >= 2 ) {
|
||||
let bonus = 0;
|
||||
const numberOfDice = parseInt(arguments[0]);
|
||||
const diceValues = parseInt(arguments[1]);
|
||||
if (arguments.length==3) { bonus = parseInt(arguments[2]); }
|
||||
let sum = bonus;
|
||||
const roll = [];
|
||||
for (let i = 0; i < numberOfDice; i++) {
|
||||
const a = Random.int(1, diceValues);
|
||||
roll.push(a);
|
||||
sum += a;
|
||||
const numberOfDice = parseInt( params[0] );
|
||||
const diceValues = parseInt( params[1] );
|
||||
if ( params.length == 3 ) {
|
||||
bonus = parseInt( params[2] );
|
||||
}
|
||||
if (numberOfDice == 1) {
|
||||
msg = 'n';
|
||||
}
|
||||
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})`);
|
||||
|
||||
const result = roll( numberOfDice, diceValues, message.author.tag );
|
||||
message.reply(`${findMessage('ROLL')} ${result.dice.join(', ')} (Gesamt: ${result.sum} + ${bonus} = ${result.sum + bonus})` );
|
||||
}
|
||||
},
|
||||
};
|
@ -2,6 +2,7 @@
|
||||
const globals = require('../globals');
|
||||
const Discord = require('discord.js');
|
||||
const db = globals.db;
|
||||
const { findMessage }= require('@dsabot/findMessage');
|
||||
|
||||
module.exports = {
|
||||
name: 'show',
|
||||
@ -16,7 +17,7 @@ module.exports = {
|
||||
user: message.author.tag,
|
||||
}, function(err, docs) {
|
||||
if (docs.length === 0) {
|
||||
return message.reply(globals.Replies.find(r => r.id === 'NOENTRY').string);
|
||||
return message.reply(findMessage('NOENTRY'));
|
||||
}
|
||||
else {
|
||||
let gender;
|
||||
|
@ -1,5 +1,6 @@
|
||||
const globals = require('../globals');
|
||||
const db = globals.db;
|
||||
const { findMessage }= require('@dsabot/findMessage');
|
||||
module.exports = {
|
||||
name: 'skill',
|
||||
description: 'Zeigt dir deinen Fertigkeitswert im jeweiligen Talent.',
|
||||
@ -13,13 +14,18 @@ module.exports = {
|
||||
user: message.author.tag,
|
||||
}, function(err, docs) {
|
||||
if (docs.length === 0) {
|
||||
return message.reply(globals.Replies.find(r => r.id === 'NOENTRY').string);
|
||||
return message.reply(findMessage('NOENTRY'));
|
||||
}
|
||||
else {
|
||||
let level = 0;
|
||||
/*
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
@ -1,13 +1,18 @@
|
||||
const globals = require('../globals');
|
||||
const Random = require('random');
|
||||
const Discord = require('discord.js');
|
||||
const db = globals.db;
|
||||
const {
|
||||
roll
|
||||
} = require('@dsabot/Roll');
|
||||
const {
|
||||
findMessage
|
||||
} = require('@dsabot/findMessage');
|
||||
|
||||
module.exports = {
|
||||
name: 'talent',
|
||||
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.',
|
||||
' 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: ['t'],
|
||||
usage: '<Talent> [<-Erschwernis> / <+Erleichterung>]',
|
||||
needs_args: true,
|
||||
@ -15,108 +20,91 @@ module.exports = {
|
||||
try {
|
||||
db.find({
|
||||
user: message.author.tag,
|
||||
}, function(err, docs) {
|
||||
}, function (err, docs) {
|
||||
if (docs.length === 0) {
|
||||
return message.reply(globals.Replies.find(r => r.id === 'NOENTRY').string);
|
||||
return message.reply(findMessage('NOENTRY'));
|
||||
}
|
||||
if(!isNaN(args[0])) {
|
||||
return message.reply(globals.Replies.find(x => x.id === 'WRONG_ARGUMENTS').string);
|
||||
}
|
||||
else {
|
||||
Random.use(message.author.tag);
|
||||
if (!isNaN(args[0])) {
|
||||
return message.reply(findMessage('WRONG_ARGUMENTS'));
|
||||
} else {
|
||||
const Character = docs[0].character;
|
||||
const values = [];
|
||||
const roll = [];
|
||||
let found = false;
|
||||
let talent;
|
||||
let bonus = 0;
|
||||
|
||||
const erschwernis = parseInt(args[1]) || 0;
|
||||
const talent = globals.Talente.find(talent => talent.id.toLocaleLowerCase() === args[0].toLowerCase());
|
||||
|
||||
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 patzer = 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
|
||||
for (let i = 0; i < 3; i++) {
|
||||
if (Math.floor(values[i] + parseInt(erschwernis)) >= roll[i]) {
|
||||
for (let i = 0; i < dice.length; i++) {
|
||||
if (Math.floor(values[i] + erschwernis) >= dice[i]) {
|
||||
ok++;
|
||||
}
|
||||
else if ((Math.floor(values[i]) + parseInt(bonus) + parseInt(erschwernis)) >= roll[i]) {
|
||||
} else if (Math.floor(values[i] + bonus + erschwernis) >= dice[i]) {
|
||||
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();
|
||||
Reply.setTitle('Du würfelst auf das Talent ' + result.name + '.');
|
||||
Reply.setDescription('Deine Werte für ' + result.values.join(', ') + ' sind ' + values.join(', ') + '. (Bonus: ' + bonus_orig + ')');
|
||||
Reply.setTitle('Du würfelst auf das Talent ' + talent.name + '. (v2)');
|
||||
Reply.setDescription('Deine Werte für ' + talent.values.join(', ') + ' sind ' + values.join(', ') + '. (Bonus: ' + bonus_orig + ')');
|
||||
Reply.addFields({
|
||||
name: 'Deine 🎲: ' + roll.join(', ') + '.',
|
||||
value: '\u200B', inline: false});
|
||||
name: 'Deine 🎲: ' + dice.join(', ') + '.',
|
||||
value: '\u200B',
|
||||
inline: false
|
||||
});
|
||||
if (patzer >= 2) {
|
||||
Reply.setColor('#900c3f');
|
||||
Reply.addFields({
|
||||
name: globals.Replies.find(x => x.id === 'TITLE_CRIT_FAILURE').string,
|
||||
value: globals.Replies.find(x => x.id === 'MSG_CRIT_FAILURE').string,
|
||||
inline: false});
|
||||
}
|
||||
else if (crit >= 2) {
|
||||
name: findMessage('TITLE_CRIT_FAILURE'),
|
||||
value: findMessage('MSG_CRIT_FAILURE'),
|
||||
inline: false
|
||||
});
|
||||
} else if (crit >= 2) {
|
||||
Reply.setColor('#1E8449');
|
||||
Reply.addFields({
|
||||
name: globals.Replies.find(x => x.id === 'TITLE_CRIT_SUCCESS').string,
|
||||
value:globals.Replies.find(x => x.id === 'MSG_CRIT_SUCCESS').string,
|
||||
inline: false});
|
||||
}
|
||||
else if (ok < 3) {
|
||||
Reply.addFields({name: globals.Replies.find(x => x.id === 'TITLE_FAILURE').string,
|
||||
value: 'nur ' + ok + '/3 Proben erfolgreich. 😪',
|
||||
inline: false});
|
||||
}
|
||||
else {
|
||||
Reply.addFields({name: globals.Replies.find(x => x.id === 'TITLE_SUCCESS').string,
|
||||
value: ok + '/3 Proben erfolgreich. Dein Bonus: ' + bonus + '/' + bonus_orig + '.',
|
||||
inline: false});
|
||||
name: findMessage('TITLE_CRIT_SUCCESS'),
|
||||
value: findMessage('MSG_CRIT_SUCCESS'),
|
||||
inline: false
|
||||
});
|
||||
} else if (ok < 3) {
|
||||
Reply.addFields({
|
||||
name: findMessage('TITLE_FAILURE'),
|
||||
value: 'nur ' + ok + '/3 Proben erfolgreich. 😪',
|
||||
inline: false
|
||||
});
|
||||
} else {
|
||||
Reply.addFields({
|
||||
name: findMessage('TITLE_SUCCESS'),
|
||||
value: ok + '/3 Proben erfolgreich. Dein Bonus: ' + bonus + '/' + bonus_orig + '.',
|
||||
inline: false
|
||||
});
|
||||
}
|
||||
|
||||
message.reply(Reply);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (e) {
|
||||
} catch (e) {
|
||||
throw e;
|
||||
}
|
||||
},
|
||||
|
@ -2,7 +2,8 @@
|
||||
const Random = require('random');
|
||||
const globals = require('../globals');
|
||||
const Discord = require('discord.js');
|
||||
|
||||
const { roll } = require('@dsabot/Roll');
|
||||
const { findMessage }= require('@dsabot/findMessage');
|
||||
module.exports = {
|
||||
name: 'tp',
|
||||
description: 'Du machst eine Fertigkeitsprobe.\n' +
|
||||
@ -15,11 +16,11 @@ module.exports = {
|
||||
async exec(message, args) {
|
||||
|
||||
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);
|
||||
const roll = [];
|
||||
//Random.use(message.author.tag);
|
||||
//const dice = [];
|
||||
let bonus = 0;
|
||||
let bonus_orig = 0;
|
||||
let erschwernis = 0;
|
||||
@ -30,50 +31,51 @@ module.exports = {
|
||||
if (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));
|
||||
}
|
||||
}*/
|
||||
const dice = roll(3,20,message.author.tag).dice;
|
||||
|
||||
let ok = 0;
|
||||
let patzer = 0;
|
||||
let crit = 0;
|
||||
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++;
|
||||
} 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++;
|
||||
bonus = bonus - (roll[i] - parseInt(erschwernis) - parseInt(args[i]));
|
||||
bonus = bonus - (dice[i] - parseInt(erschwernis) - parseInt(args[i]));
|
||||
}
|
||||
if (roll[i] == 1) crit++;
|
||||
if (roll[i] == 20) patzer++;
|
||||
if (dice[i] == 1) {crit++;}
|
||||
if (dice[i] == 20) {patzer++;}
|
||||
}
|
||||
|
||||
const Reply = new Discord.MessageEmbed();
|
||||
//Reply.setTitle('Du würfelst auf ' + args[0] + ' ' + args[1] + ' ' + args[2] + ' (Bonus: ' + bonus_orig + ')')
|
||||
Reply.setTitle('Deine 🎲: ' + roll.join(', ') + '.');
|
||||
Reply.setTitle(`${findMessage('ROLL')} ${dice.join(', ')}.`);
|
||||
if (patzer >= 2) {
|
||||
Reply.setColor('#900c3f');
|
||||
Reply.addFields({
|
||||
name: globals.Replies.find(x => x.id === 'TITLE_CRIT_FAILURE').string,
|
||||
value: globals.Replies.find(x => x.id === 'MSG_CRIT_FAILURE').string,
|
||||
name: findMessage('TITLE_CRIT_FAILURE'),
|
||||
value: findMessage('MSG_CRIT_FAILURE'),
|
||||
inline: false
|
||||
});
|
||||
} else if (crit >= 2) {
|
||||
Reply.setColor('#1E8449');
|
||||
Reply.addFields({
|
||||
name: globals.Replies.find(x => x.id === 'TITLE_CRIT_SUCCESS').string,
|
||||
value: globals.Replies.find(x => x.id === 'MSG_CRIT_SUCCESS').string,
|
||||
name: findMessage('TITLE_CRIT_SUCCESS'),
|
||||
value: findMessage('MSG_CRIT_SUCCESS'),
|
||||
inline: false
|
||||
});
|
||||
} else if (ok < 3) {
|
||||
Reply.addFields({
|
||||
name: globals.Replies.find(x => x.id === 'TITLE_FAILURE').string,
|
||||
name: findMessage('TITLE_FAILURE'),
|
||||
value: 'Nur ' + ok + '/3 Proben erfolgreich. 😪',
|
||||
inline: false
|
||||
});
|
||||
} else {
|
||||
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 + '.',
|
||||
inline: false
|
||||
});
|
||||
|
6
functions/Compare.js
Normal file
6
functions/Compare.js
Normal file
@ -0,0 +1,6 @@
|
||||
const Compare = () => {
|
||||
|
||||
return { result };
|
||||
};
|
||||
|
||||
module.exports = { Compare };
|
7
functions/CountOccurences.js
Normal file
7
functions/CountOccurences.js
Normal 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
15
functions/Roll.js
Normal 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
7
functions/findMessage.js
Normal file
@ -0,0 +1,7 @@
|
||||
const globals = require('../globals');
|
||||
|
||||
const findMessage = (value) => {
|
||||
return globals.Replies.find(r => r.id === value).string;
|
||||
};
|
||||
|
||||
module.exports = { findMessage };
|
@ -138,7 +138,9 @@ const Replies = [
|
||||
{ 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_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 Articles = ['Der','Die','Das',''];
|
||||
|
3
jest.config.js
Normal file
3
jest.config.js
Normal file
@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
testEnvironment: 'node'
|
||||
};
|
9
jsconfig.json
Normal file
9
jsconfig.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"baseUrl": "./",
|
||||
"paths": {
|
||||
"@dsabot/*": ["functions/*"],
|
||||
"@globals": ["./globals"]
|
||||
}
|
||||
}
|
||||
}
|
1
package-lock.json
generated
1
package-lock.json
generated
@ -7,6 +7,7 @@
|
||||
"": {
|
||||
"name": "dsabot",
|
||||
"version": "1.0.0",
|
||||
"hasInstallScript": true,
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"discord.js": "^12.5.0",
|
||||
|
@ -1,11 +1,15 @@
|
||||
{
|
||||
"name": "dsabot",
|
||||
"version": "1.0.0",
|
||||
"version": "1.1.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"lint": "eslint commands/",
|
||||
"start": "node index.js"
|
||||
"start": "node index.js",
|
||||
"test": "jest"
|
||||
},
|
||||
"_moduleAliases": {
|
||||
"@dsabot": "functions"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
|
Reference in New Issue
Block a user