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
+39 -56
View File
@@ -10,6 +10,7 @@ module.exports = class PickANumberCommand extends Command {
group: 'games-mp',
memberName: 'pick-a-number',
description: 'Two players pick a number between 1 and 10. Whoever\'s closer wins.',
game: true,
args: [
{
key: 'opponent',
@@ -22,66 +23,48 @@ module.exports = class PickANumberCommand extends Command {
async run(msg, { opponent }) {
if (opponent.id === msg.author.id) return msg.reply('You may not play against 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 {
const clientOpp = opponent.id === this.client.user.id;
if (!opponent.bot) {
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(`${msg.author}, pick a number from 1 to 10.`);
let userTurn = true;
let player1Pick = null;
const filter = res => {
if (res.author.id !== (userTurn ? msg.author.id : opponent.id)) return false;
const num = Number.parseInt(res.content, 10);
if (!userTurn && num === player1Pick) return false;
return num && nums.includes(num);
};
const player1 = await msg.channel.awaitMessages({
const clientOpp = opponent.id === this.client.user.id;
if (!opponent.bot) {
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(`${msg.author}, pick a number from 1 to 10.`);
let userTurn = true;
let player1Pick = null;
const filter = res => {
if (res.author.id !== (userTurn ? msg.author.id : opponent.id)) return false;
const num = Number.parseInt(res.content, 10);
if (!userTurn && num === player1Pick) return false;
return num && nums.includes(num);
};
const player1 = await msg.channel.awaitMessages({
filter,
max: 1,
time: 30000
});
if (!player1.size) return msg.say('I guess you didn\'t want to play after all...');
player1Pick = Number.parseInt(player1.first().content, 10);
let player2Pick;
if (opponent.bot) {
const valid = nums.filter(num => num !== player1Pick);
player2Pick = valid[Math.floor(Math.random() * valid.length)];
await msg.say(`Okay, ${clientOpp ? 'I' : `${opponent}`} pick${clientOpp ? '' : 's'} ${player2Pick}!`);
} else {
userTurn = false;
await msg.say(`${opponent}, pick a number from 1 to 10, except ${player1Pick}.`);
const player2 = await msg.channel.awaitMessages({
filter,
max: 1,
time: 30000
});
if (!player1.size) {
this.client.games.delete(msg.channel.id);
return msg.say('I guess you didn\'t want to play after all...');
}
player1Pick = Number.parseInt(player1.first().content, 10);
let player2Pick;
if (opponent.bot) {
const valid = nums.filter(num => num !== player1Pick);
player2Pick = valid[Math.floor(Math.random() * valid.length)];
await msg.say(`Okay, ${clientOpp ? 'I' : `${opponent}`} pick${clientOpp ? '' : 's'} ${player2Pick}!`);
} else {
userTurn = false;
await msg.say(`${opponent}, pick a number from 1 to 10, except ${player1Pick}.`);
const player2 = await msg.channel.awaitMessages({
filter,
max: 1,
time: 30000
});
if (!player2.size) {
this.client.games.delete(msg.channel.id);
return msg.say('I guess you didn\'t want to play after all...');
}
player2Pick = Number.parseInt(player2.first().content, 10);
}
const num = Math.floor(Math.random() * 10) + 1;
const winNum = [player1Pick, player2Pick].sort((a, b) => Math.abs(num - a) - Math.abs(num - b))[0];
const winner = winNum === player1Pick ? msg.author : opponent;
const clientWin = clientOpp && this.client.user.id === winner.id;
this.client.games.delete(msg.channel.id);
return msg.say(`The number was **${num}**! ${clientWin ? 'I' : winner} win${clientWin ? '' : 's'}!`);
} catch (err) {
this.client.games.delete(msg.channel.id);
throw err;
if (!player2.size) return msg.say('I guess you didn\'t want to play after all...');
player2Pick = Number.parseInt(player2.first().content, 10);
}
const num = Math.floor(Math.random() * 10) + 1;
const winNum = [player1Pick, player2Pick].sort((a, b) => Math.abs(num - a) - Math.abs(num - b))[0];
const winner = winNum === player1Pick ? msg.author : opponent;
const clientWin = clientOpp && this.client.user.id === winner.id;
return msg.say(`The number was **${num}**! ${clientWin ? 'I' : winner} win${clientWin ? '' : 's'}!`);
}
};