Fix button-based stuff

This commit is contained in:
Dragon Fire
2024-03-21 16:32:39 -04:00
parent 60b4d5b5b7
commit 99b71f5657
5 changed files with 63 additions and 54 deletions
+24 -23
View File
@@ -48,16 +48,16 @@ module.exports = class AkinatorCommand extends Command {
const gameMsg = await msg.reply('Welcome to Akinator! Think of a character, and I will try to guess it.', {
components: [initialRow]
});
const initialVerify = await gameMsg.awaitMessageComponent({
filter: res => res.user.id === msg.author.id,
max: 1,
time: 30000
});
if (!initialVerify.size) {
try {
const initialVerify = await gameMsg.awaitMessageComponent({
filter: res => res.user.id === msg.author.id,
max: 1,
time: 30000
});
if (initialVerify.customId === 'false') return initialVerify.update('Too bad...', { components: [] });
} catch {
return gameMsg.edit('Guess you didn\'t want to play after all...', { components: [] });
}
let buttonPress = initialVerify.first();
if (buttonPress.customId === 'false') return buttonPress.update('Too bad...', { components: [] });
}
await this.sendLoadingMessage(buttonPress, [initialRow]);
const guessBlacklist = [];
while (timesGuessed < 3) {
@@ -87,16 +87,17 @@ module.exports = class AkinatorCommand extends Command {
`**${aki.currentStep + 1}.** ${aki.question} (${Math.round(Number.parseInt(aki.progress, 10))}%)`,
{ components: [row, sRow] }
);
const interactions = await gameMsg.awaitMessageComponent({
filter: res => res.user.id === msg.author.id,
max: 1,
time: 30000
});
if (!interactions.size) {
let buttonPress;
try {
buttonPress = await gameMsg.awaitMessageComponent({
filter: res => res.user.id === msg.author.id,
max: 1,
time: 30000
});
} catch {
win = 'time';
break;
}
buttonPress = interactions.first();
await this.sendLoadingMessage(buttonPress, [row, sRow]);
const choice = interactions.first().customId;
if (choice === 'end') {
@@ -130,16 +131,16 @@ module.exports = class AkinatorCommand extends Command {
new MessageButton().setCustomId('false').setLabel('No').setStyle('DANGER')
);
await buttonPress.editReply('Is this your character?', { embeds: [embed], components: [guessRow] });
const verification = await gameMsg.awaitMessageComponent({
filter: res => res.user.id === msg.author.id,
max: 1,
time: 30000
});
if (!verification.size) {
try {
buttonPress = await gameMsg.awaitMessageComponent({
filter: res => res.user.id === msg.author.id,
max: 1,
time: 30000
});
} catch {
win = 'time';
break;
}
buttonPress = verification.first();
await this.sendLoadingMessage(buttonPress, [guessRow]);
if (buttonPress.customId === 'true') {
win = false;
+12 -10
View File
@@ -56,15 +56,17 @@ module.exports = class TrueOrFalseCommand extends Command {
${decodeURIComponent(body.results[0].question)}
`, { components: [row] });
const filter = res => res.user.id === msg.author.id;
const interactions = await questionMsg.awaitMessageComponent({
filter,
max: 1,
time: 15000
});
if (!interactions.size) return questionMsg.edit(`Sorry, time is up! It was ${correctBool}.`, { components: [] });
const ans = interactions.first();
const ansBool = ans.customId === 'true';
if (correctBool !== ansBool) return ans.update(`Nope, sorry, it's ${correctBool}.`, { components: [] });
return ans.update('Nice job! 10/10! You deserve some cake!', { components: [] });
try {
const ans = await questionMsg.awaitMessageComponent({
filter,
max: 1,
time: 15000
});
const ansBool = ans.customId === 'true';
if (correctBool !== ansBool) return ans.update(`Nope, sorry, it's ${correctBool}.`, { components: [] });
return ans.update('Nice job! 10/10! You deserve some cake!', { components: [] });
} catch {
return questionMsg.edit(`Sorry, time is up! It was ${correctBool}.`, { components: [] });
}
}
};