Fix bugs in various commands

This commit is contained in:
Dragon Fire
2020-11-07 10:59:00 -05:00
parent 5b5487674f
commit 14c36e5314
7 changed files with 23 additions and 19 deletions
+5
View File
@@ -42,6 +42,7 @@ module.exports = class HoroscopeCommand extends Command {
.setTitle(`Horoscope for ${firstUpperCase(sign)}...`) .setTitle(`Horoscope for ${firstUpperCase(sign)}...`)
.setURL(`https://astrology.tv/horoscope/signs/${sign}/`) .setURL(`https://astrology.tv/horoscope/signs/${sign}/`)
.setFooter('© Kelli Fox, The Astrologer') .setFooter('© Kelli Fox, The Astrologer')
.setThumbnail(this.getImageURL(sign))
.setTimestamp() .setTimestamp()
.setDescription(horoscope); .setDescription(horoscope);
return msg.embed(embed); return msg.embed(embed);
@@ -55,4 +56,8 @@ module.exports = class HoroscopeCommand extends Command {
const $ = cheerio.load(text); const $ = cheerio.load(text);
return $('div[class="ct-text-block day-tabs-content_horoscope"]').eq(1).text(); return $('div[class="ct-text-block day-tabs-content_horoscope"]').eq(1).text();
} }
getImageURL(sign) {
return `https://astrology.tv/wp-content/uploads/2019/07/astrology_tv_${sign}_cover-768x768.jpg`;
}
}; };
+5 -6
View File
@@ -1,7 +1,6 @@
const Command = require('../../structures/Command'); const Command = require('../../structures/Command');
const request = require('node-superfetch'); const request = require('node-superfetch');
const { stripIndents } = require('common-tags'); const { stripIndents } = require('common-tags');
const { shorten } = require('../../util/Util');
module.exports = class SuperpowerCommand extends Command { module.exports = class SuperpowerCommand extends Command {
constructor(client) { constructor(client) {
@@ -32,7 +31,7 @@ module.exports = class SuperpowerCommand extends Command {
const article = await this.fetchSuperpower(id); const article = await this.fetchSuperpower(id);
return msg.reply(stripIndents` return msg.reply(stripIndents`
Your superpower is... **${article.title}**! Your superpower is... **${article.title}**!
_${shorten(article.content.map(section => section.text).join('\n\n'), 1950)}_ _${article.abstract}_
`); `);
} 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!`);
@@ -41,7 +40,7 @@ module.exports = class SuperpowerCommand extends Command {
async random() { async random() {
const { body } = await request const { body } = await request
.get('http://powerlisting.wikia.com/api.php') .get('http://powerlisting.fandom.com/api.php')
.query({ .query({
action: 'query', action: 'query',
list: 'random', list: 'random',
@@ -55,8 +54,8 @@ module.exports = class SuperpowerCommand extends Command {
async fetchSuperpower(id) { async fetchSuperpower(id) {
const { body } = await request const { body } = await request
.get('http://powerlisting.wikia.com/api/v1/Articles/AsSimpleJson/') .get('https://powerlisting.fandom.com/api/v1/Articles/Details')
.query({ id }); .query({ ids: id });
return body.sections[0]; return body.items[id.toString()];
} }
}; };
+1 -1
View File
@@ -66,7 +66,7 @@ module.exports = class MayoClinicCommand extends Command {
return { return {
name: $('h1').first().text().trim(), name: $('h1').first().text().trim(),
url: location, url: location,
description: $('p').first().text().trim() description: $('p').eq(2).text().trim()
}; };
} }
return location; return location;
+2 -1
View File
@@ -1,6 +1,7 @@
const Command = require('../../structures/Command'); const Command = require('../../structures/Command');
const request = require('node-superfetch'); const request = require('node-superfetch');
const { html } = require('common-tags'); const { html } = require('common-tags');
const { shorten } = require('../../util/Util');
module.exports = class PoemCommand extends Command { module.exports = class PoemCommand extends Command {
constructor(client) { constructor(client) {
@@ -42,7 +43,7 @@ module.exports = class PoemCommand extends Command {
const data = body[0]; const data = body[0];
return msg.say(html` return msg.say(html`
**${data.title}** by **${data.author}** **${data.title}** by **${data.author}**
${data.lines.join('\n')} ${shorten(data.lines.join('\n'), 1750)}
`); `);
} catch (err) { } catch (err) {
if (err.status === 404) return msg.say('Could not find any results.'); if (err.status === 404) return msg.say('Could not find any results.');
+1 -1
View File
@@ -43,7 +43,7 @@ module.exports = class PornhubCommand extends Command {
.query({ search: query }); .query({ search: query });
if (text.includes('<div class="noResultsWrapper">')) return null; if (text.includes('<div class="noResultsWrapper">')) return null;
const $ = cheerio.load(text); const $ = cheerio.load(text);
const video = $('li[class="pcVideoListItem js-pop videoblock videoBox"]').eq(5); const video = $('li[class="pcVideoListItem js-pop videoblock videoBox]').eq(5);
return `https://www.pornhub.com/view_video.php?viewkey=${video.attr('_vkey')}`; return `https://www.pornhub.com/view_video.php?viewkey=${video.attr('_vkey')}`;
} }
}; };
+8 -9
View File
@@ -1,7 +1,6 @@
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 { shorten } = require('../../util/Util');
module.exports = class WikiaCommand extends Command { module.exports = class WikiaCommand extends Command {
constructor(client) { constructor(client) {
@@ -44,19 +43,19 @@ module.exports = class WikiaCommand extends Command {
.setColor(0x002D54) .setColor(0x002D54)
.setTitle(data.title) .setTitle(data.title)
.setURL(url) .setURL(url)
.setAuthor('Wikia', 'https://i.imgur.com/15A34JT.png', 'http://www.wikia.com/fandom') .setAuthor('FANDOM', 'https://i.imgur.com/15A34JT.png', 'https://www.fandom.com/')
.setDescription(shorten(data.content.map(section => section.text).join('\n\n'))) .setDescription(data.abstract)
.setThumbnail(data.images.length ? data.images[0].src : null); .setThumbnail(data.thumbnail);
return msg.embed(embed); return msg.embed(embed);
} catch (err) { } catch (err) {
if (err.status === 404) return msg.say('Could not find any results'); if (err.status === 404) return msg.say('Could not find any results.');
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Perhaps you entered an invalid wiki?`); return msg.say(`Oh no, an error occurred: \`${err.message}\`. Perhaps you entered an invalid wiki?`);
} }
} }
async search(wiki, query) { async search(wiki, query) {
const { body } = await request const { body } = await request
.get(`https://${wiki}.wikia.com/api/v1/Search/List/`) .get(`https://${wiki}.fandom.com/api/v1/Search/List/`)
.query({ .query({
query, query,
limit: 1, limit: 1,
@@ -68,8 +67,8 @@ module.exports = class WikiaCommand extends Command {
async fetchArticle(wiki, id) { async fetchArticle(wiki, id) {
const { body } = await request const { body } = await request
.get(`https://${wiki}.wikia.com/api/v1/Articles/AsSimpleJson/`) .get(`https://${wiki}.fandom.com/api/v1/Articles/Details`)
.query({ id }); .query({ ids: id });
return body.sections[0]; return body.items[id.toString()];
} }
}; };
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "xiao", "name": "xiao",
"version": "119.38.1", "version": "119.38.2",
"description": "Your personal server companion.", "description": "Your personal server companion.",
"main": "Xiao.js", "main": "Xiao.js",
"scripts": { "scripts": {