diff --git a/commands/games-sp/jeopardy.js b/commands/games-sp/jeopardy.js index 52427fd2..6f734b59 100644 --- a/commands/games-sp/jeopardy.js +++ b/commands/games-sp/jeopardy.js @@ -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!`); } }