mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Only one game per channel for ALL games,
This commit is contained in:
@@ -22,20 +22,19 @@ module.exports = class BalloonPopCommand extends Command {
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
this.playing = new Set();
|
||||
}
|
||||
|
||||
async run(msg, { opponent }) {
|
||||
if (opponent.bot) return msg.reply('Bots may not be played against.');
|
||||
if (opponent.id === msg.author.id) return msg.reply('You may not play against yourself.');
|
||||
if (this.playing.has(msg.channel.id)) return msg.reply('Only one game may be occurring per channel.');
|
||||
this.playing.add(msg.channel.id);
|
||||
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.playing.delete(msg.channel.id);
|
||||
this.client.games.delete(msg.channel.id);
|
||||
return msg.say('Looks like they declined...');
|
||||
}
|
||||
let userTurn = false;
|
||||
@@ -71,10 +70,10 @@ module.exports = class BalloonPopCommand extends Command {
|
||||
userTurn = !userTurn;
|
||||
}
|
||||
}
|
||||
this.playing.delete(msg.channel.id);
|
||||
this.client.games.delete(msg.channel.id);
|
||||
return msg.say(`And the winner is... ${winner}! Great job!`);
|
||||
} catch (err) {
|
||||
this.playing.delete(msg.channel.id);
|
||||
this.client.games.delete(msg.channel.id);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,21 +19,20 @@ module.exports = class BattleCommand extends Command {
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
this.battles = new Map();
|
||||
}
|
||||
|
||||
async run(msg, { opponent }) {
|
||||
if (opponent.id === msg.author.id) return msg.reply('You may not battle yourself.');
|
||||
if (this.battles.has(msg.channel.id)) return msg.reply('Only one battle may be occurring per channel.');
|
||||
this.battles.set(msg.channel.id, new Battle(msg.author, opponent));
|
||||
const battle = this.battles.get(msg.channel.id);
|
||||
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, data: new Battle(msg.author, opponent) });
|
||||
const battle = this.client.games.get(msg.channel.id).data;
|
||||
try {
|
||||
if (!opponent.bot) {
|
||||
await msg.say(`${opponent}, do you accept this challenge?`);
|
||||
const verification = await verify(msg.channel, opponent);
|
||||
if (!verification) {
|
||||
this.battles.delete(msg.channel.id);
|
||||
this.client.games.delete(msg.channel.id);
|
||||
return msg.say('Looks like they declined...');
|
||||
}
|
||||
}
|
||||
@@ -82,10 +81,10 @@ module.exports = class BattleCommand extends Command {
|
||||
}
|
||||
}
|
||||
const { winner } = battle;
|
||||
this.battles.delete(msg.channel.id);
|
||||
this.client.games.delete(msg.channel.id);
|
||||
return msg.say(`The match is over! Congrats, ${winner}!`);
|
||||
} catch (err) {
|
||||
this.battles.delete(msg.channel.id);
|
||||
this.client.games.delete(msg.channel.id);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
+10
-11
@@ -24,14 +24,13 @@ module.exports = class BlackjackCommand extends Command {
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
this.decks = new Map();
|
||||
}
|
||||
|
||||
async run(msg, { deckCount }) {
|
||||
if (this.decks.has(msg.channel.id)) return msg.reply('Only one game may be occurring per channel.');
|
||||
async run(msg, { deckCount }) { // eslint-disable-line complexity
|
||||
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.`);
|
||||
try {
|
||||
this.decks.set(msg.channel.id, this.generateDeck(deckCount));
|
||||
this.client.games.set(msg.channel.id, { name: this.name, data: this.generateDeck(deckCount) });
|
||||
const dealerHand = [];
|
||||
this.draw(msg.channel, dealerHand);
|
||||
this.draw(msg.channel, dealerHand);
|
||||
@@ -41,13 +40,13 @@ module.exports = class BlackjackCommand extends Command {
|
||||
const dealerInitialTotal = this.calculate(dealerHand);
|
||||
const playerInitialTotal = this.calculate(playerHand);
|
||||
if (dealerInitialTotal === 21 && playerInitialTotal === 21) {
|
||||
this.decks.delete(msg.channel.id);
|
||||
this.client.games.delete(msg.channel.id);
|
||||
return msg.say('Well, both of you just hit blackjack. Right away. Rigged.');
|
||||
} else if (dealerInitialTotal === 21) {
|
||||
this.decks.delete(msg.channel.id);
|
||||
this.client.games.delete(msg.channel.id);
|
||||
return msg.say('Ouch, the dealer hit blackjack right away! Try again!');
|
||||
} else if (playerInitialTotal === 21) {
|
||||
this.decks.delete(msg.channel.id);
|
||||
this.client.games.delete(msg.channel.id);
|
||||
return msg.say('Wow, you hit blackjack right away! Lucky you!');
|
||||
}
|
||||
let playerTurn = true;
|
||||
@@ -104,11 +103,11 @@ module.exports = class BlackjackCommand extends Command {
|
||||
}
|
||||
}
|
||||
}
|
||||
this.decks.delete(msg.channel.id);
|
||||
this.client.games.delete(msg.channel.id);
|
||||
if (win) return msg.say(`${reason}! You won!`);
|
||||
return msg.say(`${reason}! Too bad.`);
|
||||
} catch (err) {
|
||||
this.decks.delete(msg.channel.id);
|
||||
this.client.games.delete(msg.channel.id);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
@@ -139,7 +138,7 @@ module.exports = class BlackjackCommand extends Command {
|
||||
}
|
||||
|
||||
draw(channel, hand) {
|
||||
const deck = this.decks.get(channel.id);
|
||||
const deck = this.client.games.get(channel.id).data;
|
||||
const card = deck[0];
|
||||
deck.shift();
|
||||
hand.push(card);
|
||||
|
||||
@@ -27,21 +27,21 @@ module.exports = class BoxChoosingCommand extends Command {
|
||||
]
|
||||
});
|
||||
|
||||
this.playing = new Set();
|
||||
this.blue = new Set();
|
||||
this.red = new Set();
|
||||
}
|
||||
|
||||
async run(msg) {
|
||||
if (this.playing.has(msg.channel.id)) return msg.reply('Only one game may be occurring per channel.');
|
||||
this.playing.add(msg.channel.id);
|
||||
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 {
|
||||
let i = 0;
|
||||
let path = 'before';
|
||||
while (true) { // eslint-disable-line no-constant-condition
|
||||
const line = script[path][i];
|
||||
if (line.end) {
|
||||
this.playing.delete(msg.channel.id);
|
||||
this.client.games.delete(msg.channel.id);
|
||||
return msg.say(line.text);
|
||||
} else {
|
||||
await msg.say(typeof line === 'object' ? line.text : stripIndents`
|
||||
@@ -75,10 +75,10 @@ module.exports = class BoxChoosingCommand extends Command {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
this.playing.delete(msg.channel.id);
|
||||
this.client.games.delete(msg.channel.id);
|
||||
return msg.say('See you soon!');
|
||||
} catch (err) {
|
||||
this.playing.delete(msg.channel.id);
|
||||
this.client.games.delete(msg.channel.id);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,13 +21,12 @@ module.exports = class DoorsCommand extends Command {
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
this.playing = new Set();
|
||||
}
|
||||
|
||||
async run(msg, { door }) {
|
||||
if (this.playing.has(msg.channel.id)) return msg.reply('Only one game may be occurring per channel.');
|
||||
this.playing.add(msg.channel.id);
|
||||
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 win = doors[Math.floor(Math.random() * doors.length)];
|
||||
const noWin = doors.filter(thisDoor => thisDoor !== win && door !== thisDoor)[0];
|
||||
@@ -37,13 +36,13 @@ module.exports = class DoorsCommand extends Command {
|
||||
`);
|
||||
const stick = await verify(msg.channel, msg.author);
|
||||
if (!stick) door = doors.filter(thisDoor => door !== thisDoor && thisDoor !== noWin)[0];
|
||||
this.playing.delete(msg.channel.id);
|
||||
this.client.games.delete(msg.channel.id);
|
||||
return msg.reply(stripIndents`
|
||||
${door === win ? 'You chose wisely.' : 'Hmm... Try again.'}
|
||||
${this.emoji(1, noWin, win, door)} ${this.emoji(2, noWin, win, door)} ${this.emoji(3, noWin, win, door)}
|
||||
`);
|
||||
} catch (err) {
|
||||
this.playing.delete(msg.channel.id);
|
||||
this.client.games.delete(msg.channel.id);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,20 +20,19 @@ module.exports = class EmojiEmojiRevolutionCommand extends Command {
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
this.playing = new Set();
|
||||
}
|
||||
|
||||
async run(msg, { opponent }) {
|
||||
if (opponent.bot) return msg.reply('Bots may not be played against.');
|
||||
if (opponent.id === msg.author.id) return msg.reply('You may not play against yourself.');
|
||||
if (this.playing.has(msg.channel.id)) return msg.reply('Only one fight may be occurring per channel.');
|
||||
this.playing.add(msg.channel.id);
|
||||
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.playing.delete(msg.channel.id);
|
||||
this.client.games.delete(msg.channel.id);
|
||||
return msg.say('Looks like they declined...');
|
||||
}
|
||||
let turn = 0;
|
||||
@@ -61,12 +60,12 @@ module.exports = class EmojiEmojiRevolutionCommand extends Command {
|
||||
**${opponent.username}:** ${oPts}
|
||||
`);
|
||||
}
|
||||
this.playing.delete(msg.channel.id);
|
||||
this.client.games.delete(msg.channel.id);
|
||||
if (aPts === oPts) return msg.say('It\'s a tie!');
|
||||
const userWin = aPts > oPts;
|
||||
return msg.say(`You win ${userWin ? msg.author : opponent} with ${userWin ? aPts : oPts} points!`);
|
||||
} catch (err) {
|
||||
this.playing.delete(msg.channel.id);
|
||||
this.client.games.delete(msg.channel.id);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,13 +25,12 @@ module.exports = class GoogleFeudCommand extends Command {
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
this.playing = new Set();
|
||||
}
|
||||
|
||||
async run(msg, { question }) {
|
||||
if (this.playing.has(msg.channel.id)) return msg.reply('Only one fight may be occurring per channel.');
|
||||
this.playing.add(msg.channel.id);
|
||||
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 suggestions = await this.fetchSuggestions(question);
|
||||
if (!suggestions) return msg.say('Could not find any results.');
|
||||
@@ -57,11 +56,11 @@ module.exports = class GoogleFeudCommand extends Command {
|
||||
if (suggestions.includes(choice)) display[suggestions.indexOf(choice)] = choice;
|
||||
else --tries;
|
||||
}
|
||||
this.playing.delete(msg.channel.id);
|
||||
this.client.games.delete(msg.channel.id);
|
||||
if (!display.includes('???')) return msg.say('You win! Nice job, master of Google!');
|
||||
return msg.say('Better luck next time!');
|
||||
} catch (err) {
|
||||
this.playing.delete(msg.channel.id);
|
||||
this.client.games.delete(msg.channel.id);
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,20 +19,19 @@ module.exports = class GunfightCommand extends Command {
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
this.fighting = new Set();
|
||||
}
|
||||
|
||||
async run(msg, { opponent }) {
|
||||
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.fighting.has(msg.channel.id)) return msg.reply('Only one fight may be occurring per channel.');
|
||||
this.fighting.add(msg.channel.id);
|
||||
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.fighting.delete(msg.channel.id);
|
||||
this.client.games.delete(msg.channel.id);
|
||||
return msg.say('Looks like they declined...');
|
||||
}
|
||||
await msg.say('Get Ready...');
|
||||
@@ -44,11 +43,11 @@ module.exports = class GunfightCommand extends Command {
|
||||
max: 1,
|
||||
time: 30000
|
||||
});
|
||||
this.fighting.delete(msg.channel.id);
|
||||
this.client.games.delete(msg.channel.id);
|
||||
if (!winner.size) return msg.say('Oh... No one won.');
|
||||
return msg.say(`The winner is ${winner.first().author}!`);
|
||||
} catch (err) {
|
||||
this.fighting.delete(msg.channel.id);
|
||||
this.client.games.delete(msg.channel.id);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,13 +16,12 @@ module.exports = class HangmanCommand extends Command {
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
this.playing = new Set();
|
||||
}
|
||||
|
||||
async run(msg) { // eslint-disable-line complexity
|
||||
if (this.playing.has(msg.channel.id)) return msg.reply('Only one game may be occurring per channel.');
|
||||
this.playing.add(msg.channel.id);
|
||||
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 word = words[Math.floor(Math.random() * words.length)].toLowerCase();
|
||||
let points = 0;
|
||||
@@ -75,11 +74,11 @@ module.exports = class HangmanCommand extends Command {
|
||||
points++;
|
||||
}
|
||||
}
|
||||
this.playing.delete(msg.channel.id);
|
||||
this.client.games.delete(msg.channel.id);
|
||||
if (word.length === confirmation.length || guessed) return msg.say(`You won, it was ${word}!`);
|
||||
return msg.say(`Too bad... It was ${word}...`);
|
||||
} catch (err) {
|
||||
this.playing.delete(msg.channel.id);
|
||||
this.client.games.delete(msg.channel.id);
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,16 +27,15 @@ module.exports = class HungerGamesCommand extends Command {
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
this.playing = new Set();
|
||||
}
|
||||
|
||||
async run(msg, { tributes }) {
|
||||
if (tributes.length < 2) return msg.say(`...${tributes[0]} wins, as they were the only tribute.`);
|
||||
if (tributes.length > 24) return msg.reply('Please do not enter more than 24 tributes.');
|
||||
if (new Set(tributes).size !== tributes.length) return msg.reply('Please do not enter the same tribute twice.');
|
||||
if (this.playing.has(msg.channel.id)) return msg.reply('Only one game may be occurring per channel.');
|
||||
this.playing.add(msg.channel.id);
|
||||
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 {
|
||||
let sun = true;
|
||||
let turn = 0;
|
||||
@@ -63,17 +62,17 @@ module.exports = class HungerGamesCommand extends Command {
|
||||
await msg.say(text);
|
||||
const verification = await verify(msg.channel, msg.author, 120000);
|
||||
if (!verification) {
|
||||
this.playing.delete(msg.channel.id);
|
||||
this.client.games.delete(msg.channel.id);
|
||||
return msg.say('See you next time!');
|
||||
}
|
||||
if (!bloodbath) sun = !sun;
|
||||
if (bloodbath) bloodbath = false;
|
||||
}
|
||||
this.playing.delete(msg.channel.id);
|
||||
this.client.games.delete(msg.channel.id);
|
||||
const remainingArr = Array.from(remaining);
|
||||
return msg.say(`And the winner is... ${remainingArr[0]}!`);
|
||||
} catch (err) {
|
||||
this.playing.delete(msg.channel.id);
|
||||
this.client.games.delete(msg.channel.id);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,18 +14,17 @@ module.exports = class MafiaCommand extends Command {
|
||||
description: 'Who is the Mafia? Who is the doctor? Who is the detective? Will the Mafia kill them all?',
|
||||
guildOnly: true
|
||||
});
|
||||
|
||||
this.playing = new Set();
|
||||
}
|
||||
|
||||
async run(msg) { // eslint-disable-line complexity
|
||||
if (this.playing.has(msg.channel.id)) return msg.reply('Only one game may be occurring per channel.');
|
||||
this.playing.add(msg.channel.id);
|
||||
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('You will need at least 2 more players, at maximum 10. To join, type `join game`.');
|
||||
const awaitedPlayers = await awaitPlayers(msg, 10, 3, { dmCheck: true });
|
||||
if (!awaitedPlayers) {
|
||||
this.playing.delete(msg.channel.id);
|
||||
this.client.games.delete(msg.channel.id);
|
||||
return msg.say('Game could not be started...');
|
||||
}
|
||||
const players = await this.generatePlayers(awaitedPlayers);
|
||||
@@ -117,12 +116,12 @@ module.exports = class MafiaCommand extends Command {
|
||||
players.delete(hanged.id);
|
||||
++turn;
|
||||
}
|
||||
this.playing.delete(msg.channel.id);
|
||||
this.client.games.delete(msg.channel.id);
|
||||
const mafia = players.find(p => p.role === 'mafia');
|
||||
if (!mafia) return msg.say('The Mafia has been hanged! Thanks for playing!');
|
||||
return msg.say(`Oh no, the Mafia wasn't caught in time... Nice job, ${mafia.user}!`);
|
||||
} catch (err) {
|
||||
this.playing.delete(msg.channel.id);
|
||||
this.client.games.delete(msg.channel.id);
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,20 +34,19 @@ module.exports = class QuizDuelCommand extends Command {
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
this.playing = new Set();
|
||||
}
|
||||
|
||||
async run(msg, { opponent, maxPts }) {
|
||||
if (opponent.bot) return msg.reply('Bots may not be played against.');
|
||||
if (opponent.id === msg.author.id) return msg.reply('You may not play against yourself.');
|
||||
if (this.playing.has(msg.channel.id)) return msg.reply('Only one game may be occurring per channel.');
|
||||
this.playing.add(msg.channel.id);
|
||||
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.playing.delete(msg.channel.id);
|
||||
this.client.games.delete(msg.channel.id);
|
||||
return msg.say('Looks like they declined...');
|
||||
}
|
||||
let winner = null;
|
||||
@@ -92,11 +91,11 @@ module.exports = class QuizDuelCommand extends Command {
|
||||
`;
|
||||
await msg.say(`Nice one, ${result.author}! The score is now ${score}!`);
|
||||
}
|
||||
this.playing.delete(msg.channel.id);
|
||||
this.client.games.delete(msg.channel.id);
|
||||
if (!winner) return msg.say('Aww, no one won...');
|
||||
return msg.say(`Congrats, ${winner}, you won!`);
|
||||
} catch (err) {
|
||||
this.playing.delete(msg.channel.id);
|
||||
this.client.games.delete(msg.channel.id);
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,13 +23,12 @@ module.exports = class SortingHatCommand extends Command {
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
this.playing = new Set();
|
||||
}
|
||||
|
||||
async run(msg) {
|
||||
if (this.playing.has(msg.channel.id)) return msg.reply('Only one quiz may be occurring per channel.');
|
||||
this.playing.add(msg.channel.id);
|
||||
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 points = {
|
||||
g: 0,
|
||||
@@ -70,7 +69,7 @@ module.exports = class SortingHatCommand extends Command {
|
||||
++turn;
|
||||
}
|
||||
const houseResult = Object.keys(points).filter(h => points[h] > 0).sort((a, b) => points[b] - points[a]);
|
||||
this.playing.delete(msg.channel.id);
|
||||
this.client.games.delete(msg.channel.id);
|
||||
const totalPoints = houseResult.reduce((a, b) => a + points[b], 0);
|
||||
return msg.say(stripIndents`
|
||||
You are a member of... **${houses[houseResult[0]]}**!
|
||||
@@ -79,7 +78,7 @@ module.exports = class SortingHatCommand extends Command {
|
||||
${houseResult.map(house => `${houses[house]}: ${Math.round((points[house] / totalPoints) * 100)}%`).join('\n')}
|
||||
`);
|
||||
} catch (err) {
|
||||
this.playing.delete(msg.channel.id);
|
||||
this.client.games.delete(msg.channel.id);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,20 +18,19 @@ module.exports = class TicTacToeCommand extends Command {
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
this.playing = new Set();
|
||||
}
|
||||
|
||||
async run(msg, { opponent }) {
|
||||
if (opponent.bot) return msg.reply('Bots may not be played against.');
|
||||
if (opponent.id === msg.author.id) return msg.reply('You may not play against yourself.');
|
||||
if (this.playing.has(msg.channel.id)) return msg.reply('Only one game may be occurring per channel.');
|
||||
this.playing.add(msg.channel.id);
|
||||
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.playing.delete(msg.channel.id);
|
||||
this.client.games.delete(msg.channel.id);
|
||||
return msg.say('Looks like they declined...');
|
||||
}
|
||||
const sides = ['0', '1', '2', '3', '4', '5', '6', '7', '8'];
|
||||
@@ -70,10 +69,10 @@ module.exports = class TicTacToeCommand extends Command {
|
||||
if (this.verifyWin(sides)) winner = userTurn ? msg.author : opponent;
|
||||
userTurn = !userTurn;
|
||||
}
|
||||
this.playing.delete(msg.channel.id);
|
||||
this.client.games.delete(msg.channel.id);
|
||||
return msg.say(winner ? `Congrats, ${winner}!` : 'Oh... The cat won.');
|
||||
} catch (err) {
|
||||
this.playing.delete(msg.channel.id);
|
||||
this.client.games.delete(msg.channel.id);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,18 +14,17 @@ module.exports = class WizardConventionCommand extends Command {
|
||||
description: 'Who is the Dragon? Who is the healer? Who is the mind reader? Will the Dragon eat them all?',
|
||||
guildOnly: true
|
||||
});
|
||||
|
||||
this.playing = new Set();
|
||||
}
|
||||
|
||||
async run(msg) { // eslint-disable-line complexity
|
||||
if (this.playing.has(msg.channel.id)) return msg.reply('Only one game may be occurring per channel.');
|
||||
this.playing.add(msg.channel.id);
|
||||
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('You will need at least 2 more players, at maximum 10. To join, type `join game`.');
|
||||
const awaitedPlayers = await awaitPlayers(msg, 10, 3, { dmCheck: true });
|
||||
if (!awaitedPlayers) {
|
||||
this.playing.delete(msg.channel.id);
|
||||
this.client.games.delete(msg.channel.id);
|
||||
return msg.say('Game could not be started...');
|
||||
}
|
||||
const players = await this.generatePlayers(awaitedPlayers);
|
||||
@@ -117,12 +116,12 @@ module.exports = class WizardConventionCommand extends Command {
|
||||
players.delete(expelled.id);
|
||||
++turn;
|
||||
}
|
||||
this.playing.delete(msg.channel.id);
|
||||
this.client.games.delete(msg.channel.id);
|
||||
const dragon = players.find(p => p.role === 'dragon');
|
||||
if (!dragon) return msg.say('The dragon has been vanquished! Thanks for playing!');
|
||||
return msg.say(`Oh no, the dragon wasn't caught in time... Nice job, ${dragon.user}!`);
|
||||
} catch (err) {
|
||||
this.playing.delete(msg.channel.id);
|
||||
this.client.games.delete(msg.channel.id);
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,20 +35,19 @@ module.exports = class WordChainCommand extends Command {
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
this.playing = new Set();
|
||||
}
|
||||
|
||||
async run(msg, { opponent, time }) {
|
||||
if (opponent.bot) return msg.reply('Bots may not be played against.');
|
||||
if (opponent.id === msg.author.id) return msg.reply('You may not play against yourself.');
|
||||
if (this.playing.has(msg.channel.id)) return msg.reply('Only one game may be occurring per channel.');
|
||||
this.playing.add(msg.channel.id);
|
||||
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.playing.delete(msg.channel.id);
|
||||
this.client.games.delete(msg.channel.id);
|
||||
return msg.say('Looks like they declined...');
|
||||
}
|
||||
const startWord = startWords[Math.floor(Math.random() * startWords.length)];
|
||||
@@ -98,11 +97,11 @@ module.exports = class WordChainCommand extends Command {
|
||||
lastWord = choice;
|
||||
userTurn = !userTurn;
|
||||
}
|
||||
this.playing.delete(msg.channel.id);
|
||||
this.client.games.delete(msg.channel.id);
|
||||
if (!winner) return msg.say('Oh... No one won.');
|
||||
return msg.say(`The game is over! The winner is ${winner}!`);
|
||||
} catch (err) {
|
||||
this.playing.delete(msg.channel.id);
|
||||
this.client.games.delete(msg.channel.id);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiao",
|
||||
"version": "105.3.2",
|
||||
"version": "106.0.0",
|
||||
"description": "Your personal server companion.",
|
||||
"main": "Xiao.js",
|
||||
"scripts": {
|
||||
@@ -39,7 +39,7 @@
|
||||
"discord.js-commando": "github:discordjs/Commando",
|
||||
"dotenv": "^8.0.0",
|
||||
"gifencoder": "^2.0.1",
|
||||
"mathjs": "^6.0.1",
|
||||
"mathjs": "^6.0.2",
|
||||
"moment": "^2.24.0",
|
||||
"moment-duration-format": "^2.3.2",
|
||||
"moment-timezone": "^0.5.25",
|
||||
|
||||
@@ -17,5 +17,6 @@ module.exports = class XiaoClient extends CommandoClient {
|
||||
});
|
||||
this.webhook = new WebhookClient(XIAO_WEBHOOK_ID, XIAO_WEBHOOK_TOKEN, { disableEveryone: true });
|
||||
this.pokemon = new PokemonStore();
|
||||
this.games = new Map();
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user