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