diff --git a/commands/search/anime.js b/commands/search/anime.js index 3f9dd0af..a1216d04 100644 --- a/commands/search/anime.js +++ b/commands/search/anime.js @@ -1,7 +1,8 @@ const { Command } = require('discord.js-commando'); const { RichEmbed } = require('discord.js'); const request = require('superagent'); -const cheerio = require('cheerio'); +const { promisify } = require('tsubaki'); +const xml = promisify(require('xml2js').parseString); const { ANIMELIST_LOGIN } = process.env; module.exports = class AnimeCommand extends Command { @@ -31,8 +32,8 @@ module.exports = class AnimeCommand extends Command { const { text } = await request .get(`https://${ANIMELIST_LOGIN}@myanimelist.net/api/anime/search.xml?q=${query}`) .buffer(true); - const $ = cheerio.load(text, { xmlMode: true }); - const synopsis = $('synopsis').first().text().substr(0, 2000) + const { anime } = await xml(text); + const synopsis = anime.entry[0].synopsis[0].substr(0, 2000) .replace(/(
)/g, '') .replace(/(')/g, '\'') .replace(/(—)/g, '—') @@ -41,18 +42,18 @@ module.exports = class AnimeCommand extends Command { const embed = new RichEmbed() .setColor(0x2D54A2) .setAuthor('My Anime List', 'https://i.imgur.com/R4bmNFz.png') - .setURL(`https://myanimelist.net/anime/${$('id').first().text()}`) - .setThumbnail($('image').first().text()) - .setTitle(`${$('title').first().text()} (English: ${$('english').first().text() || 'N/A'})`) + .setURL(`https://myanimelist.net/anime/${anime.entry[0].id[0]}`) + .setThumbnail(anime.entry[0].image[0]) + .setTitle(`${anime.entry[0].title[0]} (English: ${anime.entry[0].english[0] || 'N/A'})`) .setDescription(synopsis) .addField('Type', - `${$('type').first().text()} - ${$('status').first().text()}`, true) + `${anime.entry[0].type[0]} - ${anime.entry[0].status[0]}`, true) .addField('Episodes', - $('episodes').first().text(), true) + anime.entry[0].episodes[0], true) .addField('Start Date', - $('start_date').first().text(), true) + anime.entry[0].start_date[0], true) .addField('End Date', - $('end_date').first().text(), true); + anime.entry[0].end_date[0], true); return msg.embed(embed); } catch (err) { return msg.say('Error: No Results.'); diff --git a/package.json b/package.json index 31ebea11..31048f4b 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,6 @@ "node-opus": "^0.2.6", "pg": "^6.1.5", "sequelize": "^3.30.4", - "snekfetch": "devsnek/snekfetch", "superagent": "^3.5.2", "tsubaki": "^1.1.0", "xml2js": "^0.4.17",