mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-25 22:32:50 +02:00
Fix
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
const Command = require('../../framework/Command');
|
const Command = require('../../framework/Command');
|
||||||
const { ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js');
|
const { ActionRowBuilder, ButtonBuilder, ButtonStyle, ComponentType } = 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');
|
||||||
@@ -64,17 +64,8 @@ module.exports = class LieSwatterCommand extends Command {
|
|||||||
content: `**(${turn}) ${question.category}**\n${question.question}`,
|
content: `**(${turn}) ${question.category}**\n${question.question}`,
|
||||||
components: [row]
|
components: [row]
|
||||||
});
|
});
|
||||||
let choices;
|
const answers = await this.getChoices(msg, pts.size, awaitedPlayers);
|
||||||
try {
|
if (!answers) {
|
||||||
choices = await msg.channel.awaitMessageComponent({
|
|
||||||
filter: res => awaitedPlayers.includes(res.user.id),
|
|
||||||
max: pts.size,
|
|
||||||
time: 30000
|
|
||||||
});
|
|
||||||
} catch {
|
|
||||||
choices = null;
|
|
||||||
}
|
|
||||||
if (!choices) {
|
|
||||||
await gameMsg.edit({
|
await gameMsg.edit({
|
||||||
content: `No answers? Well, it was ${question.answer ? 'true' : 'a lie'}.`,
|
content: `No answers? Well, it was ${question.answer ? 'true' : 'a lie'}.`,
|
||||||
components: []
|
components: []
|
||||||
@@ -86,12 +77,6 @@ module.exports = class LieSwatterCommand extends Command {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const answers = choices.map(ans => {
|
|
||||||
let answer;
|
|
||||||
if (ans.customId === 'true') answer = true;
|
|
||||||
else if (ans.customId === 'false') answer = false;
|
|
||||||
return { answer, id: res.author.id };
|
|
||||||
});
|
|
||||||
const correct = answers.filter(answer => answer.answer === question.answer);
|
const correct = answers.filter(answer => answer.answer === question.answer);
|
||||||
for (const answer of correct) {
|
for (const answer of correct) {
|
||||||
const player = pts.get(answer.id);
|
const player = pts.get(answer.id);
|
||||||
@@ -122,6 +107,28 @@ module.exports = class LieSwatterCommand extends Command {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getChoices(msg, max, players) {
|
||||||
|
const collector = msg.channel.createMessageComponentCollector({
|
||||||
|
filter: res => players.includes(res.user.id),
|
||||||
|
componentType: ComponentType.Button,
|
||||||
|
max: max,
|
||||||
|
time: 30000
|
||||||
|
});
|
||||||
|
const answers = [];
|
||||||
|
collector.on('collect', interaction => {
|
||||||
|
let answer;
|
||||||
|
if (interaction.customId === 'true') answer = true;
|
||||||
|
if (interaction.customId === 'false') answer = false;
|
||||||
|
answers.push({ id: interaction.user.id, answer });
|
||||||
|
});
|
||||||
|
return new Promise(res => {
|
||||||
|
collector.once('end', () => {
|
||||||
|
if (answers.length === 0) res(null);
|
||||||
|
return res(answers);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async fetchQuestions() {
|
async fetchQuestions() {
|
||||||
const { body } = await request
|
const { body } = await request
|
||||||
.get('https://opentdb.com/api.php')
|
.get('https://opentdb.com/api.php')
|
||||||
|
|||||||
Reference in New Issue
Block a user