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 Command = require('../../structures/Command');
const { MessageEmbed } = require('discord.js'); const { MessageEmbed } = require('discord.js');
const request = require('node-superfetch'); const request = require('node-superfetch');
const cheerio = require('cheerio');
const { list } = require('../../util/Util'); const { list } = require('../../util/Util');
const signs = require('../../assets/json/horoscope'); const signs = require('../../assets/json/horoscope');
@@ -27,20 +28,23 @@ module.exports = class HoroscopeCommand extends Command {
async run(msg, { sign }) { async run(msg, { sign }) {
try { 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() const embed = new MessageEmbed()
.setColor(0x9797FF) .setColor(0x9797FF)
.setTitle(`Horoscope for ${body.sunsign}...`) .setTitle(`Horoscope for ${sign}...`)
.setURL(`https://new.theastrologer.com/${body.sunsign}/`) .setURL(`https://new.theastrologer.com/${sign}/`)
.setFooter('© Kelli Fox, The Astrologer') .setFooter('© Kelli Fox, The Astrologer')
.setTimestamp() .setTimestamp()
.setDescription(body.horoscope) .setDescription(horoscope);
.addField(' Mood', body.meta.mood, true)
.addField(' Intensity', body.meta.intensity, true)
.addField(' Date', body.date, true);
return msg.embed(embed); return msg.embed(embed);
} catch (err) { } catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); 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();
}
}; };
+2 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "xiao", "name": "xiao",
"version": "85.9.1", "version": "85.9.2",
"description": "Your personal server companion.", "description": "Your personal server companion.",
"main": "Xiao.js", "main": "Xiao.js",
"scripts": { "scripts": {
@@ -32,6 +32,7 @@
}, },
"dependencies": { "dependencies": {
"canvas": "github:automattic/node-canvas", "canvas": "github:automattic/node-canvas",
"cheerio": "1.0.0-rc.2",
"common-tags": "^1.8.0", "common-tags": "^1.8.0",
"cowsay": "^1.3.1", "cowsay": "^1.3.1",
"custom-translate": "^2.2.4", "custom-translate": "^2.2.4",