mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-17 08:17:35 +02:00
Add Personal Data to AniList
This commit is contained in:
@@ -17,6 +17,7 @@ SILVER_FISH_EMOJI_NAME=
|
|||||||
|
|
||||||
# API Keys, IDs, and Secrets
|
# API Keys, IDs, and Secrets
|
||||||
ALPHA_VANTAGE_KEY=
|
ALPHA_VANTAGE_KEY=
|
||||||
|
ANILIST_USERNAME=
|
||||||
CLEVERBOT_KEY=
|
CLEVERBOT_KEY=
|
||||||
CUSTOM_SEARCH_ID=
|
CUSTOM_SEARCH_ID=
|
||||||
DEVIANTART_ID=
|
DEVIANTART_ID=
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ const { MessageEmbed } = require('discord.js');
|
|||||||
const request = require('node-superfetch');
|
const request = require('node-superfetch');
|
||||||
const { stripIndents } = require('common-tags');
|
const { stripIndents } = require('common-tags');
|
||||||
const { cleanAnilistHTML } = require('../../util/Util');
|
const { cleanAnilistHTML } = require('../../util/Util');
|
||||||
|
const ANILIST_USERNAME = process.env.ANILIST_USERNAME || 'dragonfire535';
|
||||||
const searchGraphQL = stripIndents`
|
const searchGraphQL = stripIndents`
|
||||||
query ($search: String, $type: MediaType, $isAdult: Boolean) {
|
query ($search: String, $type: MediaType, $isAdult: Boolean) {
|
||||||
anime: Page (perPage: 10) {
|
anime: Page (perPage: 10) {
|
||||||
@@ -40,6 +41,17 @@ const resultGraphQL = stripIndents`
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
const personalGraphQL = stripIndents`
|
||||||
|
query ($name: String, $type: MediaType) {
|
||||||
|
MediaListCollection(userName: $name, type: $type) {
|
||||||
|
entries {
|
||||||
|
mediaId
|
||||||
|
score(format: POINT_10)
|
||||||
|
progress
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
const seasons = {
|
const seasons = {
|
||||||
WINTER: 'Winter',
|
WINTER: 'Winter',
|
||||||
SPRING: 'Spring',
|
SPRING: 'Spring',
|
||||||
@@ -76,6 +88,8 @@ module.exports = class AnimeCommand extends Command {
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.personalList = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
async run(msg, { query }) {
|
async run(msg, { query }) {
|
||||||
@@ -83,6 +97,8 @@ module.exports = class AnimeCommand extends Command {
|
|||||||
const id = await this.search(query);
|
const id = await this.search(query);
|
||||||
if (!id) return msg.say('Could not find any results.');
|
if (!id) return msg.say('Could not find any results.');
|
||||||
const anime = await this.fetchAnime(id);
|
const anime = await this.fetchAnime(id);
|
||||||
|
await this.fetchPersonalList();
|
||||||
|
const entry = this.personalList.find(ani => ani.media.id === id);
|
||||||
const embed = new MessageEmbed()
|
const embed = new MessageEmbed()
|
||||||
.setColor(0x02A9FF)
|
.setColor(0x02A9FF)
|
||||||
.setAuthor('AniList', 'https://i.imgur.com/iUIRC7v.png', 'https://anilist.co/')
|
.setAuthor('AniList', 'https://i.imgur.com/iUIRC7v.png', 'https://anilist.co/')
|
||||||
@@ -93,7 +109,10 @@ module.exports = class AnimeCommand extends Command {
|
|||||||
.addField('❯ Status', statuses[anime.status], true)
|
.addField('❯ Status', statuses[anime.status], true)
|
||||||
.addField('❯ Episodes', anime.episodes || '???', true)
|
.addField('❯ Episodes', anime.episodes || '???', true)
|
||||||
.addField('❯ Season', anime.season ? `${seasons[anime.season]} ${anime.startDate.year}` : '???', true)
|
.addField('❯ Season', anime.season ? `${seasons[anime.season]} ${anime.startDate.year}` : '???', true)
|
||||||
.addField('❯ Average Score', anime.meanScore ? `${anime.meanScore}/100` : '???', true);
|
.addField('❯ Average Score', anime.meanScore ? `${anime.meanScore}/100` : '???', true)
|
||||||
|
.addField(`❯ ${ANILIST_USERNAME}'s Score`, entry && entry.score ? `${entry.score}/10` : '???', true)
|
||||||
|
.addField(`❯ ${ANILIST_USERNAME}'s Progress`,
|
||||||
|
entry && entry.progress ? `${entry.progress}/${anime.episodes || ''}` : '???', true);
|
||||||
return msg.embed(embed);
|
return msg.embed(embed);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||||
@@ -126,4 +145,20 @@ module.exports = class AnimeCommand extends Command {
|
|||||||
});
|
});
|
||||||
return body.data.Media;
|
return body.data.Media;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fetchPersonalList() {
|
||||||
|
if (this.personalList) return this.personalList;
|
||||||
|
const { body } = await request
|
||||||
|
.post('https://graphql.anilist.co/')
|
||||||
|
.send({
|
||||||
|
variables: {
|
||||||
|
name: ANILIST_USERNAME,
|
||||||
|
type: 'ANIME'
|
||||||
|
},
|
||||||
|
query: personalGraphQL
|
||||||
|
});
|
||||||
|
this.personalList = body.data.MediaListCollection.entries;
|
||||||
|
setTimeout(() => { this.personalList = null; }, 3.6e+6);
|
||||||
|
return this.personalList;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "xiao",
|
"name": "xiao",
|
||||||
"version": "107.0.1",
|
"version": "107.0.2",
|
||||||
"description": "Your personal server companion.",
|
"description": "Your personal server companion.",
|
||||||
"main": "Xiao.js",
|
"main": "Xiao.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Reference in New Issue
Block a user