mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-13 00:09:08 +02:00
Add buttons to true/false
This commit is contained in:
@@ -1,10 +1,9 @@
|
|||||||
const Command = require('../../framework/Command');
|
const Command = require('../../framework/Command');
|
||||||
|
const { MessageActionRow, MessageButton } = require('discord.js');
|
||||||
const { stripIndents } = require('common-tags');
|
const { stripIndents } = require('common-tags');
|
||||||
const request = require('node-superfetch');
|
const request = require('node-superfetch');
|
||||||
const { list } = require('../../util/Util');
|
const { list } = require('../../util/Util');
|
||||||
const difficulties = ['easy', 'medium', 'hard'];
|
const difficulties = ['easy', 'medium', 'hard'];
|
||||||
const trueAns = ['true', 't', 'tru', 'yes', 'y'];
|
|
||||||
const falseAns = ['false', 'f', 'no', 'n'];
|
|
||||||
|
|
||||||
module.exports = class TrueOrFalseCommand extends Command {
|
module.exports = class TrueOrFalseCommand extends Command {
|
||||||
constructor(client) {
|
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!');
|
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 correct = decodeURIComponent(body.results[0].correct_answer.toLowerCase());
|
||||||
const correctBool = correct === 'true';
|
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`
|
await msg.reply(stripIndents`
|
||||||
**You have 15 seconds to answer this question.**
|
**You have 15 seconds to answer this question.**
|
||||||
${decodeURIComponent(body.results[0].question)}
|
${decodeURIComponent(body.results[0].question)}
|
||||||
**[T]rue or [F]alse?**
|
`, { components: [row] });
|
||||||
`);
|
const filter = res => res.author.id !== msg.author.id;
|
||||||
const filter = res => {
|
const interactions = await msg.awaitMessageComponentInteractions(filter, {
|
||||||
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, {
|
|
||||||
max: 1,
|
max: 1,
|
||||||
time: 15000
|
time: 15000
|
||||||
});
|
});
|
||||||
if (!msgs.size) return msg.reply(`Sorry, time is up! It was ${correctBool}.`);
|
if (!interactions.size) return msg.edit(`Sorry, time is up! It was ${correctBool}.`, { components: [] });
|
||||||
const ans = msgs.first().content.toLowerCase();
|
const ans = interactions.first().customID === 'true';
|
||||||
const ansBool = trueAns.includes(ans);
|
if (correctBool !== ans) return msg.edit(`Nope, sorry, it's ${correctBool}.`, { components: [] });
|
||||||
if (correctBool !== ansBool) return msg.reply(`Nope, sorry, it's ${correctBool}.`);
|
return msg.edit('Nice job! 10/10! You deserve some cake!', { components: [] });
|
||||||
return msg.reply('Nice job! 10/10! You deserve some cake!');
|
|
||||||
} catch (err) {
|
} 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() {
|
enable() {
|
||||||
this._enabled = true;
|
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