mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-18 21:40:49 +02:00
Change to kitsu.io
This commit is contained in:
+16
-21
@@ -1,19 +1,16 @@
|
|||||||
const Command = require('../../structures/Command');
|
const Command = require('../../structures/Command');
|
||||||
const { MessageEmbed } = require('discord.js');
|
const { MessageEmbed } = require('discord.js');
|
||||||
const snekfetch = require('snekfetch');
|
const snekfetch = require('snekfetch');
|
||||||
const { cleanXML, shorten } = require('../../structures/Util');
|
const { shorten } = require('../../structures/Util');
|
||||||
const { promisify } = require('util');
|
|
||||||
const xml = promisify(require('xml2js').parseString);
|
|
||||||
const { ANIMELIST_LOGIN } = process.env;
|
|
||||||
|
|
||||||
module.exports = class AnimeCommand extends Command {
|
module.exports = class AnimeCommand extends Command {
|
||||||
constructor(client) {
|
constructor(client) {
|
||||||
super(client, {
|
super(client, {
|
||||||
name: 'anime',
|
name: 'anime',
|
||||||
aliases: ['my-anime-list-anime', 'mal-anime'],
|
aliases: ['my-anime-list-anime', 'mal-anime', 'kitsu-anime'],
|
||||||
group: 'search',
|
group: 'search',
|
||||||
memberName: 'anime',
|
memberName: 'anime',
|
||||||
description: 'Searches My Anime List for your query, getting anime results.',
|
description: 'Searches Kitsu.io for your query, getting anime results.',
|
||||||
clientPermissions: ['EMBED_LINKS'],
|
clientPermissions: ['EMBED_LINKS'],
|
||||||
args: [
|
args: [
|
||||||
{
|
{
|
||||||
@@ -29,28 +26,26 @@ module.exports = class AnimeCommand extends Command {
|
|||||||
const { query } = args;
|
const { query } = args;
|
||||||
try {
|
try {
|
||||||
const { text } = await snekfetch
|
const { text } = await snekfetch
|
||||||
.get(`https://${ANIMELIST_LOGIN}@myanimelist.net/api/anime/search.xml`)
|
.get('https://kitsu.io/api/edge/anime')
|
||||||
.query({ q: query });
|
.query({ 'filter[text]': query });
|
||||||
const { anime } = await xml(text);
|
const body = JSON.parse(text);
|
||||||
const synopsis = cleanXML(anime.entry[0].synopsis[0]);
|
if (!body.meta.count) return msg.say('Could not find any results.');
|
||||||
const embed = new MessageEmbed()
|
const embed = new MessageEmbed()
|
||||||
.setColor(0x2D54A2)
|
.setColor(0xF75239)
|
||||||
.setAuthor('My Anime List', 'https://i.imgur.com/R4bmNFz.png')
|
.setAuthor('Kitsu.io', 'https://i.imgur.com/VnIpwgF.png')
|
||||||
.setURL(`https://myanimelist.net/anime/${anime.entry[0].id[0]}`)
|
.setThumbnail(body.data[0].attributes.posterImage ? body.data[0].attributes.posterImage.original : null)
|
||||||
.setThumbnail(anime.entry[0].image[0])
|
.setTitle(body.data[0].attributes.canonicalTitle)
|
||||||
.setTitle(`${anime.entry[0].title[0]} (English: ${anime.entry[0].english[0] || 'N/A'})`)
|
.setDescription(shorten(body.data[0].attributes.synopsis))
|
||||||
.setDescription(shorten(synopsis))
|
|
||||||
.addField('❯ Type',
|
.addField('❯ Type',
|
||||||
`${anime.entry[0].type[0]} - ${anime.entry[0].status[0]}`, true)
|
`${body.data[0].attributes.showType} - ${body.data[0].attributes.status}`, true)
|
||||||
.addField('❯ Episodes',
|
.addField('❯ Episodes',
|
||||||
anime.entry[0].episodes[0], true)
|
body.data[0].attributes.episodeCount || 'N/A', true)
|
||||||
.addField('❯ Start Date',
|
.addField('❯ Start Date',
|
||||||
anime.entry[0].start_date[0], true)
|
body.data[0].attributes.startDate ? new Date(body.data[0].attributes.startDate).toDateString() : 'N/A', true)
|
||||||
.addField('❯ End Date',
|
.addField('❯ End Date',
|
||||||
anime.entry[0].end_date[0], true);
|
body.data[0].attributes.endDate ? new Date(body.data[0].attributes.endDate).toDateString() : 'N/A', true);
|
||||||
return msg.embed(embed);
|
return msg.embed(embed);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err.message === 'Parse Error') return msg.say('Could not find any results.');
|
|
||||||
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-21
@@ -1,19 +1,16 @@
|
|||||||
const Command = require('../../structures/Command');
|
const Command = require('../../structures/Command');
|
||||||
const { MessageEmbed } = require('discord.js');
|
const { MessageEmbed } = require('discord.js');
|
||||||
const snekfetch = require('snekfetch');
|
const snekfetch = require('snekfetch');
|
||||||
const { cleanXML, shorten } = require('../../structures/Util');
|
const { shorten } = require('../../structures/Util');
|
||||||
const { promisify } = require('util');
|
|
||||||
const xml = promisify(require('xml2js').parseString);
|
|
||||||
const { ANIMELIST_LOGIN } = process.env;
|
|
||||||
|
|
||||||
module.exports = class MangaCommand extends Command {
|
module.exports = class MangaCommand extends Command {
|
||||||
constructor(client) {
|
constructor(client) {
|
||||||
super(client, {
|
super(client, {
|
||||||
name: 'manga',
|
name: 'manga',
|
||||||
aliases: ['my-anime-list-manga', 'mal-manga'],
|
aliases: ['my-anime-list-manga', 'mal-manga', 'kitsu-manga'],
|
||||||
group: 'search',
|
group: 'search',
|
||||||
memberName: 'manga',
|
memberName: 'manga',
|
||||||
description: 'Searches My Anime List for your query, getting manga results.',
|
description: 'Searches Kitsu.io for your query, getting manga results.',
|
||||||
clientPermissions: ['EMBED_LINKS'],
|
clientPermissions: ['EMBED_LINKS'],
|
||||||
args: [
|
args: [
|
||||||
{
|
{
|
||||||
@@ -29,28 +26,26 @@ module.exports = class MangaCommand extends Command {
|
|||||||
const { query } = args;
|
const { query } = args;
|
||||||
try {
|
try {
|
||||||
const { text } = await snekfetch
|
const { text } = await snekfetch
|
||||||
.get(`https://${ANIMELIST_LOGIN}@myanimelist.net/api/manga/search.xml`)
|
.get('https://kitsu.io/api/edge/manga')
|
||||||
.query({ q: query });
|
.query({ 'filter[text]': query });
|
||||||
const { manga } = await xml(text);
|
const body = JSON.parse(text);
|
||||||
const synopsis = cleanXML(manga.entry[0].synopsis[0]);
|
if (!body.meta.count) return msg.say('Could not find any results.');
|
||||||
const embed = new MessageEmbed()
|
const embed = new MessageEmbed()
|
||||||
.setColor(0x2D54A2)
|
.setColor(0xF75239)
|
||||||
.setAuthor('My Anime List', 'https://i.imgur.com/R4bmNFz.png')
|
.setAuthor('Kitsu.io', 'https://i.imgur.com/VnIpwgF.png')
|
||||||
.setURL(`https://myanimelist.net/manga/${manga.entry[0].id[0]}`)
|
.setThumbnail(body.data[0].attributes.posterImage ? body.data[0].attributes.posterImage.original : null)
|
||||||
.setThumbnail(manga.entry[0].image[0])
|
.setTitle(body.data[0].attributes.canonicalTitle)
|
||||||
.setTitle(`${manga.entry[0].title[0]} (English: ${manga.entry[0].english[0] || 'N/A'})`)
|
.setDescription(shorten(body.data[0].attributes.synopsis))
|
||||||
.setDescription(shorten(synopsis))
|
|
||||||
.addField('❯ Type',
|
.addField('❯ Type',
|
||||||
`${manga.entry[0].type[0]} - ${manga.entry[0].status[0]}`, true)
|
`${body.data[0].attributes.subtype} - ${body.data[0].attributes.status}`, true)
|
||||||
.addField('❯ Volumes / Chapters',
|
.addField('❯ Volumes / Chapters',
|
||||||
`${manga.entry[0].volumes[0]} / ${manga.entry[0].chapters[0]}`, true)
|
`${body.data[0].attributes.volumeCount || 'N/A'} / ${body.data[0].attributes.chapterCount || 'N/A'}`, true)
|
||||||
.addField('❯ Start Date',
|
.addField('❯ Start Date',
|
||||||
manga.entry[0].start_date[0], true)
|
body.data[0].attributes.startDate ? new Date(body.data[0].attributes.startDate).toDateString() : 'N/A', true)
|
||||||
.addField('❯ End Date',
|
.addField('❯ End Date',
|
||||||
manga.entry[0].end_date[0], true);
|
body.data[0].attributes.endDate ? new Date(body.data[0].attributes.endDate).toDateString() : 'N/A', true);
|
||||||
return msg.embed(embed);
|
return msg.embed(embed);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err.message === 'Parse Error') return msg.say('Could not find any results.');
|
|
||||||
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-2
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "xiaobot",
|
"name": "xiaobot",
|
||||||
"version": "37.5.3",
|
"version": "37.5.4",
|
||||||
"description": "Your personal server companion.",
|
"description": "Your personal server companion.",
|
||||||
"main": "Shard.js",
|
"main": "Shard.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -43,7 +43,6 @@
|
|||||||
"sequelize": "^4.8.2",
|
"sequelize": "^4.8.2",
|
||||||
"snekfetch": "^3.3.0",
|
"snekfetch": "^3.3.0",
|
||||||
"uws": "^8.14.1",
|
"uws": "^8.14.1",
|
||||||
"xml2js": "^0.4.19",
|
|
||||||
"zalgolize": "^1.2.4"
|
"zalgolize": "^1.2.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@@ -4,16 +4,6 @@ const { DBOTS_KEY, DBOTSORG_KEY } = process.env;
|
|||||||
const { stripIndents } = require('common-tags');
|
const { stripIndents } = require('common-tags');
|
||||||
|
|
||||||
class Util {
|
class Util {
|
||||||
static cleanXML(str) {
|
|
||||||
return str
|
|
||||||
.replace(/<br \/>/g, '')
|
|
||||||
.replace(/'/g, '\'')
|
|
||||||
.replace(/—/g, '—')
|
|
||||||
.replace(/("|")/g, '"')
|
|
||||||
.replace(/&/g, '&')
|
|
||||||
.replace(/(\[i\]|\[\/i\])/g, '*');
|
|
||||||
}
|
|
||||||
|
|
||||||
static postStats(count, id) {
|
static postStats(count, id) {
|
||||||
snekfetch
|
snekfetch
|
||||||
.post(`https://bots.discord.pw/api/bots/${id}/stats`)
|
.post(`https://bots.discord.pw/api/bots/${id}/stats`)
|
||||||
|
|||||||
Reference in New Issue
Block a user