mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-18 13:56:25 +02:00
Buttons in lie-swatter
This commit is contained in:
@@ -1,11 +1,9 @@
|
|||||||
const Command = require('../../framework/Command');
|
const Command = require('../../framework/Command');
|
||||||
|
const { ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js');
|
||||||
const request = require('node-superfetch');
|
const request = require('node-superfetch');
|
||||||
const { stripIndents } = require('common-tags');
|
const { stripIndents } = require('common-tags');
|
||||||
const { Collection } = require('@discordjs/collection');
|
const { Collection } = require('@discordjs/collection');
|
||||||
const { delay, awaitPlayers, reactIfAble } = require('../../util/Util');
|
const { delay, awaitPlayers } = require('../../util/Util');
|
||||||
const { SUCCESS_EMOJI_ID } = process.env;
|
|
||||||
const trueOptions = ['true', 'yes', 'the truth', 't', 'tru', 'tr', 'y', 'ye'];
|
|
||||||
const falseOptions = ['false', 'lie', 'no', 'a lie', 'f', 'fals', 'fal', 'fa', 'n', 'l'];
|
|
||||||
|
|
||||||
module.exports = class LieSwatterCommand extends Command {
|
module.exports = class LieSwatterCommand extends Command {
|
||||||
constructor(client) {
|
constructor(client) {
|
||||||
@@ -53,27 +51,23 @@ module.exports = class LieSwatterCommand extends Command {
|
|||||||
}
|
}
|
||||||
const questions = await this.fetchQuestions();
|
const questions = await this.fetchQuestions();
|
||||||
let lastTurnTimeout = false;
|
let lastTurnTimeout = false;
|
||||||
|
const gameMsg = await msg.say('Loading...');
|
||||||
while (questions.length) {
|
while (questions.length) {
|
||||||
++turn;
|
++turn;
|
||||||
const question = questions[0];
|
const question = questions[0];
|
||||||
questions.shift();
|
questions.shift();
|
||||||
await msg.say(`**(${turn}) ${question.category}**\n${question.question}\n\n_Is it True or is it a Lie?_`);
|
const row = new ActionRowBuilder().addComponents(
|
||||||
const filter = res => {
|
new ButtonBuilder().setCustomId('true').setStyle(ButtonStyle.Success).setLabel('The Truth'),
|
||||||
if (!awaitedPlayers.includes(res.author.id)) return false;
|
new ButtonBuilder().setCustomId('false').setStyle(ButtonStyle.Danger).setLabel('A Lie')
|
||||||
const answer = res.content.toLowerCase();
|
);
|
||||||
if (trueOptions.includes(answer) || falseOptions.includes(answer)) {
|
await gameMsg.edit(`**(${turn}) ${question.category}**\n${question.question}`, { components: [row] });
|
||||||
reactIfAble(res, res.author, SUCCESS_EMOJI_ID, '✅');
|
const choices = await msg.channel.awaitMessageComponent({
|
||||||
return true;
|
filter: res => awaitedPlayers.includes(res.author.id),
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
const msgs = await msg.channel.awaitMessages({
|
|
||||||
filter,
|
|
||||||
max: pts.size,
|
max: pts.size,
|
||||||
time: 30000
|
time: 30000
|
||||||
});
|
});
|
||||||
if (!msgs.size) {
|
if (!choices.size) {
|
||||||
await msg.say(`No answers? Well, it was ${question.answer ? 'true' : 'a lie'}.`);
|
await gameMsg.edit(`No answers? Well, it was ${question.answer ? 'true' : 'a lie'}.`, { components: [] });
|
||||||
if (lastTurnTimeout) {
|
if (lastTurnTimeout) {
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
@@ -81,10 +75,10 @@ module.exports = class LieSwatterCommand extends Command {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const answers = msgs.map(res => {
|
const answers = choices.map(ans => {
|
||||||
let answer;
|
let answer;
|
||||||
if (trueOptions.includes(res.content.toLowerCase())) answer = true;
|
if (ans.customId === 'true') answer = true;
|
||||||
else if (falseOptions.includes(res.content.toLowerCase())) answer = false;
|
else if (ans.customId === 'false') answer = false;
|
||||||
return { answer, id: res.author.id };
|
return { answer, id: res.author.id };
|
||||||
});
|
});
|
||||||
const correct = answers.filter(answer => answer.answer === question.answer);
|
const correct = answers.filter(answer => answer.answer === question.answer);
|
||||||
@@ -93,17 +87,17 @@ module.exports = class LieSwatterCommand extends Command {
|
|||||||
if (correct[0].id === answer.id) player.points += 75;
|
if (correct[0].id === answer.id) player.points += 75;
|
||||||
else player.points += 50;
|
else player.points += 50;
|
||||||
}
|
}
|
||||||
await msg.say(stripIndents`
|
await gameMsg.edit(stripIndents`
|
||||||
It was... **${question.answer ? 'true' : 'a lie'}**!
|
It was... **${question.answer ? 'true' : 'a lie'}**!
|
||||||
|
|
||||||
_Fastest Guess: ${correct.length ? `${pts.get(correct[0].id).user.tag} (+75 pts)` : 'No One...'}_
|
_Fastest Guess: ${correct.length ? `${pts.get(correct[0].id).user.tag} (+75 pts)` : 'No One...'}_
|
||||||
${questions.length ? '_Next round starting in 5 seconds..._' : ''}
|
${questions.length ? '_Next round starting in 5 seconds..._' : ''}
|
||||||
`);
|
`, { components: [] });
|
||||||
if (lastTurnTimeout) lastTurnTimeout = false;
|
if (lastTurnTimeout) lastTurnTimeout = false;
|
||||||
if (questions.length) await delay(5000);
|
if (questions.length) await delay(5000);
|
||||||
}
|
}
|
||||||
const winner = pts.sort((a, b) => b.points - a.points).first().user;
|
const winner = pts.sort((a, b) => b.points - a.points).first().user;
|
||||||
return msg.say(stripIndents`
|
return gameMsg.edit(stripIndents`
|
||||||
Congrats, ${winner}!
|
Congrats, ${winner}!
|
||||||
|
|
||||||
__**Top 10:**__
|
__**Top 10:**__
|
||||||
|
|||||||
@@ -53,10 +53,9 @@ module.exports = class TrueOrFalseCommand extends Command {
|
|||||||
**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)}
|
||||||
`, { components: [row] });
|
`, { components: [row] });
|
||||||
const filter = res => res.user.id === msg.author.id;
|
|
||||||
try {
|
try {
|
||||||
const ans = await questionMsg.awaitMessageComponent({
|
const ans = await questionMsg.awaitMessageComponent({
|
||||||
filter,
|
filter: res => res.user.id === msg.author.id,
|
||||||
max: 1,
|
max: 1,
|
||||||
time: 15000
|
time: 15000
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user