From 04a67593f509f1e10ef5dd507944ca578130f95d Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Sun, 17 Jan 2021 10:22:08 -0500 Subject: [PATCH] Allow any emoji in connect 4 --- assets/json/connect-four.json | 9 --------- commands/games-mp/connect-four.js | 30 +++++++++++++++++++++++------- package.json | 3 ++- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/assets/json/connect-four.json b/assets/json/connect-four.json index cb69fcad..d13f62a9 100644 --- a/assets/json/connect-four.json +++ b/assets/json/connect-four.json @@ -7,13 +7,6 @@ "orange": "🟠", "purple": "🟣", "black": "⚫", - "cheese": "🧀", - "face": "😶", - "angry": "😡", - "cold": "🥶", - "dog": "🐶", - "cat": "🐱", - "turtle": "🐢", "moon": "🌘", "earth": "🌎", "donut": "🍙", @@ -27,8 +20,6 @@ "8ball": "🎱", "cd": "💿", "dvd": "📀", - "nsfw": "🔞", - "nosmoke": "🚭", "clock": "🕓", "coin": "🪙" } diff --git a/commands/games-mp/connect-four.js b/commands/games-mp/connect-four.js index a2a1c4b8..10dd8e20 100644 --- a/commands/games-mp/connect-four.js +++ b/commands/games-mp/connect-four.js @@ -1,6 +1,7 @@ const Command = require('../../structures/Command'); const { Connect4AI } = require('connect4-ai'); const { stripIndents } = require('common-tags'); +const emojiRegex = require('emoji-regex/RGI_Emoji.js'); const { verify, list } = require('../../util/Util'); const { LOADING_EMOJI_ID } = process.env; const blankEmoji = '⚪'; @@ -31,10 +32,16 @@ module.exports = class ConnectFourCommand extends Command { }, { key: 'color', - prompt: `What color do you want to be? Either ${list(Object.keys(colors), 'or')}.`, - type: 'string', - oneOf: Object.keys(colors), - parse: color => color.toLowerCase() + prompt: `What color do you want to be? Either an emoji or one of ${list(Object.keys(colors), 'or')}.`, + type: 'default-emoji|string', + validate: color => { + const hasEmoji = new RegExp(`^(?:${emojiRegex().source})$`).test(value); + if (!hasEmoji && !colors[color.toLowerCase()]) { + return `Please enter an emoji or one of the following: ${list(Object.keys(colors), 'or')}.`; + } + return true; + }, + parse: color => colors[color.toLowerCase()] || color } ] }); @@ -62,13 +69,22 @@ module.exports = class ConnectFourCommand extends Command { this.client.games.delete(msg.channel.id); return msg.say('Looks like they declined...'); } - await msg.say(`${opponent}, what color do you want to be? Either ${list(available, 'or')}.`); - const filter = res => res.author.id === opponent.id && available.includes(res.content.toLowerCase()); + await msg.say( + `${opponent}, what color do you want to be? Either an emoji or one of ${list(available, 'or')}.` + ); + const filter = res => { + if (res.author.id !== opponent.id) return false; + const hasEmoji = new RegExp(`^(?:${emojiRegex().source})$`).test(value); + return hasEmoji || available.includes(res.content.toLowerCase()); + } const p2Color = await msg.channel.awaitMessages(filter, { max: 1, time: 30000 }); - if (p2Color.size) playerTwoEmoji = colors[p2Color.first().content.toLowerCase()]; + if (p2Color.size) { + const choice = p2Color.first().content.toLowerCase(); + playerTwoEmoji = colors[choice] || choice; + } } let AIEngine = null; if (opponent.bot) AIEngine = new Connect4AI(); diff --git a/package.json b/package.json index fcb99092..d5dee8e6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "126.4.0", + "version": "126.4.1", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": { @@ -46,6 +46,7 @@ "discord.js": "^12.5.1", "discord.js-commando": "github:discordjs/Commando", "dotenv": "^8.2.0", + "emoji-regex": "^9.2.0", "eslint": "^7.18.0", "expr-eval": "^2.0.2", "gifencoder": "^2.0.1",