Today in History supports date entry

This commit is contained in:
Daniel Odendahl Jr
2018-02-22 11:56:49 +00:00
parent b76d72c9ea
commit 08ae313690
2 changed files with 22 additions and 4 deletions
+21 -3
View File
@@ -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!`);
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "66.0.0",
"version": "66.1.0",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {