mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Add buttons to true/false
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
const Command = require('../../framework/Command');
|
||||
const { MessageActionRow, MessageButton } = require('discord.js');
|
||||
const { stripIndents } = require('common-tags');
|
||||
const request = require('node-superfetch');
|
||||
const { list } = require('../../util/Util');
|
||||
const difficulties = ['easy', 'medium', 'hard'];
|
||||
const trueAns = ['true', 't', 'tru', 'yes', 'y'];
|
||||
const falseAns = ['false', 'f', 'no', 'n'];
|
||||
|
||||
module.exports = class TrueOrFalseCommand extends Command {
|
||||
constructor(client) {
|
||||
@@ -49,26 +48,25 @@ module.exports = class TrueOrFalseCommand extends Command {
|
||||
if (!body.results) return msg.reply('Oh no, a question could not be fetched. Try again later!');
|
||||
const correct = decodeURIComponent(body.results[0].correct_answer.toLowerCase());
|
||||
const correctBool = correct === 'true';
|
||||
const row = new MessageActionRow().addComponents(
|
||||
new MessageButton().setCustomID('true').setStyle('SUCCESS').setLabel('True'),
|
||||
new MessageButton().setCustomID('false').setStyle('DANGER').setLabel('False')
|
||||
);
|
||||
await msg.reply(stripIndents`
|
||||
**You have 15 seconds to answer this question.**
|
||||
${decodeURIComponent(body.results[0].question)}
|
||||
**[T]rue or [F]alse?**
|
||||
`);
|
||||
const filter = res => {
|
||||
if (res.author.id !== msg.author.id) return false;
|
||||
return trueAns.includes(res.content.toLowerCase()) || falseAns.includes(res.content.toLowerCase());
|
||||
};
|
||||
const msgs = await msg.channel.awaitMessages(filter, {
|
||||
`, { components: [row] });
|
||||
const filter = res => res.author.id !== msg.author.id;
|
||||
const interactions = await msg.awaitMessageComponentInteractions(filter, {
|
||||
max: 1,
|
||||
time: 15000
|
||||
});
|
||||
if (!msgs.size) return msg.reply(`Sorry, time is up! It was ${correctBool}.`);
|
||||
const ans = msgs.first().content.toLowerCase();
|
||||
const ansBool = trueAns.includes(ans);
|
||||
if (correctBool !== ansBool) return msg.reply(`Nope, sorry, it's ${correctBool}.`);
|
||||
return msg.reply('Nice job! 10/10! You deserve some cake!');
|
||||
if (!interactions.size) return msg.edit(`Sorry, time is up! It was ${correctBool}.`, { components: [] });
|
||||
const ans = interactions.first().customID === 'true';
|
||||
if (correctBool !== ans) return msg.edit(`Nope, sorry, it's ${correctBool}.`, { components: [] });
|
||||
return msg.edit('Nice job! 10/10! You deserve some cake!', { components: [] });
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
return msg.edit(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -51,4 +51,11 @@ module.exports = class Command {
|
||||
enable() {
|
||||
this._enabled = true;
|
||||
}
|
||||
|
||||
reload() {
|
||||
delete require.cache[require.resolve(`../commands/${this.groupID}/${this.memberName}.js`)];
|
||||
const NewCmd = require(`../commands/${this.groupID}/${this.memberName}.js`);
|
||||
this.client.registry.commands.delete(this.name);
|
||||
this.client.registry.registerCommand(this.name, new NewCmd(this.client));
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user