From f98e1700d5ffa6ea97ab0d1ce25cc2bd602a563f Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Sun, 14 Feb 2021 20:46:12 -0500 Subject: [PATCH] Prevent blacklisted users from playing games --- commands/games-mp/balloon-pop.js | 2 +- commands/games-mp/battle.js | 1 + commands/games-mp/bingo.js | 2 +- commands/games-mp/car-race.js | 1 + commands/games-mp/chess.js | 1 + commands/games-mp/connect-four.js | 1 + commands/games-mp/cram.js | 1 + commands/games-mp/domineering.js | 1 + commands/games-mp/dots-and-boxes.js | 1 + commands/games-mp/emoji-emoji-revolution.js | 1 + commands/games-mp/guesspionage.js | 2 +- commands/games-mp/gunfight.js | 1 + commands/games-mp/imposter.js | 2 +- commands/games-mp/island.js | 2 +- commands/games-mp/jenga.js | 1 + commands/games-mp/lie-swatter.js | 2 +- commands/games-mp/nim.js | 1 + commands/games-mp/obstruction.js | 1 + commands/games-mp/pick-a-number.js | 1 + commands/games-mp/poker.js | 2 +- commands/games-mp/quiz-duel.js | 2 +- commands/games-mp/russian-roulette.js | 1 + commands/games-mp/spam-war.js | 1 + commands/games-mp/tic-tac-toe.js | 1 + commands/games-mp/typing-race.js | 1 + commands/games-mp/word-chain.js | 1 + commands/games-mp/word-spud.js | 1 + package.json | 2 +- util/Util.js | 3 ++- 29 files changed, 30 insertions(+), 10 deletions(-) diff --git a/commands/games-mp/balloon-pop.js b/commands/games-mp/balloon-pop.js index 4bfba658..c01c5cad 100644 --- a/commands/games-mp/balloon-pop.js +++ b/commands/games-mp/balloon-pop.js @@ -34,7 +34,7 @@ module.exports = class BalloonPopCommand extends Command { 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 awaitedPlayers = await awaitPlayers(msg, playersCount, 2); + const awaitedPlayers = await awaitPlayers(msg, playersCount, 2, this.client.blacklist.user); if (!awaitedPlayers) { this.client.games.delete(msg.channel.id); return msg.say('Game could not be started...'); diff --git a/commands/games-mp/battle.js b/commands/games-mp/battle.js index eaf64766..b6448b45 100644 --- a/commands/games-mp/battle.js +++ b/commands/games-mp/battle.js @@ -22,6 +22,7 @@ module.exports = class BattleCommand extends Command { async run(msg, { opponent }) { if (opponent.id === msg.author.id) return msg.reply('You may not battle 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, data: new Battle(msg.author, opponent) }); diff --git a/commands/games-mp/bingo.js b/commands/games-mp/bingo.js index b5694c2f..bc2a66d6 100644 --- a/commands/games-mp/bingo.js +++ b/commands/games-mp/bingo.js @@ -32,7 +32,7 @@ module.exports = class BingoCommand extends Command { 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 awaitedPlayers = await awaitPlayers(msg, playersCount); + const awaitedPlayers = await awaitPlayers(msg, playersCount, 1, this.client.blacklist.user); if (!awaitedPlayers) { this.client.games.delete(msg.channel.id); return msg.say('Game could not be started...'); diff --git a/commands/games-mp/car-race.js b/commands/games-mp/car-race.js index 2c6ee207..83e874b7 100644 --- a/commands/games-mp/car-race.js +++ b/commands/games-mp/car-race.js @@ -353,6 +353,7 @@ module.exports = class CarRaceCommand extends Command { async run(msg, { opponent, car }) { 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 }); diff --git a/commands/games-mp/chess.js b/commands/games-mp/chess.js index 2a8cc8d1..ec1644cc 100644 --- a/commands/games-mp/chess.js +++ b/commands/games-mp/chess.js @@ -60,6 +60,7 @@ module.exports = class ChessCommand extends Command { async run(msg, { opponent, time, fen }) { 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 }); diff --git a/commands/games-mp/connect-four.js b/commands/games-mp/connect-four.js index 16087943..fd4e9aee 100644 --- a/commands/games-mp/connect-four.js +++ b/commands/games-mp/connect-four.js @@ -60,6 +60,7 @@ module.exports = class ConnectFourCommand extends Command { async run(msg, { opponent, color }) { 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 }); diff --git a/commands/games-mp/cram.js b/commands/games-mp/cram.js index 50370fb8..60eaa785 100644 --- a/commands/games-mp/cram.js +++ b/commands/games-mp/cram.js @@ -43,6 +43,7 @@ module.exports = class CramCommand extends Command { async run(msg, { opponent, color, size }) { 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.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 }); diff --git a/commands/games-mp/domineering.js b/commands/games-mp/domineering.js index 87bf5d00..a02e1b3b 100644 --- a/commands/games-mp/domineering.js +++ b/commands/games-mp/domineering.js @@ -43,6 +43,7 @@ module.exports = class DomineeringCommand extends Command { async run(msg, { opponent, color, size }) { 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.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 }); diff --git a/commands/games-mp/dots-and-boxes.js b/commands/games-mp/dots-and-boxes.js index c6293026..171d2080 100644 --- a/commands/games-mp/dots-and-boxes.js +++ b/commands/games-mp/dots-and-boxes.js @@ -25,6 +25,7 @@ module.exports = class DotsAndBoxesCommand extends Command { 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.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 }); diff --git a/commands/games-mp/emoji-emoji-revolution.js b/commands/games-mp/emoji-emoji-revolution.js index 6a9a5c0f..c62af077 100644 --- a/commands/games-mp/emoji-emoji-revolution.js +++ b/commands/games-mp/emoji-emoji-revolution.js @@ -33,6 +33,7 @@ module.exports = class EmojiEmojiRevolutionCommand extends Command { 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.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 }); diff --git a/commands/games-mp/guesspionage.js b/commands/games-mp/guesspionage.js index 5e6c3edb..7e47c242 100644 --- a/commands/games-mp/guesspionage.js +++ b/commands/games-mp/guesspionage.js @@ -54,7 +54,7 @@ module.exports = class GuesspionageCommand extends Command { 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 awaitedPlayers = await awaitPlayers(msg, players, min); + const awaitedPlayers = await awaitPlayers(msg, players, min, this.client.blacklist.user); if (!awaitedPlayers) { this.client.games.delete(msg.channel.id); return msg.say('Game could not be started...'); diff --git a/commands/games-mp/gunfight.js b/commands/games-mp/gunfight.js index 0f1704fd..c9d847e3 100644 --- a/commands/games-mp/gunfight.js +++ b/commands/games-mp/gunfight.js @@ -25,6 +25,7 @@ module.exports = class GunfightCommand extends Command { 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.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 }); diff --git a/commands/games-mp/imposter.js b/commands/games-mp/imposter.js index 0663504e..e492ab9a 100644 --- a/commands/games-mp/imposter.js +++ b/commands/games-mp/imposter.js @@ -33,7 +33,7 @@ module.exports = class ImposterCommand extends Command { 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 awaitedPlayers = await awaitPlayers(msg, playersCount, 3); + const awaitedPlayers = await awaitPlayers(msg, playersCount, 3, this.client.blacklist.user); if (!awaitedPlayers) { this.client.games.delete(msg.channel.id); return msg.say('Game could not be started...'); diff --git a/commands/games-mp/island.js b/commands/games-mp/island.js index 2a0bd386..05980151 100644 --- a/commands/games-mp/island.js +++ b/commands/games-mp/island.js @@ -30,7 +30,7 @@ module.exports = class IslandCommand extends Command { 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 awaitedPlayers = await awaitPlayers(msg, playersCount, 3); + const awaitedPlayers = await awaitPlayers(msg, playersCount, 3, this.client.blacklist.user); if (!awaitedPlayers) { this.client.games.delete(msg.channel.id); return msg.say('Game could not be started...'); diff --git a/commands/games-mp/jenga.js b/commands/games-mp/jenga.js index 3786bbd8..c0666250 100644 --- a/commands/games-mp/jenga.js +++ b/commands/games-mp/jenga.js @@ -29,6 +29,7 @@ module.exports = class JengaCommand 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 }); diff --git a/commands/games-mp/lie-swatter.js b/commands/games-mp/lie-swatter.js index ced28227..9582da03 100644 --- a/commands/games-mp/lie-swatter.js +++ b/commands/games-mp/lie-swatter.js @@ -45,7 +45,7 @@ module.exports = class LieSwatterCommand extends Command { 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 awaitedPlayers = await awaitPlayers(msg, players); + const awaitedPlayers = await awaitPlayers(msg, players, 1, this.client.blacklist.user); let turn = 0; const pts = new Collection(); for (const player of awaitedPlayers) { diff --git a/commands/games-mp/nim.js b/commands/games-mp/nim.js index fc069111..daf84abe 100644 --- a/commands/games-mp/nim.js +++ b/commands/games-mp/nim.js @@ -31,6 +31,7 @@ module.exports = class NimCommand extends Command { async run(msg, { opponent, rows }) { 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 }); diff --git a/commands/games-mp/obstruction.js b/commands/games-mp/obstruction.js index bb285494..80fe272a 100644 --- a/commands/games-mp/obstruction.js +++ b/commands/games-mp/obstruction.js @@ -38,6 +38,7 @@ module.exports = class ObstructionCommand extends Command { async run(msg, { opponent, size }) { 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.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 }); diff --git a/commands/games-mp/pick-a-number.js b/commands/games-mp/pick-a-number.js index 167aa59b..99d8528e 100644 --- a/commands/games-mp/pick-a-number.js +++ b/commands/games-mp/pick-a-number.js @@ -22,6 +22,7 @@ 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 }); diff --git a/commands/games-mp/poker.js b/commands/games-mp/poker.js index 90432ff1..908e4ce6 100644 --- a/commands/games-mp/poker.js +++ b/commands/games-mp/poker.js @@ -47,7 +47,7 @@ module.exports = class PokerCommand extends Command { } }); try { - const awaitedPlayers = await awaitPlayers(msg, playersCount, min); + const awaitedPlayers = await awaitPlayers(msg, playersCount, min, this.client.blacklist.user); if (!awaitedPlayers) { this.client.games.delete(msg.channel.id); return msg.say('Game could not be started...'); diff --git a/commands/games-mp/quiz-duel.js b/commands/games-mp/quiz-duel.js index 440dae82..2d0999da 100644 --- a/commands/games-mp/quiz-duel.js +++ b/commands/games-mp/quiz-duel.js @@ -39,7 +39,7 @@ module.exports = class QuizDuelCommand extends Command { 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 awaitedPlayers = await awaitPlayers(msg, players); + const awaitedPlayers = await awaitPlayers(msg, players, 1, this.client.blacklist.user); let turn = 0; const pts = new Collection(); for (const player of awaitedPlayers) { diff --git a/commands/games-mp/russian-roulette.js b/commands/games-mp/russian-roulette.js index 45564f8a..7ebc8be0 100644 --- a/commands/games-mp/russian-roulette.js +++ b/commands/games-mp/russian-roulette.js @@ -22,6 +22,7 @@ module.exports = class RussianRouletteCommand extends Command { async run(msg, { opponent }) { if (opponent.id === msg.author.id) return msg.reply('You may not challenge 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 }); diff --git a/commands/games-mp/spam-war.js b/commands/games-mp/spam-war.js index f47a4556..b3dfe805 100644 --- a/commands/games-mp/spam-war.js +++ b/commands/games-mp/spam-war.js @@ -23,6 +23,7 @@ module.exports = class SpamWarCommand extends Command { 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.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 }); diff --git a/commands/games-mp/tic-tac-toe.js b/commands/games-mp/tic-tac-toe.js index 07d09ba1..5bd5abb4 100644 --- a/commands/games-mp/tic-tac-toe.js +++ b/commands/games-mp/tic-tac-toe.js @@ -24,6 +24,7 @@ module.exports = class TicTacToeCommand 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 }); diff --git a/commands/games-mp/typing-race.js b/commands/games-mp/typing-race.js index 52ff52d5..89d36215 100644 --- a/commands/games-mp/typing-race.js +++ b/commands/games-mp/typing-race.js @@ -23,6 +23,7 @@ module.exports = class TypingRaceCommand extends Command { 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.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 }); diff --git a/commands/games-mp/word-chain.js b/commands/games-mp/word-chain.js index 70cf2519..49a3a0b0 100644 --- a/commands/games-mp/word-chain.js +++ b/commands/games-mp/word-chain.js @@ -43,6 +43,7 @@ module.exports = class WordChainCommand extends Command { 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.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 }); diff --git a/commands/games-mp/word-spud.js b/commands/games-mp/word-spud.js index 543c5d50..e0e3388e 100644 --- a/commands/games-mp/word-spud.js +++ b/commands/games-mp/word-spud.js @@ -32,6 +32,7 @@ module.exports = class WordSpudCommand extends Command { 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.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 }); diff --git a/package.json b/package.json index 4d594363..8c0dc4ce 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "129.7.2", + "version": "129.7.3", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": { diff --git a/util/Util.js b/util/Util.js index 6dba09fd..415ec2b6 100644 --- a/util/Util.js +++ b/util/Util.js @@ -253,7 +253,7 @@ module.exports = class Util { return arr[Number.parseInt(msgs.first().content, 10) - 1]; } - static async awaitPlayers(msg, max, min = 1) { + static async awaitPlayers(msg, max, min, blacklist) { if (max === 1) return [msg.author.id]; const addS = min - 1 === 1 ? '' : 's'; await msg.say( @@ -263,6 +263,7 @@ module.exports = class Util { joined.push(msg.author.id); const filter = res => { if (res.author.bot) return false; + if (blacklist.includes(res.author.id)) return false; if (joined.includes(res.author.id)) return false; if (res.content.toLowerCase() !== 'join game') return false; joined.push(res.author.id);