Files
xiao/commands/events/today-in-history.js
T
Daniel Odendahl Jr b6afded306 Updates
2017-11-09 00:02:59 +00:00

37 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const { Command } = require('discord.js-commando');
const { MessageEmbed } = require('discord.js');
const snekfetch = require('snekfetch');
module.exports = class TodayInHistoryCommand extends Command {
constructor(client) {
super(client, {
name: 'today-in-history',
aliases: ['event', 'today', 'history'],
group: 'events',
memberName: 'today-in-history',
description: 'Responds with an event that occurred today in history.',
clientPermissions: ['EMBED_LINKS']
});
}
async run(msg) {
try {
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}`)
.addField(' See More',
event.links.map(link => `[${link.title}](${link.link.replace(/\)/g, '%29')})`).join(', '));
return msg.embed(embed);
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};