From 227df68eb1e8abdd01770af689c0087eaafd7c1f Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Sat, 15 Jul 2017 05:08:35 +0000 Subject: [PATCH] Today Date Specification --- commands/random/today.js | 58 +++++++++++++++++++++++++++++----------- package.json | 2 +- 2 files changed, 44 insertions(+), 16 deletions(-) diff --git a/commands/random/today.js b/commands/random/today.js index be732af9..049b35b3 100644 --- a/commands/random/today.js +++ b/commands/random/today.js @@ -6,25 +6,53 @@ module.exports = class TodayCommand extends Command { constructor(client) { super(client, { name: 'today', + aliases: ['event'], group: 'random', memberName: 'today', - description: 'Responds with a random event that occurred today sometime in history.', - clientPermissions: ['EMBED_LINKS'] + description: 'Responds with an event that occurred today in history, or on a specific day.', + clientPermissions: ['EMBED_LINKS'], + args: [ + { + key: 'month', + prompt: 'Which month do you want events for?', + type: 'integer', + default: '', + validate: (month) => { + if (month < 13 && month > 0) return true; + else return 'Please enter a valid month.'; + } + }, + { + key: 'day', + prompt: 'Which day do you want events for?', + type: 'integer', + default: '', + validate: (day) => { + if (day < 32 && day > 0) return true; + else return 'Please enter a valid day.'; + } + }, + ] }); } - async run(msg) { - const { text } = await snekfetch - .get('http://history.muffinlabs.com/date'); - const body = JSON.parse(text); - const events = body.data.Events; - const event = events[Math.floor(Math.random() * events.length)]; - const embed = new MessageEmbed() - .setColor(0x9797FF) - .setURL(body.url) - .setTitle(`On this day (${body.date})...`) - .setTimestamp() - .setDescription(`${event.year}: ${event.text}`); - return msg.embed(embed); + async run(msg, args) { + const { month, day } = args; + try { + const { text } = await snekfetch + .get(`http://history.muffinlabs.com/date${month && day ? `/${month}/${day}` : ''}`); + const body = JSON.parse(text); + const events = body.data.Events; + const event = events[Math.floor(Math.random() * events.length)]; + const embed = new MessageEmbed() + .setColor(0x9797FF) + .setURL(body.url) + .setTitle(`On this day (${body.date})...`) + .setTimestamp() + .setDescription(`${event.year}: ${event.text}`); + return msg.embed(embed); + } catch (err) { + return msg.say(`An error occurred: \`${err.message}\`. You likely entered an invalid date.`); + } } }; diff --git a/package.json b/package.json index a2e6a684..f912cd01 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "27.2.0", + "version": "27.2.1", "description": "Your personal server companion.", "main": "Shard.js", "scripts": {