End jeopardy music when game ends

This commit is contained in:
Dragon Fire
2020-05-24 18:48:41 -04:00
parent c6512200c7
commit 6cb1783e21
+6
View File
@@ -38,7 +38,10 @@ module.exports = class JeopardyCommand extends Command {
}
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.`);
try {
this.client.games.set(msg.channel.id, { name: this.name });
const question = await this.fetchQuestion();
const clueCard = await this.generateClueCard(question.question.replace(/<\/?i>/gi, ''));
const connection = msg.guild ? this.client.voice.connections.get(msg.guild.id) : null;
@@ -55,12 +58,15 @@ module.exports = class JeopardyCommand extends Command {
max: 1,
time: 30000
});
if (connection) connection.dispatcher.end();
const answer = question.answer.replace(/<\/?i>/gi, '*');
this.client.games.delete(msg.channel.id);
if (!msgs.size) return msg.reply(`Time's up, the answer was **${answer}**.`);
const win = msgs.first().content.toLowerCase() === answer.toLowerCase();
if (!win) return msg.reply(`The answer was **${answer}**.`);
return msg.reply(`The answer was **${answer}**. Good job!`);
} catch (err) {
this.client.games.delete(msg.channel.id);
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}