diff --git a/.gitignore b/.gitignore index 64056266..e1806d7a 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,8 @@ report*.json .env config.json command-leaderboard.json -eng.traineddata + +# Tesseract Trained Data +*.traineddata # In-Development Commands diff --git a/README.md b/README.md index 91f07025..6a3ad0ac 100644 --- a/README.md +++ b/README.md @@ -257,7 +257,7 @@ in the appropriate channel's topic to use it. ## Commands -Total: 566 +Total: 567 ### Utility: @@ -607,6 +607,7 @@ Total: 566 * **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. +* **typing-race:** Race a user to see who can type a sentence faster. * **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/typing-race.js b/commands/games-mp/typing-race.js new file mode 100644 index 00000000..0150be8b --- /dev/null +++ b/commands/games-mp/typing-race.js @@ -0,0 +1,55 @@ +const Command = require('../../structures/Command'); +const { stripIndents } = require('common-tags'); +const sentences = require('../../assets/json/typing-test'); + +module.exports = class TypingRaceCommand extends Command { + constructor(client) { + super(client, { + name: 'typing-race', + group: 'games-mp', + memberName: 'typing-race', + description: 'Race a user to see who can type a sentence faster.', + guildOnly: true, + args: [ + { + key: 'opponent', + prompt: 'What user would you like to race against?', + 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...'); + } + const sentence = sentences[Math.floor(Math.random() * sentences.length)]; + await msg.reply(stripIndents` + **Type the following sentence within 30 seconds:** + ${sentence} + `); + const now = Date.now(); + const filter = res => [opponent.id, msg.author.id].includes(res.author.id) && res.content === sentence; + const winner = await msg.channel.awaitMessages(filter, { + max: 1, + time: 30000 + }); + this.client.games.delete(msg.channel.id); + if (!winner.size) return msg.reply('Oh... No one won.'); + return msg.reply(`The winner is ${winner.first().author}! (Took ${(Date.now() - now) / 1000} seconds)`); + } catch (err) { + this.client.games.delete(msg.channel.id); + throw err; + } + } +}; diff --git a/package.json b/package.json index b1c4bf73..836ae374 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "123.1.1", + "version": "123.2.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {