Allow any emoji in connect 4

This commit is contained in:
Dragon Fire
2021-01-17 10:22:08 -05:00
parent a27c925fb5
commit 04a67593f5
3 changed files with 25 additions and 17 deletions
-9
View File
@@ -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": "🪙"
}
+23 -7
View File
@@ -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();
+2 -1
View File
@@ -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",