Fix horoscope

This commit is contained in:
Dragon Fire
2018-07-31 13:31:16 -04:00
parent 8be1e0262c
commit d3692a7d8c
2 changed files with 13 additions and 8 deletions
+11 -7
View File
@@ -1,6 +1,7 @@
const Command = require('../../structures/Command');
const { MessageEmbed } = require('discord.js');
const request = require('node-superfetch');
const cheerio = require('cheerio');
const { list } = require('../../util/Util');
const signs = require('../../assets/json/horoscope');
@@ -27,20 +28,23 @@ module.exports = class HoroscopeCommand extends Command {
async run(msg, { sign }) {
try {
const { body } = await request.get(`http://theastrologer-api.herokuapp.com/api/horoscope/${sign}/today`);
const horoscope = await this.fetchHoroscope(sign);
const embed = new MessageEmbed()
.setColor(0x9797FF)
.setTitle(`Horoscope for ${body.sunsign}...`)
.setURL(`https://new.theastrologer.com/${body.sunsign}/`)
.setTitle(`Horoscope for ${sign}...`)
.setURL(`https://new.theastrologer.com/${sign}/`)
.setFooter('© Kelli Fox, The Astrologer')
.setTimestamp()
.setDescription(body.horoscope)
.addField(' Mood', body.meta.mood, true)
.addField(' Intensity', body.meta.intensity, true)
.addField(' Date', body.date, true);
.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').text();
}
};