mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Fix
This commit is contained in:
@@ -13,6 +13,7 @@ module.exports = class TwentyQuestionsCommand extends Command {
|
||||
group: 'games-sp',
|
||||
memberName: '20-questions',
|
||||
description: 'Think of something and 20Q will read your mind by asking a few simple questions.',
|
||||
game: true,
|
||||
credit: [
|
||||
{
|
||||
name: '20Q.net',
|
||||
@@ -33,53 +34,44 @@ module.exports = class TwentyQuestionsCommand extends Command {
|
||||
}
|
||||
|
||||
async run(msg, { game }) {
|
||||
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 {
|
||||
const startURL = await this.initialize(game);
|
||||
let question = await this.startGame(game, startURL);
|
||||
let win = null;
|
||||
this.client.games.set(msg.channel.id, { name: this.name });
|
||||
while (win === null) {
|
||||
const answers = question.answers.map(answer => answer.text.toLowerCase());
|
||||
answers.push('end');
|
||||
await msg.say(stripIndents`
|
||||
**${question.question}**
|
||||
${question.answers.map(answer => answer.text).join(' | ')} | End
|
||||
`);
|
||||
const filter = res => res.author.id === msg.author.id && answers.includes(res.content.toLowerCase());
|
||||
const msgs = await msg.channel.awaitMessages({
|
||||
filter,
|
||||
max: 1,
|
||||
time: 30000
|
||||
});
|
||||
if (!msgs.size) {
|
||||
await msg.say('Sorry, time is up!');
|
||||
win = 'time';
|
||||
break;
|
||||
}
|
||||
const choice = msgs.first().content.toLowerCase();
|
||||
if (choice === 'end') {
|
||||
win = 'time';
|
||||
break;
|
||||
}
|
||||
const answer = question.answers[answers.indexOf(choice)];
|
||||
question = await this.nextQuestion(game, answer.href, question.url);
|
||||
if (typeof question.win !== 'undefined') {
|
||||
win = question.win;
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.client.games.delete(msg.channel.id);
|
||||
if (win === 'time') return msg.say('Game ended due to forfeit.');
|
||||
return msg.say(stripIndents`
|
||||
**${question.winText}**
|
||||
${question.result}
|
||||
const startURL = await this.initialize(game);
|
||||
let question = await this.startGame(game, startURL);
|
||||
let win = null;
|
||||
while (win === null) {
|
||||
const answers = question.answers.map(answer => answer.text.toLowerCase());
|
||||
answers.push('end');
|
||||
await msg.say(stripIndents`
|
||||
**${question.question}**
|
||||
${question.answers.map(answer => answer.text).join(' | ')} | End
|
||||
`);
|
||||
} catch (err) {
|
||||
this.client.games.delete(msg.channel.id);
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
const filter = res => res.author.id === msg.author.id && answers.includes(res.content.toLowerCase());
|
||||
const msgs = await msg.channel.awaitMessages({
|
||||
filter,
|
||||
max: 1,
|
||||
time: 30000
|
||||
});
|
||||
if (!msgs.size) {
|
||||
await msg.say('Sorry, time is up!');
|
||||
win = 'time';
|
||||
break;
|
||||
}
|
||||
const choice = msgs.first().content.toLowerCase();
|
||||
if (choice === 'end') {
|
||||
win = 'time';
|
||||
break;
|
||||
}
|
||||
const answer = question.answers[answers.indexOf(choice)];
|
||||
question = await this.nextQuestion(game, answer.href, question.url);
|
||||
if (typeof question.win !== 'undefined') {
|
||||
win = question.win;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (win === 'time') return msg.say('Game ended due to forfeit.');
|
||||
return msg.say(stripIndents`
|
||||
**${question.winText}**
|
||||
${question.result}
|
||||
`);
|
||||
}
|
||||
|
||||
makeBaseURI(game) {
|
||||
|
||||
Reference in New Issue
Block a user