mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-18 21:40:49 +02:00
End jeopardy music when game ends
This commit is contained in:
@@ -38,7 +38,10 @@ module.exports = class JeopardyCommand extends Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async run(msg) {
|
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 {
|
try {
|
||||||
|
this.client.games.set(msg.channel.id, { name: this.name });
|
||||||
const question = await this.fetchQuestion();
|
const question = await this.fetchQuestion();
|
||||||
const clueCard = await this.generateClueCard(question.question.replace(/<\/?i>/gi, ''));
|
const clueCard = await this.generateClueCard(question.question.replace(/<\/?i>/gi, ''));
|
||||||
const connection = msg.guild ? this.client.voice.connections.get(msg.guild.id) : null;
|
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,
|
max: 1,
|
||||||
time: 30000
|
time: 30000
|
||||||
});
|
});
|
||||||
|
if (connection) connection.dispatcher.end();
|
||||||
const answer = question.answer.replace(/<\/?i>/gi, '*');
|
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}**.`);
|
if (!msgs.size) return msg.reply(`Time's up, the answer was **${answer}**.`);
|
||||||
const win = msgs.first().content.toLowerCase() === answer.toLowerCase();
|
const win = msgs.first().content.toLowerCase() === answer.toLowerCase();
|
||||||
if (!win) return msg.reply(`The answer was **${answer}**.`);
|
if (!win) return msg.reply(`The answer was **${answer}**.`);
|
||||||
return msg.reply(`The answer was **${answer}**. Good job!`);
|
return msg.reply(`The answer was **${answer}**. Good job!`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
this.client.games.delete(msg.channel.id);
|
||||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user