Today Command

This commit is contained in:
dragonfire535
2017-03-14 17:51:29 -04:00
parent 4f56703440
commit 27a1050b57
+43
View File
@@ -0,0 +1,43 @@
const commando = require('discord.js-commando');
const Discord = require('discord.js');
const request = require('request-promise');
class TodayCommand extends commando.Command {
constructor(Client){
super(Client, {
name: 'today',
group: 'random',
memberName: 'today',
description: 'Tells you what happened today. (;today)',
examples: [';today']
});
}
async run(message, args) {
if(message.channel.type !== 'dm') {
if(!message.channel.permissionsFor(this.client.user).hasPermission('SEND_MESSAGES')) return;
if(!message.channel.permissionsFor(this.client.user).hasPermission('READ_MESSAGES')) return;
if(!message.channel.permissionsFor(this.client.user).hasPermission('EMBED_LINKS')) return;
}
console.log("[Command] " + message.content);
const options = {
method: 'GET',
uri: 'http://history.muffinlabs.com/date',
json: true
}
request(options).then(function (response) {
let randomNumber = Math.floor(Math.random() * response.data.Events.length);
const embed = new Discord.RichEmbed()
.setColor(0x9797FF)
.setURL(response.url)
.setTitle('On this day (' + response.date + ')...')
.setTimestamp()
.setDescription(response.data.Events[randomNumber].text + ' (' + response.data.Events[randomNumber].year + ')');
message.channel.sendEmbed(embed).catch(console.error);
}).catch(function (err) {
message.channel.sendMessage(":x: Error! Something went wrong!");
});
}
}
module.exports = TodayCommand;