Merge development into master (#5)

* fixing typos

* merge Dynamic commands (#3)

* Update README.md

* Update README.md

* fixing typos

* dynamically read new commands inside folder.

* eslint, update package.json due to moving files

Co-authored-by: Marcus Netz <marcus.netz@godyo.com>

* fix talent checking on empty arguments list

* Origin/message embed (#4)

* add first embedded message on tp.js

* move db from message commands

* fix missing arguments list, add need_args

* add global Message Replies.

* add more global Message Replies.

* more embedded messages. fixing string

* missing comma

* adding a few more strings on talents.

Co-authored-by: Marcus Netz <marcus.netz@godyo.com>

* fixing creating from json file

* bugfix: db not defined

* possible  fix for nonworking talent?

* fix double msg

* fix: aliases are now being used

* change: show command displays now some character attributes

* added various aliases to commands, added global strings.

Co-authored-by: Marcus Netz <marcus.netz@godyo.com>
This commit is contained in:
2020-12-16 08:53:09 +01:00
committed by GitHub
parent 0ac4fe4d04
commit c179bdd0e0
32 changed files with 710 additions and 655 deletions

17
commands/HeadsOrTails.js Normal file
View File

@ -0,0 +1,17 @@
const globals = require('../globals');
const Random = require('random');
module.exports = {
name: 'kopf',
description: 'Wirf eine Münze. Kopf oder Zahl?',
aliases: ['zahl', 'heads', 'tails'],
usage: '',
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.');
},
};

48
commands/add.js Normal file
View File

@ -0,0 +1,48 @@
const globals = require('../globals')
const db = globals.db
module.exports = {
name: 'add',
description: '',
aliases: [],
usage: '',
needs_args: true,
async exec(message, args) {
try {
console.log(message.author.tag + ': ' + args);
if (!isNaN(args[0])) {
message.reply(args[1]);
console.log('1: ' + args[1] + ', 2: ' + args[2]);
const money = ['gold', 'silver', 'bronce', 'iron', 'hp'];
db.find({
user: message.author.tag,
}, function(err, docs) {
gold = docs[0].gold;
silver = docs[0].silver;
bronce = docs[0].bronce;
iron = docs[0].iron;
hp = docs[0].hp;
});
db.update({
user: message.author.tag,
}, {
gold: gold,
silver: silver,
bronce: bronce,
iron: iron,
hp: hp,
}, function(err, docs) {
if (!docs.length > 0) {
message.reply('Sorry, Für dich habe ich keinen Eintrag 😥');
return;
}
message.reply(`ich habe ${args[2]} zu ${args[1]} hinzugefügt.`);
});
}
}
catch (e) {
throw e;
}
},
};

86
commands/attribute.js Normal file
View File

@ -0,0 +1,86 @@
const globals = require('../globals');
const Random = require('random');
const db = globals.db
module.exports = {
name: 'attribute',
description: '',
aliases: ['ap', 'ep'],
usage: '<Eigenschaft> / <Eigenschaftswert>',
needs_args: true,
async exec(message, args) {
try {
let level = 8;
let attributename;
await db.find({
user: message.author.tag,
}, 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 {
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) {
message.reply('Du hast einen kritischen Erfolg erzielt (' + dice.join(', ') + ')! 🎉🥳🎆');
return;
}
else if (countOccurrences(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;
}
},
};

68
commands/help.js Normal file
View File

@ -0,0 +1,68 @@
const Discord = require('discord.js');
const cmdprefix = process.env.CMDPREFIX || '!';
module.exports = {
name: 'help',
description: '',
aliases: ['hilfe'],
usage: '',
needs_args: false,
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.')
.addFields({
name: cmdprefix + 'kopf',
value: 'Wirf eine Münze. Kopf oder Zahl?',
inline: false,
}, {
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: 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: 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: cmdprefix + 'talents',
value: ' Du erhälst eine Liste mit den Talentnamen, die du für ' +
cmdprefix + 'talent/' + cmdprefix + 'skill nutzen kannst.',
inline: false,
}, {
name: '\u200B',
value: '\u200B',
}, {
name: '\u200B',
value: 'Wenn du mir deine .tdc Datei zusendest, kannst du folgendes nutzen:',
}, {
name: cmdprefix + 'ep/ap [Klugheit] oder ' + cmdprefix + 'ep/ap [FF]',
value: 'siehe oben. Du brauchst deinen Wert nicht wissen.',
inline: false,
}, {
name: cmdprefix + 'talent <Talentname> (+Erleichtert/-Erschwert)',
value: 'siehe tp. Allerdings musst du deine Werte nicht wissen.',
inline: false,
}, {
name: cmdprefix + 'skill <Talentname>',
value: 'Zeigt dir deinen Fertigkeitswert im jeweiligen Talent.',
inline: false,
}, {
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);
},
};

16
commands/remove.js Normal file
View File

@ -0,0 +1,16 @@
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.',
aliases: [],
usage: '',
needs_args: false,
async exec(message, args) {
db.remove({
user: message.author.tag,
}, {}, function(err, numRemoved) {
message.reply(globals.Replies.find(x => x.id === 'DELETED_DATA').string);
});
},
};

36
commands/roll.js Normal file
View File

@ -0,0 +1,36 @@
// eslint-disable-next-line no-unused-vars
const globals = require('../globals');
const Random = require('random');
module.exports = {
name: 'roll',
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) {
Random.use(message.author.tag);
let msg;
let arguments = args.join('');
arguments = arguments.split(globals.DiceRegex);
if (arguments.length == 2) {
const numberOfDice = parseInt(arguments[0]);
const diceValues = parseInt(arguments[1]);
console.log(diceValues)
const roll = [];
for (let i = 0; i < numberOfDice; i++) {
const a = Random.int(1, diceValues);
roll.push(a);
}
if (numberOfDice == 1) {
msg = 'n';
}
else {
msg = ' ' + numberOfDice;
}
message.reply('Das sind deine Ergebnisse für deine' + msg + ' ' + diceValues + '-seitigen 🎲: ' + roll.join(', ') + '.');
}
},
};

39
commands/show.js Normal file
View File

@ -0,0 +1,39 @@
// eslint-disable-next-line no-unused-vars
const globals = require('../globals')
const Discord = require('discord.js')
const db = globals.db
module.exports = {
name: 'show',
description: '',
aliases: [],
usage: '',
needs_args: false,
async exec(message, args) {
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 {
let gender
if (docs[0].character.sex == 'female') { gender = '♀️' }
else { gender = '♂️' }
const Reply = new Discord.MessageEmbed()
Reply.setColor('#0099ff')
Reply.setTitle(gender + ' ' + docs[0].character.name)
Reply.setDescription(docs[0].character.age + ' Jahre, ' + docs[0].character.race + '/' + docs[0].character.culture)
Reply.addField(docs[0].character.professionname, docs[0].character.xp.startinglevel)
message.reply( Reply );
}
});
}
catch (e) {
throw e;
}
},
};

31
commands/skill.js Normal file
View File

@ -0,0 +1,31 @@
const globals = require('../globals')
const db = globals.db
module.exports = {
name: 'skill',
description: 'Zeigt dir deinen Fertigkeitswert im jeweiligen Talent.',
aliases: [],
usage: '<Fertigkeit>',
needs_args: true,
async exec(message, args) {
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 {
let level = 0;
for (i in docs[0].character.skills) {
if (docs[0].character.skills[i].id == args[0]) level = docs[0].character.skills[i].level;
}
message.reply('Du hast folgenden Talentwert in ' + args[0] + ': ' + level);
}
});
}
catch (e) {
throw e;
}
},
};

123
commands/talent.js Normal file
View File

@ -0,0 +1,123 @@
const globals = require('../globals');
const Random = require('random');
const Discord = require('discord.js')
const db = globals.db
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.',
aliases: ['t'],
usage: '<Talent> [<-Erschwernis> / <+Erleichterung>]',
needs_args: true,
async exec(message, args) {
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);
}
if(!isNaN(args[0])) {
return message.reply(globals.Replies.find(x => x.id === 'WRONG_ARGUMENTS').string)
}
else {
Random.use(message.author.tag);
const values = [];
const roll = [];
let found = false;
let talent;
let bonus = 0;
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);
for (i in result.values) {
const kuerzel = globals.Werte.find(wert => wert.kuerzel === result.values[i]);
for (val in docs[0].character.attributes) {
if (docs[0].character.attributes[val].id == kuerzel.id) values.push(docs[0].character.attributes[val].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]) {
ok++;
}
else if ((Math.floor(values[i]) + parseInt(bonus) + parseInt(erschwernis)) >= roll[i]) {
ok++;
bonus = bonus - (roll[i] - parseInt(erschwernis) - values[i]);
}
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.addFields({
name: 'Deine 🎲: ' + roll.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) {
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})
}
message.reply(Reply)
}
});
}
catch (e) {
throw e;
}
},
};

36
commands/talents.js Normal file
View File

@ -0,0 +1,36 @@
const globals = require('../globals');
const Discord = require('discord.js');
module.exports = {
name: 'talents',
description: '',
aliases: [],
usage: '',
needs_args: false,
async exec(message, args) {
const fields = [];
for (const i in globals.TalentKategorien) {
const ability = [];
for (const a in globals.Talente) {
if (globals.Talente[a].categoryid == i) {
ability.push(globals.Talente[a].id.charAt(0).toUpperCase() + globals.Talente[a].id.slice(1));
}
}
ability.sort();
fields.push(ability);
}
const Embed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle('Talentübersicht')
.setDescription('Das sind die Talente, die ich kenne:');
for (const i in fields) {
Embed.addField(globals.TalentKategorien[i], fields[i].join('\n'), true);
}
message.author.send(
Embed,
);
},
};

83
commands/tp.js Normal file
View File

@ -0,0 +1,83 @@
// eslint-disable-next-line no-unused-vars
const Random = require('random');
const globals = require('../globals')
const Discord = require('discord.js')
module.exports = {
name: 'tp',
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>]',
needs_args: true,
async exec(message, args) {
if(isNaN(args[0])) {
return message.reply(globals.Replies.find(x => x.id === 'WRONG_ARGUMENTS').string)
}
Random.use(message.author.tag);
const roll = [];
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));
}
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]) {
ok++;
} else if (
Math.floor(parseInt(args[i]) + parseInt(bonus) + parseInt(erschwernis)) >= roll[i]) {
ok++;
bonus = bonus - (roll[i] - parseInt(erschwernis) - parseInt(args[i]));
}
if (roll[i] == 1) crit++;
if (roll[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(', ') + '.')
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) {
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
})
}
message.reply(Reply)
}
}