diff --git a/commands/Talents.js b/commands/Talents.js index 60c2f6b..feb9833 100644 --- a/commands/Talents.js +++ b/commands/Talents.js @@ -1,6 +1,6 @@ const globals = require('../globals'); const Discord = require('discord.js'); - +const { Capitalize } = require('@dsabot/Capitalize'); module.exports = { name: 'talents', @@ -10,27 +10,33 @@ module.exports = { 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); + for (let Talent of GenerateTalentList()) { + Embed.addField(Talent.Category, Talent.Talents.join('\n'), true); } 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(); }; \ No newline at end of file diff --git a/commands/Weapons.js b/commands/Weapons.js index 4c69e3a..cbcdfa2 100644 --- a/commands/Weapons.js +++ b/commands/Weapons.js @@ -1,5 +1,6 @@ const globals = require('../globals'); const Discord = require('discord.js'); +const { Capitalize } = require('@dsabot/Capitalize'); module.exports = { @@ -38,6 +39,3 @@ const GenerateWeaponList = () => { return WeaponList.sort(); }; -const Capitalize = (Word = '') => { - return Word[0].toUpperCase() + Word.substring(1); -}; \ No newline at end of file diff --git a/functions/Capitalize.js b/functions/Capitalize.js new file mode 100644 index 0000000..91360c3 --- /dev/null +++ b/functions/Capitalize.js @@ -0,0 +1,5 @@ +const Capitalize = (Word = 'none') => { + return Word[0].toUpperCase() + Word.substring(1); +}; + +module.exports = { Capitalize };