Files
xiao/commands/events/horoscope.js
T
Daniel Odendahl Jr 45c8d62dd5 Credit Command
2019-04-14 00:03:38 +00:00

57 lines
1.6 KiB
JavaScript

const Command = require('../../structures/Command');
const { MessageEmbed } = require('discord.js');
const request = require('node-superfetch');
const cheerio = require('cheerio');
const { list, firstUpperCase } = require('../../util/Util');
const signs = require('../../assets/json/horoscope');
module.exports = class HoroscopeCommand extends Command {
constructor(client) {
super(client, {
name: 'horoscope',
group: 'events',
memberName: 'horoscope',
description: 'Responds with today\'s horoscope for a specific Zodiac sign.',
details: `**Signs:** ${signs.join(', ')}`,
clientPermissions: ['EMBED_LINKS'],
credit: [
{
name: 'The Astrologer by Kelli Fox',
url: 'https://new.theastrologer.com/'
}
],
args: [
{
key: 'sign',
prompt: `Which sign would you like to get the horoscope for? Either ${list(signs, 'or')}.`,
type: 'string',
oneOf: signs,
parse: sign => sign.toLowerCase()
}
]
});
}
async run(msg, { sign }) {
try {
const horoscope = await this.fetchHoroscope(sign);
const embed = new MessageEmbed()
.setColor(0x9797FF)
.setTitle(`Horoscope for ${firstUpperCase(sign)}...`)
.setURL(`https://new.theastrologer.com/${sign}/`)
.setFooter('© Kelli Fox, The Astrologer')
.setTimestamp()
.setDescription(horoscope);
return msg.embed(embed);
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
async fetchHoroscope(sign) {
const { text } = await request.get(`https://new.theastrologer.com/${sign}/`);
const $ = cheerio.load(text);
return $('#today').find('p').first().text();
}
};