mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 15:07:42 +02:00
Typing Race Command
This commit is contained in:
+3
-1
@@ -11,6 +11,8 @@ report*.json
|
|||||||
.env
|
.env
|
||||||
config.json
|
config.json
|
||||||
command-leaderboard.json
|
command-leaderboard.json
|
||||||
eng.traineddata
|
|
||||||
|
# Tesseract Trained Data
|
||||||
|
*.traineddata
|
||||||
|
|
||||||
# In-Development Commands
|
# In-Development Commands
|
||||||
|
|||||||
@@ -257,7 +257,7 @@ in the appropriate channel's topic to use it.
|
|||||||
|
|
||||||
## Commands
|
## Commands
|
||||||
|
|
||||||
Total: 566
|
Total: 567
|
||||||
|
|
||||||
### Utility:
|
### Utility:
|
||||||
|
|
||||||
@@ -607,6 +607,7 @@ Total: 566
|
|||||||
* **russian-roulette:** Who will pull the trigger and die first?
|
* **russian-roulette:** Who will pull the trigger and die first?
|
||||||
* **spam-war:** See who can type more characters the fastest.
|
* **spam-war:** See who can type more characters the fastest.
|
||||||
* **tic-tac-toe:** Play a game of tic-tac-toe with another user.
|
* **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-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.
|
* **word-spud:** Hot potato, but with words.
|
||||||
|
|
||||||
|
|||||||
@@ -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
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "xiao",
|
"name": "xiao",
|
||||||
"version": "123.1.1",
|
"version": "123.2.0",
|
||||||
"description": "Your personal server companion.",
|
"description": "Your personal server companion.",
|
||||||
"main": "Xiao.js",
|
"main": "Xiao.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Reference in New Issue
Block a user