diff --git a/commands/search/anime.js b/commands/search/anime.js index 25596410..babb2ada 100644 --- a/commands/search/anime.js +++ b/commands/search/anime.js @@ -1,19 +1,16 @@ const Command = require('../../structures/Command'); const { MessageEmbed } = require('discord.js'); const snekfetch = require('snekfetch'); -const { cleanXML, shorten } = require('../../structures/Util'); -const { promisify } = require('util'); -const xml = promisify(require('xml2js').parseString); -const { ANIMELIST_LOGIN } = process.env; +const { shorten } = require('../../structures/Util'); module.exports = class AnimeCommand extends Command { constructor(client) { super(client, { name: 'anime', - aliases: ['my-anime-list-anime', 'mal-anime'], + aliases: ['my-anime-list-anime', 'mal-anime', 'kitsu-anime'], group: 'search', memberName: 'anime', - description: 'Searches My Anime List for your query, getting anime results.', + description: 'Searches Kitsu.io for your query, getting anime results.', clientPermissions: ['EMBED_LINKS'], args: [ { @@ -29,28 +26,26 @@ module.exports = class AnimeCommand extends Command { const { query } = args; try { const { text } = await snekfetch - .get(`https://${ANIMELIST_LOGIN}@myanimelist.net/api/anime/search.xml`) - .query({ q: query }); - const { anime } = await xml(text); - const synopsis = cleanXML(anime.entry[0].synopsis[0]); + .get('https://kitsu.io/api/edge/anime') + .query({ 'filter[text]': query }); + const body = JSON.parse(text); + if (!body.meta.count) return msg.say('Could not find any results.'); const embed = new MessageEmbed() - .setColor(0x2D54A2) - .setAuthor('My Anime List', 'https://i.imgur.com/R4bmNFz.png') - .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(shorten(synopsis)) + .setColor(0xF75239) + .setAuthor('Kitsu.io', 'https://i.imgur.com/VnIpwgF.png') + .setThumbnail(body.data[0].attributes.posterImage ? body.data[0].attributes.posterImage.original : null) + .setTitle(body.data[0].attributes.canonicalTitle) + .setDescription(shorten(body.data[0].attributes.synopsis)) .addField('❯ Type', - `${anime.entry[0].type[0]} - ${anime.entry[0].status[0]}`, true) + `${body.data[0].attributes.showType} - ${body.data[0].attributes.status}`, true) .addField('❯ Episodes', - anime.entry[0].episodes[0], true) + body.data[0].attributes.episodeCount || 'N/A', true) .addField('❯ Start Date', - anime.entry[0].start_date[0], true) + body.data[0].attributes.startDate ? new Date(body.data[0].attributes.startDate).toDateString() : 'N/A', true) .addField('❯ End Date', - anime.entry[0].end_date[0], true); + body.data[0].attributes.endDate ? new Date(body.data[0].attributes.endDate).toDateString() : 'N/A', true); return msg.embed(embed); } catch (err) { - if (err.message === 'Parse Error') return msg.say('Could not find any results.'); return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); } } diff --git a/commands/search/manga.js b/commands/search/manga.js index 55ee182d..77f110cd 100644 --- a/commands/search/manga.js +++ b/commands/search/manga.js @@ -1,19 +1,16 @@ const Command = require('../../structures/Command'); const { MessageEmbed } = require('discord.js'); const snekfetch = require('snekfetch'); -const { cleanXML, shorten } = require('../../structures/Util'); -const { promisify } = require('util'); -const xml = promisify(require('xml2js').parseString); -const { ANIMELIST_LOGIN } = process.env; +const { shorten } = require('../../structures/Util'); module.exports = class MangaCommand extends Command { constructor(client) { super(client, { name: 'manga', - aliases: ['my-anime-list-manga', 'mal-manga'], + aliases: ['my-anime-list-manga', 'mal-manga', 'kitsu-manga'], group: 'search', memberName: 'manga', - description: 'Searches My Anime List for your query, getting manga results.', + description: 'Searches Kitsu.io for your query, getting manga results.', clientPermissions: ['EMBED_LINKS'], args: [ { @@ -29,28 +26,26 @@ module.exports = class MangaCommand extends Command { const { query } = args; try { const { text } = await snekfetch - .get(`https://${ANIMELIST_LOGIN}@myanimelist.net/api/manga/search.xml`) - .query({ q: query }); - const { manga } = await xml(text); - const synopsis = cleanXML(manga.entry[0].synopsis[0]); + .get('https://kitsu.io/api/edge/manga') + .query({ 'filter[text]': query }); + const body = JSON.parse(text); + if (!body.meta.count) return msg.say('Could not find any results.'); const embed = new MessageEmbed() - .setColor(0x2D54A2) - .setAuthor('My Anime List', 'https://i.imgur.com/R4bmNFz.png') - .setURL(`https://myanimelist.net/manga/${manga.entry[0].id[0]}`) - .setThumbnail(manga.entry[0].image[0]) - .setTitle(`${manga.entry[0].title[0]} (English: ${manga.entry[0].english[0] || 'N/A'})`) - .setDescription(shorten(synopsis)) + .setColor(0xF75239) + .setAuthor('Kitsu.io', 'https://i.imgur.com/VnIpwgF.png') + .setThumbnail(body.data[0].attributes.posterImage ? body.data[0].attributes.posterImage.original : null) + .setTitle(body.data[0].attributes.canonicalTitle) + .setDescription(shorten(body.data[0].attributes.synopsis)) .addField('❯ Type', - `${manga.entry[0].type[0]} - ${manga.entry[0].status[0]}`, true) + `${body.data[0].attributes.subtype} - ${body.data[0].attributes.status}`, true) .addField('❯ Volumes / Chapters', - `${manga.entry[0].volumes[0]} / ${manga.entry[0].chapters[0]}`, true) + `${body.data[0].attributes.volumeCount || 'N/A'} / ${body.data[0].attributes.chapterCount || 'N/A'}`, true) .addField('❯ Start Date', - manga.entry[0].start_date[0], true) + body.data[0].attributes.startDate ? new Date(body.data[0].attributes.startDate).toDateString() : 'N/A', true) .addField('❯ End Date', - manga.entry[0].end_date[0], true); + body.data[0].attributes.endDate ? new Date(body.data[0].attributes.endDate).toDateString() : 'N/A', true); return msg.embed(embed); } catch (err) { - if (err.message === 'Parse Error') return msg.say('Could not find any results.'); return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); } } diff --git a/package.json b/package.json index 59a11549..ea5ffd99 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "37.5.3", + "version": "37.5.4", "description": "Your personal server companion.", "main": "Shard.js", "scripts": { @@ -43,7 +43,6 @@ "sequelize": "^4.8.2", "snekfetch": "^3.3.0", "uws": "^8.14.1", - "xml2js": "^0.4.19", "zalgolize": "^1.2.4" }, "devDependencies": { diff --git a/structures/Util.js b/structures/Util.js index cb721ae5..9a4c88aa 100644 --- a/structures/Util.js +++ b/structures/Util.js @@ -4,16 +4,6 @@ const { DBOTS_KEY, DBOTSORG_KEY } = process.env; const { stripIndents } = require('common-tags'); class Util { - static cleanXML(str) { - return str - .replace(/
/g, '') - .replace(/'/g, '\'') - .replace(/—/g, '—') - .replace(/("|")/g, '"') - .replace(/&/g, '&') - .replace(/(\[i\]|\[\/i\])/g, '*'); - } - static postStats(count, id) { snekfetch .post(`https://bots.discord.pw/api/bots/${id}/stats`)