Typing Race Command

This commit is contained in:
Dragon Fire
2020-12-03 09:49:18 -05:00
parent d69631cef6
commit cd1991b173
4 changed files with 61 additions and 3 deletions
+3 -1
View File
@@ -11,6 +11,8 @@ report*.json
.env
config.json
command-leaderboard.json
eng.traineddata
# Tesseract Trained Data
*.traineddata
# In-Development Commands
+2 -1
View File
@@ -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.
+55
View File
@@ -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;
}
}
};
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "123.1.1",
"version": "123.2.0",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {