Memory Command

This commit is contained in:
Dragon Fire
2020-05-20 11:17:57 -04:00
parent c3b46b2351
commit 513b91bcb0
4 changed files with 65 additions and 4 deletions
+2 -1
View File
@@ -224,7 +224,7 @@ in the appropriate channel's topic to use it.
## Commands
Total: 427
Total: 428
### Utility:
@@ -479,6 +479,7 @@ Total: 427
* **lottery:** Attempt to win the lottery with 6 numbers.
* **mad-libs:** Choose words that fill in the blanks to create a crazy story!
* **math-quiz:** See how fast you can answer a math problem in a given time limit.
* **memory:** Test your memory.
* **quiz:** Answer a quiz question.
* **reaction-time:** Test your reaction time.
* **rock-paper-scissors:** Play Rock-Paper-Scissors.
+60
View File
@@ -0,0 +1,60 @@
const Command = require('../../structures/Command');
const { stripIndents } = require('common-tags');
const { delay } = require('../../util/Util');
const directions = ['up', 'down', 'left', 'right'];
module.exports = class MemoryCommand extends Command {
constructor(client) {
super(client, {
name: 'memory',
group: 'games-sp',
memberName: 'memory',
description: 'Test your memory.',
args: [
{
key: 'level',
prompt: 'How many directions do you want to have to memorize?',
type: 'integer',
min: 1,
max: 20
}
]
});
}
async run(msg, { level }) {
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 {
const memorize = this.genArray(level);
const memorizeDisplay = memorize.map(direction => `\`${direction.toUpperCase()}\``).join(' ');
const memorizeMsg = await msg.say(stripIndents`
**You have 10 seconds to memorize:**
${memorizeDisplay}
`);
await delay(10000);
if (memorizeMsg.deletable) await memorizeMsg.delete();
await msg.say('Type what you saw. Don\'t worry about formatting, just the words.');
const memorizeType = memorize.join(' ');
const msgs = await msg.channel.awaitMessages(res => msg.author.id === res.author.id, {
max: 1,
time: 30000
});
this.client.games.delete(msg.channel.id);
if (!msgs.size) return msg.say(`Sorry, time is up! It was ${memorizeDisplay}.`);
const answer = msgs.first().content.toLowerCase();
if (answer !== memorizeType) return msg.say(`Sorry, you typed it wrong. It was ${memorizeDisplay}.`);
return msg.say('Nice job! 10/10! You deserve some cake!');
} catch (err) {
this.client.games.delete(msg.channel.id);
throw err;
}
}
genArray(level) {
const arr = [];
for (let i = 0; i < level; i++) arr.push(directions[Math.floor(Math.random() * directions.length)]);
return arr;
}
};
+1 -1
View File
@@ -29,7 +29,7 @@ module.exports = class ReactionTimeCommand extends Command {
time: 30000
});
this.client.games.delete(msg.channel.id);
if (!msgs.size) return msg.say(`Failed to answer within 30 seconds.`);
if (!msgs.size) return msg.say('Failed to answer within 30 seconds.');
return msg.say(`Nice one! (Took ${(Date.now() - now) / 1000} seconds)`);
} catch (err) {
this.client.games.delete(msg.channel.id);
+2 -2
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "114.16.8",
"version": "114.17.0",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {
@@ -46,7 +46,7 @@
"dotenv": "^8.2.0",
"gifencoder": "^2.0.1",
"mathjs": "^7.0.0",
"moment": "^2.25.3",
"moment": "^2.26.0",
"moment-duration-format": "^2.3.2",
"moment-timezone": "^0.5.31",
"node-superfetch": "^0.1.10",