Skip to content

Commit

Permalink
even more typings (...and some smol refactorings)
Browse files Browse the repository at this point in the history
hopefully the refactorings don't break anything lul, attempting to modify parseReply and getRandomIntFromInterval both broke like, immediately lol
  • Loading branch information
meadowsys committed Nov 14, 2023
1 parent 1a16dcf commit 18d4324
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 31 deletions.
31 changes: 18 additions & 13 deletions config/BestPony.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
8 changes: 2 additions & 6 deletions lib/Tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++]);
},

/**
Expand Down
46 changes: 34 additions & 12 deletions modules/BestPony/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> } 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();
}
Expand Down

0 comments on commit 18d4324

Please sign in to comment.