MAL Scores Work Again

This commit is contained in:
Dragon Fire
2020-06-26 11:57:42 -04:00
parent 23fc863300
commit ce3d459f69
4 changed files with 46 additions and 5 deletions
+3
View File
@@ -1251,6 +1251,9 @@ 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)
- [Myinstants](https://www.myinstants.com/index/us/)
* soundboard ([Various Meme Sounds](https://www.myinstants.com/search/?name=meme))
- [Mythbusters](https://go.discovery.com/tv-shows/mythbusters)
+21 -2
View File
@@ -1,8 +1,9 @@
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 { cleanAnilistHTML } = require('../../util/Util');
const { cleanAnilistHTML, embedURL } = require('../../util/Util');
const ANILIST_USERNAME = process.env.ANILIST_USERNAME || 'dragonfire535';
const searchGraphQL = stripIndents`
query ($search: String, $type: MediaType, $isAdult: Boolean) {
@@ -21,6 +22,7 @@ const resultGraphQL = stripIndents`
query media($id: Int, $type: MediaType) {
Media(id: $id, type: $type) {
id
idMal
title {
english
romaji
@@ -88,6 +90,11 @@ 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: [
@@ -109,6 +116,8 @@ 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/')
@@ -119,8 +128,8 @@ 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(' Mean Score', anime.meanScore ? `${anime.meanScore}%` : '???', true)
.addField(' Average Score', anime.averageScore ? `${anime.averageScore}%` : '???', true)
.addField(` MAL Score`, malScore ? embedURL(malScore, malURL) : '???', true)
.addField(` ${ANILIST_USERNAME}'s Score`, entry && entry.score ? `${entry.score}/10` : '???', true)
.addField(' External Links', anime.externalLinks.length
? anime.externalLinks.map(link => `[${link.site}](${link.url})`).join(', ')
@@ -158,6 +167,16 @@ 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
+21 -2
View File
@@ -1,8 +1,9 @@
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 { cleanAnilistHTML } = require('../../util/Util');
const { cleanAnilistHTML, embedURL } = require('../../util/Util');
const ANILIST_USERNAME = process.env.ANILIST_USERNAME || 'dragonfire535';
const searchGraphQL = stripIndents`
query ($search: String, $type: MediaType, $isAdult: Boolean) {
@@ -21,6 +22,7 @@ const resultGraphQL = stripIndents`
query media($id: Int, $type: MediaType) {
Media(id: $id, type: $type) {
id
idMal
title {
english
romaji
@@ -82,6 +84,11 @@ 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: [
@@ -103,6 +110,8 @@ 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/')
@@ -113,8 +122,8 @@ 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(' Mean Score', manga.meanScore ? `${manga.meanScore}%` : '???', true)
.addField(' Average Score', manga.averageScore ? `${manga.averageScore}%` : '???', true)
.addField(` MAL Score`, malScore ? embedURL(malScore, malURL) : '???', true)
.addField(` ${ANILIST_USERNAME}'s Score`, entry && entry.score ? `${entry.score}/10` : '???', true)
.addField(' External Links', manga.externalLinks.length
? manga.externalLinks.map(link => `[${link.site}](${link.url})`).join(', ')
@@ -152,6 +161,16 @@ 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
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "116.37.3",
"version": "116.37.4",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {