From 08ae3136900e625f6dfd609f56ccaf2f071008c8 Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Thu, 22 Feb 2018 11:56:49 +0000 Subject: [PATCH] Today in History supports date entry --- commands/events/today-in-history.js | 24 +++++++++++++++++++++--- package.json | 2 +- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/commands/events/today-in-history.js b/commands/events/today-in-history.js index e8b7c3e9..ec1e03f3 100644 --- a/commands/events/today-in-history.js +++ b/commands/events/today-in-history.js @@ -10,13 +10,30 @@ module.exports = class TodayInHistoryCommand extends Command { group: 'events', memberName: 'today-in-history', description: 'Responds with an event that occurred today in history.', - clientPermissions: ['EMBED_LINKS'] + clientPermissions: ['EMBED_LINKS'], + args: [ + { + key: 'month', + prompt: 'What month would you like to get an event for?', + type: 'month', + default: '' + }, + { + key: 'day', + prompt: 'What day would you like to get an event for?', + type: 'integer', + default: '', + min: 1, + max: 31 + } + ] }); } - async run(msg) { + async run(msg, { month, day }) { + const date = month && day ? `/${month}/${day}` : ''; try { - const { text } = await snekfetch.get('http://history.muffinlabs.com/date'); + const { text } = await snekfetch.get(`http://history.muffinlabs.com/date${date}`); const body = JSON.parse(text); const events = body.data.Events; const event = events[Math.floor(Math.random() * events.length)]; @@ -30,6 +47,7 @@ module.exports = class TodayInHistoryCommand extends Command { event.links.map(link => `[${link.title}](${link.link.replace(/\)/g, '%29')})`).join(', ')); return msg.embed(embed); } catch (err) { + if (err.status === 404 || err.status === 500) return msg.say('Invalid date.'); return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); } } diff --git a/package.json b/package.json index 4a65a462..61ef3ecd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "66.0.0", + "version": "66.1.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {