mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Fix button-based stuff
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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: [] });
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -56,17 +56,19 @@ module.exports = class Game {
|
||||
}
|
||||
|
||||
createJoinLeaveCollector() {
|
||||
const collector = this.channel.createMessageCollector(res => {
|
||||
if (res.author.bot) return false;
|
||||
if (this.players.has(res.author.id) && res.content.toLowerCase() !== 'leave game') return false;
|
||||
if (!this.players.has(res.author.id) && res.content.toLowerCase() !== 'join game') return false;
|
||||
if (this.czar.id === res.author.id || this.players.size >= 10) {
|
||||
reactIfAble(res, res.author, FAILURE_EMOJI_ID, '❌');
|
||||
return false;
|
||||
const collector = this.channel.createMessageCollector({
|
||||
filter: res => {
|
||||
if (res.author.bot) return false;
|
||||
if (this.players.has(res.author.id) && res.content.toLowerCase() !== 'leave game') return false;
|
||||
if (!this.players.has(res.author.id) && res.content.toLowerCase() !== 'join game') return false;
|
||||
if (this.czar.id === res.author.id || this.players.size >= 10) {
|
||||
reactIfAble(res, res.author, FAILURE_EMOJI_ID, '❌');
|
||||
return false;
|
||||
}
|
||||
if (!['join game', 'leave game'].includes(res.content.toLowerCase())) return false;
|
||||
reactIfAble(res, res.author, SUCCESS_EMOJI_ID, '✅');
|
||||
return true;
|
||||
}
|
||||
if (!['join game', 'leave game'].includes(res.content.toLowerCase())) return false;
|
||||
reactIfAble(res, res.author, SUCCESS_EMOJI_ID, '✅');
|
||||
return true;
|
||||
});
|
||||
collector.on('collect', msg => {
|
||||
if (msg.content.toLowerCase() === 'join game') this.addUser(msg.author);
|
||||
|
||||
@@ -53,16 +53,19 @@ module.exports = class Player {
|
||||
await this.sendHand(hand, black);
|
||||
let gambled = false;
|
||||
let swapped = false;
|
||||
const collector = this.user.dmChannel.createMessageCollector(res => {
|
||||
if (res.content.toLowerCase() === 'swap' && this.points > 0 && !swapped) return true;
|
||||
if (res.content.toLowerCase() === 'gamble' && this.points > 0 && !gambled) return true;
|
||||
const existing = hand[Number.parseInt(res.content, 10) - 1];
|
||||
if (!existing || chosen.includes(existing)) {
|
||||
reactIfAble(res, res.author, FAILURE_EMOJI_ID, '❌');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}, { time: 60000 });
|
||||
const collector = this.user.dmChannel.createMessageCollector({
|
||||
filter: res => {
|
||||
if (res.content.toLowerCase() === 'swap' && this.points > 0 && !swapped) return true;
|
||||
if (res.content.toLowerCase() === 'gamble' && this.points > 0 && !gambled) return true;
|
||||
const existing = hand[Number.parseInt(res.content, 10) - 1];
|
||||
if (!existing || chosen.includes(existing)) {
|
||||
reactIfAble(res, res.author, FAILURE_EMOJI_ID, '❌');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
time: 60000
|
||||
});
|
||||
collector.on('collect', async msg => {
|
||||
const existing = hand[Number.parseInt(msg.content, 10) - 1];
|
||||
if (msg.content.toLowerCase() === 'swap') {
|
||||
|
||||
+2
-1
@@ -359,7 +359,8 @@ module.exports = class Util {
|
||||
if (joined.includes(interaction.user.id)) return false;
|
||||
return true;
|
||||
};
|
||||
const collector = msg.channel.createMessageComponentCollector(filter, {
|
||||
const collector = msg.channel.createMessageComponentCollector({
|
||||
filter,
|
||||
componentType: 'BUTTON',
|
||||
max: max - 1,
|
||||
time: 120000
|
||||
|
||||
Reference in New Issue
Block a user