mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
38 lines
1.3 KiB
JavaScript
38 lines
1.3 KiB
JavaScript
const { Command } = require('discord.js-commando');
|
|
const { RichEmbed } = require('discord.js');
|
|
const request = require('superagent');
|
|
|
|
module.exports = class TodayCommand extends Command {
|
|
constructor(client) {
|
|
super(client, {
|
|
name: 'today',
|
|
group: 'random',
|
|
memberName: 'today',
|
|
description: 'Tells you what happened today in history.'
|
|
});
|
|
}
|
|
|
|
async run(msg) {
|
|
if(msg.channel.type !== 'dm')
|
|
if(!msg.channel.permissionsFor(this.client.user).has('EMBED_LINKS'))
|
|
return msg.say('This Command requires the `Embed Links` Permission.');
|
|
try {
|
|
const { text } = await request
|
|
.get('http://history.muffinlabs.com/date')
|
|
.buffer(true);
|
|
const parsed = JSON.parse(text);
|
|
const events = parsed.data.Events;
|
|
const random = Math.floor(Math.random() * events.length);
|
|
const embed = new RichEmbed()
|
|
.setColor(0x9797FF)
|
|
.setURL(parsed.url)
|
|
.setTitle(`On this day (${parsed.date})...`)
|
|
.setTimestamp()
|
|
.setDescription(`${events[random].year}: ${events[random].text}`);
|
|
return msg.embed(embed);
|
|
} catch(err) {
|
|
return msg.say('An Unknown Error Occurred.');
|
|
}
|
|
}
|
|
};
|