From e28733dfe5b235d91f8ef52c2ee54a2282b221d8 Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Thu, 7 Sep 2017 21:41:39 +0000 Subject: [PATCH] Emoji Emoji Revolution --- commands/games/emoji-emoji-revolution.js | 74 ++++++++++++++++++++++++ package.json | 2 +- 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 commands/games/emoji-emoji-revolution.js diff --git a/commands/games/emoji-emoji-revolution.js b/commands/games/emoji-emoji-revolution.js new file mode 100644 index 00000000..2ae6d86e --- /dev/null +++ b/commands/games/emoji-emoji-revolution.js @@ -0,0 +1,74 @@ +const Command = require('../../structures/Command'); +const { stripIndents } = require('common-tags'); +const emojis = ['⬆', '↗', '➡', '↘', '⬇', '↙', '⬅', '↖']; + +module.exports = class EmojiEmojiRevolutionCommand extends Command { + constructor(client) { + super(client, { + name: 'emoji-emoji-revolution', + aliases: ['eer'], + group: 'games', + memberName: 'emoji-emoji-revolution', + description: 'Play a game of Emoji Emoji Revolution.', + guildOnly: true, + args: [ + { + key: 'opponent', + prompt: 'Who would you like to play against?', + type: 'user' + } + ] + }); + + this.playing = new Set(); + } + + async run(msg, args) { + const { opponent } = args; + if (opponent.bot) return msg.say('Bots may not be played against.'); + if (opponent.id === msg.author.id) return msg.say('You may not play against yourself.'); + if (this.playing.has(msg.channel.id)) return msg.say('Only one fight may be occurring per channel.'); + this.playing.add(msg.channel.id); + try { + await msg.say(`${opponent}, do you accept this challenge?`); + const verify = await msg.channel.awaitMessages(res => res.author.id === opponent.id, { + max: 1, + time: 30000 + }); + if (!verify.size || !['yes', 'y'].includes(verify.first().content.toLowerCase())) { + this.fighting.delete(msg.channel.id); + return msg.say('Looks like they declined...'); + } + let turn = 0; + let aPts = 0; + let oPts = 0; + while (turn < 10) { + ++turn; + const emoji = emojis[Math.floor(Math.random() * emojis.length)]; + await msg.say(emoji); + const filter = res => [msg.author.id, opponent.id].includes(res.author.id) && res.content === emoji; + const win = await msg.channel.awaitMessages(filter, { + max: 1, + time: 30000 + }); + if (!win.size) { + await msg.say('Hmm... No one even tried that round.'); + continue; + } + const winner = win.first().author; + if (winner.id === msg.author.id) ++aPts; + else ++oPts; + await msg.say(stripIndents` + ${winner} won this round! + **${msg.author.username}:** ${aPts} + **${opponent.username}:** ${oPts} + `); + } + if (aPts === oPts) return msg.say('It\'s a tie!'); + return msg.say(`You win ${aPts > oPts ? msg.author : opponent} with ${aPts > oPts ? aPts : oPts} points!`); + } catch (err) { + this.playing.delete(msg.channel.id); + return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } +}; diff --git a/package.json b/package.json index 07bd784d..7e4df531 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "37.4.2", + "version": "37.5.0", "description": "Your personal server companion.", "main": "Shard.js", "scripts": {