diff --git a/README.md b/README.md index 09a5c13a..b3e25013 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/commands/games-sp/memory.js b/commands/games-sp/memory.js new file mode 100644 index 00000000..a9205c7d --- /dev/null +++ b/commands/games-sp/memory.js @@ -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; + } +}; diff --git a/commands/games-sp/reaction-time.js b/commands/games-sp/reaction-time.js index 667e43f8..73420b86 100644 --- a/commands/games-sp/reaction-time.js +++ b/commands/games-sp/reaction-time.js @@ -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); diff --git a/package.json b/package.json index 91fd67ac..28a5f7c5 100644 --- a/package.json +++ b/package.json @@ -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",