Prevent blacklisted users from playing games

This commit is contained in:
Dragon Fire
2021-02-14 20:46:12 -05:00
parent ddd1eeb317
commit f98e1700d5
29 changed files with 30 additions and 10 deletions
+1 -1
View File
@@ -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...');
+1
View File
@@ -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) });
+1 -1
View File
@@ -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...');
+1
View File
@@ -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 });
+1
View File
@@ -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 });
+1
View File
@@ -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 });
+1
View File
@@ -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 });
+1
View File
@@ -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 });
+1
View File
@@ -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 });
@@ -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 });
+1 -1
View File
@@ -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...');
+1
View File
@@ -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 });
+1 -1
View File
@@ -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...');
+1 -1
View File
@@ -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...');
+1
View File
@@ -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 });
+1 -1
View File
@@ -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) {
+1
View File
@@ -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 });
+1
View File
@@ -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 });
+1
View File
@@ -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 });
+1 -1
View File
@@ -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...');
+1 -1
View File
@@ -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) {
+1
View File
@@ -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 });
+1
View File
@@ -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 });
+1
View File
@@ -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 });
+1
View File
@@ -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 });
+1
View File
@@ -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 });
+1
View File
@@ -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 });
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "129.7.2",
"version": "129.7.3",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {
+2 -1
View File
@@ -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);