Finish removing "Oh no, an error occurred"

This commit is contained in:
Dragon Fire
2024-03-30 11:59:42 -04:00
parent f6b59c2d46
commit a135cac031
119 changed files with 3418 additions and 4116 deletions
+29 -40
View File
@@ -12,6 +12,7 @@ module.exports = class GunfightCommand extends Command {
memberName: 'gunfight',
description: 'Engage in a western gunfight against another user. High noon.',
guildOnly: true,
game: true,
args: [
{
key: 'opponent',
@@ -25,46 +26,34 @@ module.exports = class GunfightCommand extends Command {
if (opponent.bot) return msg.reply('Bots may not be fought.');
if (opponent.id === msg.author.id) return msg.reply('You may not fight yourself.');
if (this.client.blacklist.user.includes(opponent.id)) return msg.reply('This user is blacklisted.');
const current = this.client.games.get(msg.channel.id);
if (current) return msg.reply(`Please wait until the current game of \`${current.name}\` is finished.`);
this.client.games.set(msg.channel.id, { name: this.name });
try {
await msg.say(`${opponent}, do you accept this challenge?`);
const verification = await verify(msg.channel, opponent);
if (!verification) {
this.client.games.delete(msg.channel.id);
return msg.say('Looks like they declined...');
}
await msg.say('Get Ready...');
await delay(randomRange(1000, 30000));
const word = words[Math.floor(Math.random() * words.length)];
await msg.say(`TYPE \`${word.toUpperCase()}\` NOW!`);
const filter = res => [opponent.id, msg.author.id].includes(res.author.id) && res.content.toLowerCase() === word;
const now = Date.now();
const winner = await msg.channel.awaitMessages({
filter,
max: 1,
time: 30000
});
const newScore = Date.now() - now;
const highScoreGet = await this.client.redis.get('reaction-time');
const highScore = highScoreGet ? Number.parseInt(highScoreGet, 10) : null;
const highScoreUser = await this.client.redis.get('reaction-time-user');
const scoreBeat = !highScore || highScore > newScore;
const user = await fetchHSUserDisplay(this.client, highScoreUser);
if (scoreBeat) {
await this.client.redis.set('reaction-time', newScore);
await this.client.redis.set('reaction-time-user', winner.first().author.id);
}
this.client.games.delete(msg.channel.id);
if (!winner.size) return msg.say('Oh... No one won.');
return msg.say(stripIndents`
The winner is ${winner.first().author}! (Took ${newScore / 1000} seconds)
${scoreBeat ? `**New High Score!** Old:` : `High Score:`} ${highScore / 1000} (Held by ${user})
`);
} catch (err) {
this.client.games.delete(msg.channel.id);
throw err;
await msg.say(`${opponent}, do you accept this challenge?`);
const verification = await verify(msg.channel, opponent);
if (!verification) return msg.say('Looks like they declined...');
await msg.say('Get Ready...');
await delay(randomRange(1000, 30000));
const word = words[Math.floor(Math.random() * words.length)];
await msg.say(`TYPE \`${word.toUpperCase()}\` NOW!`);
const filter = res => [opponent.id, msg.author.id].includes(res.author.id) && res.content.toLowerCase() === word;
const now = Date.now();
const winner = await msg.channel.awaitMessages({
filter,
max: 1,
time: 30000
});
const newScore = Date.now() - now;
const highScoreGet = await this.client.redis.get('reaction-time');
const highScore = highScoreGet ? Number.parseInt(highScoreGet, 10) : null;
const highScoreUser = await this.client.redis.get('reaction-time-user');
const scoreBeat = !highScore || highScore > newScore;
const user = await fetchHSUserDisplay(this.client, highScoreUser);
if (scoreBeat) {
await this.client.redis.set('reaction-time', newScore);
await this.client.redis.set('reaction-time-user', winner.first().author.id);
}
if (!winner.size) return msg.say('Oh... No one won.');
return msg.say(stripIndents`
The winner is ${winner.first().author}! (Took ${newScore / 1000} seconds)
${scoreBeat ? `**New High Score!** Old:` : `High Score:`} ${highScore / 1000} (Held by ${user})
`);
}
};