mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Add MAL Score to Anime/Manga
This commit is contained in:
@@ -843,6 +843,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)
|
||||
- [Mythbusters](https://go.discovery.com/tv-shows/mythbusters)
|
||||
* doors (Concept)
|
||||
- [NASA](https://www.nasa.gov/)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
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 ANILIST_USERNAME = process.env.ANILIST_USERNAME || 'dragonfire535';
|
||||
@@ -21,6 +22,7 @@ const resultGraphQL = stripIndents`
|
||||
query media($id: Int, $type: MediaType) {
|
||||
Media(id: $id, type: $type) {
|
||||
id
|
||||
idMal
|
||||
title {
|
||||
english
|
||||
romaji
|
||||
@@ -91,6 +93,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: [
|
||||
@@ -112,6 +119,7 @@ module.exports = class AnimeCommand extends Command {
|
||||
const anime = await this.fetchAnime(id);
|
||||
await this.fetchPersonalList();
|
||||
const entry = this.personalList.find(ani => ani.mediaId === id);
|
||||
const malScore = await this.fetchMALScore(anime.idMal);
|
||||
const embed = new MessageEmbed()
|
||||
.setColor(0x02A9FF)
|
||||
.setAuthor('AniList', 'https://i.imgur.com/iUIRC7v.png', 'https://anilist.co/')
|
||||
@@ -124,8 +132,7 @@ module.exports = class AnimeCommand extends Command {
|
||||
.addField('❯ Season', anime.season ? `${seasons[anime.season]} ${anime.startDate.year}` : '???', true)
|
||||
.addField('❯ Average Score', anime.meanScore ? `${anime.meanScore}/100` : '???', true)
|
||||
.addField(`❯ ${ANILIST_USERNAME}'s Score`, entry && entry.score ? `${entry.score}/10` : '?/10', true)
|
||||
.addField(`❯ ${ANILIST_USERNAME}'s Progress`,
|
||||
entry && entry.status ? userStatuses[entry.status] : 'Not Planned', true);
|
||||
.addField(`❯ MAL Score`, malScore ? `${malScore}/10` : '???', true);
|
||||
return msg.embed(embed);
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
@@ -159,6 +166,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
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
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 searchGraphQL = stripIndents`
|
||||
@@ -14,6 +15,7 @@ const resultGraphQL = stripIndents`
|
||||
query media($id: Int, $type: MediaType) {
|
||||
Media(id: $id, type: $type) {
|
||||
id
|
||||
idMal
|
||||
title {
|
||||
english
|
||||
userPreferred
|
||||
@@ -53,6 +55,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: [
|
||||
@@ -69,7 +76,8 @@ module.exports = class MangaCommand extends Command {
|
||||
try {
|
||||
const id = await this.search(query);
|
||||
if (!id) return msg.say('Could not find any results.');
|
||||
const manga = await this.fetchAnime(id);
|
||||
const manga = await this.fetchManga(id);
|
||||
const malScore = await this.fetchMALScore(manga.idMal);
|
||||
const embed = new MessageEmbed()
|
||||
.setColor(0x02A9FF)
|
||||
.setAuthor('AniList', 'https://i.imgur.com/iUIRC7v.png', 'https://anilist.co/')
|
||||
@@ -80,7 +88,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('❯ Average Score', manga.meanScore ? `${manga.meanScore}/100` : '???', true);
|
||||
.addField('❯ Average Score', manga.meanScore ? `${manga.meanScore}/100` : '???', true)
|
||||
.addField(`❯ MAL Score`, malScore ? `${malScore}/10` : '???', true);
|
||||
return msg.embed(embed);
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
@@ -101,7 +110,7 @@ module.exports = class MangaCommand extends Command {
|
||||
return body.data.anime.results[0].id;
|
||||
}
|
||||
|
||||
async fetchAnime(id) {
|
||||
async fetchManga(id) {
|
||||
const { body } = await request
|
||||
.post('https://graphql.anilist.co/')
|
||||
.send({
|
||||
@@ -113,4 +122,14 @@ 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;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiao",
|
||||
"version": "112.12.1",
|
||||
"version": "112.12.2",
|
||||
"description": "Your personal server companion.",
|
||||
"main": "Xiao.js",
|
||||
"scripts": {
|
||||
|
||||
Reference in New Issue
Block a user