diff --git a/README.md b/README.md index 57a78bd4..067d0df7 100644 --- a/README.md +++ b/README.md @@ -252,7 +252,7 @@ in the appropriate channel's topic to use it. ## Commands -Total: 531 +Total: 532 ### Utility: @@ -576,6 +576,7 @@ Total: 531 * **poker:** Play poker with up to 5 other users. * **quiz-duel:** Answer a series of quiz questions against an opponent. * **russian-roulette:** Who will pull the trigger and die first? +* **spam-war:** See who can type more characters the fastest. * **tic-tac-toe:** Play a game of tic-tac-toe with another user. * **word-chain:** Try to come up with words that start with the last letter of your opponent's word. * **word-spud:** Hot potato, but with words. diff --git a/commands/games-mp/spam-war.js b/commands/games-mp/spam-war.js new file mode 100644 index 00000000..f47a4556 --- /dev/null +++ b/commands/games-mp/spam-war.js @@ -0,0 +1,61 @@ +const Command = require('../../structures/Command'); +const { delay, verify } = require('../../util/Util'); + +module.exports = class SpamWarCommand extends Command { + constructor(client) { + super(client, { + name: 'spam-war', + aliases: ['spam-fight', 'spam-battle'], + group: 'games-mp', + memberName: 'spam-war', + description: 'See who can type more characters the fastest.', + guildOnly: true, + args: [ + { + key: 'opponent', + prompt: 'What user would you like to challenge?', + type: 'user' + } + ] + }); + } + + 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.'); + 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 }); + try { + await msg.say(`${opponent}, do you accept this challenge?`); + const verification = await verify(msg.channel, opponent); + if (!verification) { + this.client.games.delete(msg.channel.id); + return msg.say('Looks like they declined...'); + } + await msg.say('You get one point per character in your messages. You get 1 minute to spam.'); + await delay(5000); + await msg.say('You have **1 minute** to spam. Go!'); + const msgs = await msg.channel.awaitMessages(res => [opponent.id, msg.author.id].includes(res.author.id), { + time: 60000 + }); + const authorMsgs = msgs + .filter(authorMsg => authorMsg.author.id === msg.author.id) + .reduce((a, b) => a + b.content.length, 0); + const opponentMsgs = msgs + .filter(opponentMsg => opponentMsg.author.id === opponent.id) + .reduce((a, b) => a + b.content.length, 0); + const winner = authorMsgs > opponentMsgs ? msg.author : opponent; + const winnerPts = authorMsgs > opponentMsgs ? authorMsgs : opponentMsgs; + const loserPts = authorMsgs > opponentMsgs ? opponentMsgs : authorMsgs; + this.client.games.delete(msg.channel.id); + if (authorMsgs === opponentMsgs) { + return msg.say(`It was a tie! What are the odds? You both got **${winnerPts}** points!`); + } + return msg.say(`The winner is ${winner}, with **${winnerPts}** points! Your opponent only got ${loserPts}...`); + } catch (err) { + this.client.games.delete(msg.channel.id); + throw err; + } + } +}; diff --git a/package.json b/package.json index 564b5cf9..04e92255 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "119.12.5", + "version": "119.13.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {