Mad Libs Command

This commit is contained in:
Dragon Fire
2020-02-04 18:07:38 -05:00
parent 5f3071f653
commit 95f4630cd4
4 changed files with 161 additions and 2 deletions
+58
View File
@@ -0,0 +1,58 @@
const Command = require('../../structures/Command');
const libs = require('../../assets/json/mad-libs');
module.exports = class MadLibsCommand extends Command {
constructor(client) {
super(client, {
name: 'mad-libs',
group: 'sp-games',
memberName: 'mad-libs',
description: 'Choose words that fill in the blanks to create a crazy story!',
credit: [
{
name: 'Mad Libs',
url: 'http://www.madlibs.com/',
reason: 'Original Game'
},
{
name: 'Mad:)Takes',
url: 'https://www.madtakes.com/index.php',
reason: 'Mad Libs Data'
}
]
});
}
async run(msg) {
const current = this.client.games.get(msg.channel.id);
if (current) return msg.reply(`Please wait until the current game of \`${current.name}\` is finished.`);
this.client.games.set(msg.channel.id, { name: this.name });
try {
const lib = libs[Math.floor(Math.random() * libs.length)];
const choices = [];
for (const word of lib.needed) {
await msg.reply(`Give me a **${word}**.`);
const filter = res => {
if (!res.content || res.content.length > 12) {
msg.reply('Please only use a maximum of 12 characters per word.').catch(() => null);
return false;
}
return res.author.id === msg.author.id;
}
const choice = await msg.channel.awaitMessages(filter, {
max: 1,
time: 120000
});
if (!choice.size) break;
choices.push(choice.first().content);
}
this.client.games.delete(msg.channel.id);
let finished = lib.text;
for (let i = 0; i < choices.length; i++) finished = finished.replace(`{${i}}`, `**${choices[i]}**`);
return msg.say(finished);
} catch (err) {
this.client.games.delete(msg.channel.id);
throw err;
}
}
};