diff --git a/config/BestPony.json b/config/BestPony.json index 4036e2a..168a3ac 100644 --- a/config/BestPony.json +++ b/config/BestPony.json @@ -1,28 +1,33 @@ { - "bestPonyAnswer1": [ + "who": "best_pony", + "who_answer": [ "%s %s I am, of course!" ], - "bestPonyAnswer2": [ + + "canni": "canni_best_pony", + "canni_answer": [ "%s I sure am!" ], - "bestPonyAnswer3": [ + + "bizaam": "bizaam_best_pony", + "bizaam_answer": [ "%s A bizaam isn't a pony, silly..." ], - "bestPonyAnswer4": [ + + "assfart": "assfart_best_pony", + "assfart_answer": [ "%s Rude!" ], - "bestPonyAnswer5": [ + + "fanta": "fanta_best_pony", + "fanta_answer": [ "%s Is this a GalaCon thing?", "%s I'm fuelled by Fanta. Therefore I am best pony.", "%s Fanta is a carbonated soft drink and most definitely not a pony..." ], - "bestPonyAnswerDefault": [ + + "interject": "interject_best_pony", + "interject_answer": [ "%s Nu-uh. I am best pony!" - ], - "bestPonyType": "bestPony", - "canniBestPonyType": "canniBestPony", - "bizaamBestPonyType": "bizaamBestPony", - "assFartBestPonyType": "assfartBestPony", - "fantaBestPonyType:": "fantaBestPony", - "interjectType": "interject" + ] } diff --git a/lib/Tools.js b/lib/Tools.js index d621c7d..0df51e6 100644 --- a/lib/Tools.js +++ b/lib/Tools.js @@ -264,12 +264,8 @@ const Tools = { */ parseReply(str, ...args) { let i = 0; - - try { - return str.replace(/%s/g, () => args[0][i++]); - } catch (error) { - return str.replace(/%s/g, () => args[i++]); - } + args = args.flat(); + return str.replace(/%s/g, () => args[i++]); }, /** diff --git a/modules/BestPony/module.js b/modules/BestPony/module.js index 5eda936..7c31222 100644 --- a/modules/BestPony/module.js +++ b/modules/BestPony/module.js @@ -22,26 +22,48 @@ module.exports = class BestPony extends Module { }); } + /** + * @param { import("discord.js").Message } msg + */ handle(msg) { if (Tools.msg_contains(msg, "who is best pony")) { - this.whoIsBestPony(msg, this.config.bestPonyType, this.config.bestPonyAnswer1, "gc_cannibizaam"); - } else if (Tools.msg_contains(msg, "canni is best pony") || Tools.msg_contains(msg, "canni soda is best pony")) { - this.whoIsBestPony(msg, this.config.canniBestPonyType, this.config.bestPonyAnswer2); - } else if (/b+i+z+a+m+ is best pony/i.test(msg.content)) { - this.whoIsBestPony(msg, this.config.bizaamBestPonyType, this.config.bestPonyAnswer3); - } else if (Tools.msg_contains(msg, "assfart is best pony")) { - this.whoIsBestPony(msg, this.config.assFartBestPonyType, this.config.bestPonyAnswer4); - } else if (Tools.msg_contains(msg, "fanta is best pony")) { - this.whoIsBestPony(msg, this.config.fantaBestPony, this.config.bestPonyAnswer5); - } else { - this.whoIsBestPony(msg, this.config.interjectType, this.config.bestPonyAnswerDefault); + return this.whoIsBestPony(msg, this.config.who, this.config.who_answer, "gc_cannibizaam"); } + + if (Tools.msg_contains(msg, "canni is best pony") || Tools.msg_contains(msg, "canni soda is best pony")) { + return this.whoIsBestPony(msg, this.config.canni, this.config.canni_answer); + } + + if (/b+i+z+a+m+ is best pony/i.test(msg.content)) { + return this.whoIsBestPony(msg, this.config.bizaam, this.config.bizaam_answer); + } + + if (Tools.msg_contains(msg, "assfart is best pony")) { + return this.whoIsBestPony(msg, this.config.assfart, this.config.assfart_answer); + } + + if (Tools.msg_contains(msg, "fanta is best pony")) { + return this.whoIsBestPony(msg, this.config.fanta, this.config.fanta_answer); + } + + this.whoIsBestPony(msg, this.config.interject, this.config.interject_answer); } + /** + * @param { import("discord.js").Message } msg + * @param { string } type + * @param { Array } answers + * @param { string } emoji + */ whoIsBestPony(msg, type, answers, emoji = "") { if (Application.modules.Discord.controlTalkedRecently(msg, type)) { const random = Tools.getRandomIntFromInterval(0, answers.length - 1); - msg.channel.send(Tools.parseReply(answers[random], [msg.author, Application.modules.Discord.getEmoji(emoji)])); + + msg.channel.send(Tools.parseReply( + answers[random], + msg.author.toString(), + Application.modules.Discord.getEmoji(emoji).toString() + )); Application.modules.Discord.setMessageSent(); }