mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Anime Staff Command
This commit is contained in:
@@ -268,7 +268,7 @@ in the appropriate channel's topic to use it.
|
||||
|
||||
## Commands
|
||||
|
||||
Total: 559
|
||||
Total: 560
|
||||
|
||||
### Utility:
|
||||
|
||||
@@ -468,6 +468,7 @@ Total: 559
|
||||
### Search:
|
||||
|
||||
* **anime-character:** Searches AniList for your query, getting character results.
|
||||
* **anime-staff:** Searches AniList for your query, getting staff results.
|
||||
* **anime:** Searches AniList for your query, getting anime results.
|
||||
* **book:** Searches Google Books for a book.
|
||||
* **bulbapedia:** Searches Bulbapedia for your query.
|
||||
@@ -954,6 +955,7 @@ here.
|
||||
* anime ([API](https://anilist.gitbook.io/anilist-apiv2-docs/))
|
||||
* anime-airing ([API](https://anilist.gitbook.io/anilist-apiv2-docs/))
|
||||
* anime-character ([API](https://anilist.gitbook.io/anilist-apiv2-docs/))
|
||||
* anime-staff ([API](https://anilist.gitbook.io/anilist-apiv2-docs/))
|
||||
* manga ([API](https://anilist.gitbook.io/anilist-apiv2-docs/))
|
||||
- [Antidepressants or Tolkien](https://antidepressantsortolkien.now.sh/)
|
||||
* antidepressant-or-tolkien (Question Data)
|
||||
|
||||
@@ -29,7 +29,7 @@ const resultGraphQL = stripIndents`
|
||||
node {
|
||||
title {
|
||||
english
|
||||
userPreferred
|
||||
romaji
|
||||
}
|
||||
type
|
||||
siteUrl
|
||||
@@ -84,7 +84,7 @@ module.exports = class AnimeCharacterCommand extends Command {
|
||||
.setTitle(`${character.name.first || ''}${character.name.last ? ` ${character.name.last}` : ''}`)
|
||||
.setDescription(character.description ? cleanAnilistHTML(character.description, false) : 'No description.')
|
||||
.addField('❯ Appearances', trimArray(character.media.edges.map(edge => {
|
||||
const title = edge.node.title.english || edge.node.title.userPreferred;
|
||||
const title = edge.node.title.english || edge.node.title.romaji;
|
||||
return embedURL(`${title} (${types[edge.node.type]})`, edge.node.siteUrl);
|
||||
}), 5).join(', '));
|
||||
return msg.embed(embed);
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const request = require('node-superfetch');
|
||||
const { stripIndents } = require('common-tags');
|
||||
const { embedURL, cleanAnilistHTML, trimArray } = require('../../util/Util');
|
||||
const searchGraphQL = stripIndents`
|
||||
query ($search: String) {
|
||||
staff: Page (perPage: 1) {
|
||||
results: staff (search: $search) { id }
|
||||
}
|
||||
}
|
||||
`;
|
||||
const resultGraphQL = stripIndents`
|
||||
query ($id: Int!) {
|
||||
Staff (id: $id) {
|
||||
id
|
||||
name {
|
||||
first
|
||||
last
|
||||
}
|
||||
image {
|
||||
large
|
||||
medium
|
||||
}
|
||||
description(asHtml: false)
|
||||
siteUrl
|
||||
characters(page: 1, perPage: 5) {
|
||||
edges {
|
||||
node {
|
||||
name {
|
||||
full
|
||||
}
|
||||
siteUrl
|
||||
}
|
||||
}
|
||||
}
|
||||
staffMedia(page: 1, perPage: 5) {
|
||||
edges {
|
||||
node {
|
||||
title {
|
||||
english
|
||||
romaji
|
||||
}
|
||||
type
|
||||
siteUrl
|
||||
}
|
||||
staffRole
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
const types = {
|
||||
ANIME: 'Anime',
|
||||
MANGA: 'Manga'
|
||||
};
|
||||
|
||||
module.exports = class AnimeStaffCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'anime-staff',
|
||||
aliases: ['anilist-staff', 'staff', 'manga-staff', 'ani-staff'],
|
||||
group: 'search',
|
||||
memberName: 'anime-staff',
|
||||
description: 'Searches AniList for your query, getting staff results.',
|
||||
clientPermissions: ['EMBED_LINKS'],
|
||||
credit: [
|
||||
{
|
||||
name: 'AniList',
|
||||
url: 'https://anilist.co/',
|
||||
reason: 'API',
|
||||
reasonURL: 'https://anilist.gitbook.io/anilist-apiv2-docs/'
|
||||
}
|
||||
],
|
||||
args: [
|
||||
{
|
||||
key: 'query',
|
||||
prompt: 'What staff member would you like to search for?',
|
||||
type: 'string'
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg, { query }) {
|
||||
try {
|
||||
const id = await this.search(query);
|
||||
if (!id) return msg.say('Could not find any results.');
|
||||
const staff = await this.fetchStaff(id);
|
||||
const embed = new MessageEmbed()
|
||||
.setColor(0x02A9FF)
|
||||
.setAuthor('AniList', 'https://i.imgur.com/iUIRC7v.png', 'https://anilist.co/')
|
||||
.setURL(staff.siteUrl)
|
||||
.setThumbnail(staff.image.large || staff.image.medium || null)
|
||||
.setTitle(`${staff.name.first || ''}${staff.name.last ? ` ${staff.name.last}` : ''}`)
|
||||
.setDescription(staff.description ? cleanAnilistHTML(staff.description, false) : 'No description.')
|
||||
.addField('❯ Voice Roles', staff.characters.edges.length
|
||||
? trimArray(staff.characters.edges.map(edge => embedURL(edge.name.full, edge.node.siteUrl)), 5).join(', ')
|
||||
: 'None')
|
||||
.addField('❯ Production Roles', staff.staffMedia.edges.length ? trimArray(staff.staffMedia.edges.map(edge => {
|
||||
const title = edge.node.title.english || edge.node.title.romaji;
|
||||
return embedURL(`${title} (${types[edge.node.type]})`, edge.node.siteUrl);
|
||||
}), 5).join(', ') : 'None');
|
||||
return msg.embed(embed);
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
|
||||
async search(query) {
|
||||
const { body } = await request
|
||||
.post('https://graphql.anilist.co/')
|
||||
.send({
|
||||
variables: { search: query },
|
||||
query: searchGraphQL
|
||||
});
|
||||
if (!body.data.staff.results.length) return null;
|
||||
return body.data.staff.results[0].id;
|
||||
}
|
||||
|
||||
async fetchStaff(id) {
|
||||
const { body } = await request
|
||||
.post('https://graphql.anilist.co/')
|
||||
.send({
|
||||
variables: { id },
|
||||
query: resultGraphQL
|
||||
});
|
||||
return body.data.Staff;
|
||||
}
|
||||
};
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiao",
|
||||
"version": "119.44.2",
|
||||
"version": "119.45.0",
|
||||
"description": "Your personal server companion.",
|
||||
"main": "Xiao.js",
|
||||
"scripts": {
|
||||
|
||||
Reference in New Issue
Block a user