From 5953405c85e4cfddb00dea8cb9f3deb15ac4a463 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Tue, 9 Jun 2020 00:05:08 -0400 Subject: [PATCH] Remove MAL Score from Anime and Manga --- README.md | 3 --- commands/search/anime-character.js | 6 +++--- commands/search/anime.js | 26 ++++---------------------- commands/search/manga.js | 26 ++++---------------------- package.json | 2 +- 5 files changed, 12 insertions(+), 51 deletions(-) diff --git a/README.md b/README.md index 105d9648..e69958a9 100644 --- a/README.md +++ b/README.md @@ -1186,9 +1186,6 @@ here. * just-do-it ([Original Motivational Speech](https://www.youtube.com/watch?v=ZXsQAXx_ao0)) - [muffinlabs - Today in History](http://history.muffinlabs.com/) * today-in-history ([API](http://history.muffinlabs.com/#api)) -- [MyAnimeList](https://myanimelist.net/) - * anime (Score Data) - * manga (Score Data) - [Mythbusters](https://go.discovery.com/tv-shows/mythbusters) * doors (Concept) - [NASA](https://www.nasa.gov/) diff --git a/commands/search/anime-character.js b/commands/search/anime-character.js index 634d95a2..5f7673a5 100644 --- a/commands/search/anime-character.js +++ b/commands/search/anime-character.js @@ -2,7 +2,7 @@ const Command = require('../../structures/Command'); const { MessageEmbed } = require('discord.js'); const request = require('node-superfetch'); const { stripIndents } = require('common-tags'); -const { embedURL, cleanAnilistHTML } = require('../../util/Util'); +const { embedURL, cleanAnilistHTML, trimArray } = require('../../util/Util'); const searchGraphQL = stripIndents` query ($search: String) { characters: Page (perPage: 1) { @@ -83,10 +83,10 @@ module.exports = class AnimeCharacterCommand extends Command { .setThumbnail(character.image.large || character.image.medium || null) .setTitle(`${character.name.first || ''}${character.name.last ? ` ${character.name.last}` : ''}`) .setDescription(character.description ? cleanAnilistHTML(character.description, false) : 'No description.') - .addField('❯ Appearances', character.media.edges.map(edge => { + .addField('❯ Appearances', trimArray(character.media.edges.map(edge => { const title = edge.node.title.english || edge.node.title.userPreferred; return embedURL(`${title} (${types[edge.node.type]})`, edge.node.siteUrl); - }).join(', ')); + }), 10).join(', ')); return msg.embed(embed); } catch (err) { return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); diff --git a/commands/search/anime.js b/commands/search/anime.js index 5ea24de7..60accd2a 100644 --- a/commands/search/anime.js +++ b/commands/search/anime.js @@ -1,7 +1,6 @@ const Command = require('../../structures/Command'); const { MessageEmbed } = require('discord.js'); const request = require('node-superfetch'); -const cheerio = require('cheerio'); const { stripIndents } = require('common-tags'); const { embedURL, cleanAnilistHTML } = require('../../util/Util'); const ANILIST_USERNAME = process.env.ANILIST_USERNAME || 'dragonfire535'; @@ -22,7 +21,6 @@ const resultGraphQL = stripIndents` query media($id: Int, $type: MediaType) { Media(id: $id, type: $type) { id - idMal title { english romaji @@ -40,6 +38,7 @@ const resultGraphQL = stripIndents` episodes isAdult meanScore + averageScore } } `; @@ -85,11 +84,6 @@ module.exports = class AnimeCommand extends Command { url: 'https://anilist.co/', reason: 'API', reasonURL: 'https://anilist.gitbook.io/anilist-apiv2-docs/' - }, - { - name: 'MyAnimeList', - url: 'https://myanimelist.net/', - reason: 'Score Data' } ], args: [ @@ -111,8 +105,6 @@ module.exports = class AnimeCommand extends Command { const anime = await this.fetchAnime(id); if (!this.personalList) await this.fetchPersonalList(); const entry = this.personalList.find(ani => ani.mediaId === id); - const malScore = await this.fetchMALScore(anime.idMal); - const malURL = `https://myanimelist.net/anime/${anime.idMal}`; const embed = new MessageEmbed() .setColor(0x02A9FF) .setAuthor('AniList', 'https://i.imgur.com/iUIRC7v.png', 'https://anilist.co/') @@ -123,9 +115,9 @@ module.exports = class AnimeCommand extends Command { .addField('❯ Status', statuses[anime.status], true) .addField('❯ Episodes', anime.episodes || '???', true) .addField('❯ Season', anime.season ? `${seasons[anime.season]} ${anime.startDate.year}` : '???', true) - .addField('❯ Average Score', anime.meanScore ? `${anime.meanScore}%` : '???', true) - .addField(`❯ ${ANILIST_USERNAME}'s Score`, entry && entry.score ? `${entry.score}/10` : '?/10', true) - .addField(`❯ MAL Score`, malScore ? embedURL(malScore, malURL) : '???', true); + .addField('❯ Mean Score', anime.meanScore ? `${anime.meanScore}%` : '???', true) + .addField('❯ Average Score', anime.averageScore ? `${anime.averageScore}%` : '???', true) + .addField(`❯ ${ANILIST_USERNAME}'s Score`, entry && entry.score ? `${entry.score}/10` : '???', true); return msg.embed(embed); } catch (err) { return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); @@ -159,16 +151,6 @@ module.exports = class AnimeCommand extends Command { return body.data.Media; } - async fetchMALScore(id) { - try { - const { text } = await request.get(`https://myanimelist.net/anime/${id}`); - const $ = cheerio.load(text); - return $('span[itemprop="ratingValue"]').first().text(); - } catch { - return null; - } - } - async fetchPersonalList() { if (this.personalList) return this.personalList; const { body } = await request diff --git a/commands/search/manga.js b/commands/search/manga.js index c4579e04..52221c45 100644 --- a/commands/search/manga.js +++ b/commands/search/manga.js @@ -1,7 +1,6 @@ const Command = require('../../structures/Command'); const { MessageEmbed } = require('discord.js'); const request = require('node-superfetch'); -const cheerio = require('cheerio'); const { stripIndents } = require('common-tags'); const { embedURL, cleanAnilistHTML } = require('../../util/Util'); const ANILIST_USERNAME = process.env.ANILIST_USERNAME || 'dragonfire535'; @@ -22,7 +21,6 @@ const resultGraphQL = stripIndents` query media($id: Int, $type: MediaType) { Media(id: $id, type: $type) { id - idMal title { english romaji @@ -40,6 +38,7 @@ const resultGraphQL = stripIndents` chapters isAdult meanScore + averageScore } } `; @@ -79,11 +78,6 @@ module.exports = class MangaCommand extends Command { url: 'https://anilist.co/', reason: 'API', reasonURL: 'https://anilist.gitbook.io/anilist-apiv2-docs/' - }, - { - name: 'MyAnimeList', - url: 'https://myanimelist.net/', - reason: 'Score Data' } ], args: [ @@ -105,8 +99,6 @@ module.exports = class MangaCommand extends Command { const manga = await this.fetchManga(id); if (!this.personalList) await this.fetchPersonalList(); const entry = this.personalList.find(ma => ma.mediaId === id); - const malScore = await this.fetchMALScore(manga.idMal); - const malURL = `https://myanimelist.net/manga/${manga.idMal}`; const embed = new MessageEmbed() .setColor(0x02A9FF) .setAuthor('AniList', 'https://i.imgur.com/iUIRC7v.png', 'https://anilist.co/') @@ -117,9 +109,9 @@ module.exports = class MangaCommand extends Command { .addField('❯ Status', statuses[manga.status], true) .addField('❯ Chapters / Volumes', `${manga.chapters || '???'}/${manga.volumes || '???'}`, true) .addField('❯ Year', manga.startDate.year || '???', true) - .addField('❯ Average Score', manga.meanScore ? `${manga.meanScore}%` : '???', true) - .addField(`❯ ${ANILIST_USERNAME}'s Score`, entry && entry.score ? `${entry.score}/10` : '?/10', true) - .addField(`❯ MAL Score`, malScore ? embedURL(malScore, malURL) : '???', true); + .addField('❯ Mean Score', manga.meanScore ? `${manga.meanScore}%` : '???', true) + .addField('❯ Average Score', manga.averageScore ? `${manga.averageScore}%` : '???', true) + .addField(`❯ ${ANILIST_USERNAME}'s Score`, entry && entry.score ? `${entry.score}/10` : '???', true); return msg.embed(embed); } catch (err) { return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); @@ -153,16 +145,6 @@ module.exports = class MangaCommand extends Command { return body.data.Media; } - async fetchMALScore(id) { - try { - const { text } = await request.get(`https://myanimelist.net/manga/${id}`); - const $ = cheerio.load(text); - return $('span[itemprop="ratingValue"]').first().text(); - } catch { - return null; - } - } - async fetchPersonalList() { if (this.personalList) return this.personalList; const { body } = await request diff --git a/package.json b/package.json index 3cade004..c7cf89e6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "116.9.2", + "version": "116.9.3", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {