mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-08 15:19:14 +02:00
Change Kitsu to MAL
This commit is contained in:
@@ -1,53 +0,0 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const snekfetch = require('snekfetch');
|
||||
const { shorten } = require('../../util/Util');
|
||||
|
||||
module.exports = class KitsuAnimeCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'kitsu-anime',
|
||||
aliases: ['my-anime-list-anime', 'mal-anime', 'anime'],
|
||||
group: 'search',
|
||||
memberName: 'kitsu-anime',
|
||||
description: 'Searches Kitsu.io for your query, getting anime results.',
|
||||
clientPermissions: ['EMBED_LINKS'],
|
||||
args: [
|
||||
{
|
||||
key: 'query',
|
||||
prompt: 'What anime would you like to search for?',
|
||||
type: 'string'
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg, { query }) {
|
||||
try {
|
||||
const { text } = await snekfetch
|
||||
.get('https://kitsu.io/api/edge/anime')
|
||||
.query({ 'filter[text]': query });
|
||||
const body = JSON.parse(text);
|
||||
if (!body.data.length) return msg.say('Could not find any results.');
|
||||
const data = body.data[0].attributes;
|
||||
const embed = new MessageEmbed()
|
||||
.setColor(0xF75239)
|
||||
.setAuthor('Kitsu.io', 'https://i.imgur.com/y7nDpqR.png')
|
||||
.setURL(`https://kitsu.io/anime/${data.slug}`)
|
||||
.setThumbnail(data.posterImage ? data.posterImage.original : null)
|
||||
.setTitle(data.canonicalTitle)
|
||||
.setDescription(shorten(data.synopsis))
|
||||
.addField('❯ Type',
|
||||
`${data.showType} - ${data.status}`, true)
|
||||
.addField('❯ Episodes',
|
||||
data.episodeCount || '???', true)
|
||||
.addField('❯ Start Date',
|
||||
data.startDate ? new Date(data.startDate).toDateString() : '???', true)
|
||||
.addField('❯ End Date',
|
||||
data.endDate ? new Date(data.endDate).toDateString() : '???', true);
|
||||
return msg.embed(embed);
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1,53 +0,0 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const snekfetch = require('snekfetch');
|
||||
const { shorten } = require('../../util/Util');
|
||||
|
||||
module.exports = class KitsuMangaCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'kitsu-manga',
|
||||
aliases: ['my-anime-list-manga', 'mal-manga', 'manga'],
|
||||
group: 'search',
|
||||
memberName: 'kitsu-manga',
|
||||
description: 'Searches Kitsu.io for your query, getting manga results.',
|
||||
clientPermissions: ['EMBED_LINKS'],
|
||||
args: [
|
||||
{
|
||||
key: 'query',
|
||||
prompt: 'What manga would you like to search for?',
|
||||
type: 'string'
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg, { query }) {
|
||||
try {
|
||||
const { text } = await snekfetch
|
||||
.get('https://kitsu.io/api/edge/manga')
|
||||
.query({ 'filter[text]': query });
|
||||
const body = JSON.parse(text);
|
||||
if (!body.data.length) return msg.say('Could not find any results.');
|
||||
const data = body.data[0].attributes;
|
||||
const embed = new MessageEmbed()
|
||||
.setColor(0xF75239)
|
||||
.setAuthor('Kitsu.io', 'https://i.imgur.com/y7nDpqR.png')
|
||||
.setURL(`https://kitsu.io/manga/${data.slug}`)
|
||||
.setThumbnail(data.posterImage ? data.posterImage.original : null)
|
||||
.setTitle(data.canonicalTitle)
|
||||
.setDescription(shorten(data.synopsis))
|
||||
.addField('❯ Type',
|
||||
`${data.subtype} - ${data.status}`, true)
|
||||
.addField('❯ Volumes / Chapters',
|
||||
`${data.volumeCount || '???'} / ${data.chapterCount || '???'}`, true)
|
||||
.addField('❯ Start Date',
|
||||
data.startDate ? new Date(data.startDate).toDateString() : '???', true)
|
||||
.addField('❯ End Date',
|
||||
data.endDate ? new Date(data.endDate).toDateString() : '???', true);
|
||||
return msg.embed(embed);
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,55 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const snekfetch = require('snekfetch');
|
||||
const { xml2js } = require('xml-js');
|
||||
const { shorten, cleanXML } = require('../../util/Util');
|
||||
const { MAL_LOGIN } = process.env;
|
||||
|
||||
module.exports = class MyAnimeListAnimeCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'my-anime-list-anime',
|
||||
aliases: ['mal-anime', 'anime'],
|
||||
group: 'search',
|
||||
memberName: 'my-anime-list-anime',
|
||||
description: 'Searches My Anime List for your query, getting anime results.',
|
||||
clientPermissions: ['EMBED_LINKS'],
|
||||
args: [
|
||||
{
|
||||
key: 'query',
|
||||
prompt: 'What anime would you like to search for?',
|
||||
type: 'string'
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg, { query }) {
|
||||
try {
|
||||
const { text } = await snekfetch
|
||||
.get(`https://${MAL_LOGIN}@myanimelist.net/api/anime/search.xml`)
|
||||
.query({ q: query });
|
||||
const body = xml2js(text, { compact: true }).anime;
|
||||
const data = body.length ? body.entry[0] : body.entry;
|
||||
const embed = new MessageEmbed()
|
||||
.setColor(0x2D54A2)
|
||||
.setAuthor('My Anime List', 'https://i.imgur.com/5rivpMM.png')
|
||||
.setURL(`https://myanimelist.net/anime/${data.id._text}`)
|
||||
.setThumbnail(data.image._text)
|
||||
.setTitle(data.title._text)
|
||||
.setDescription(shorten(cleanXML(data.synopsis._text)))
|
||||
.addField('❯ Type',
|
||||
`${data.type._text} - ${data.status._text}`, true)
|
||||
.addField('❯ Episodes',
|
||||
data.episodes._text, true)
|
||||
.addField('❯ Start Date',
|
||||
data.start_date._text !== '0000-00-00' ? data.start_date._text : '???', true)
|
||||
.addField('❯ End Date',
|
||||
data.end_date._text !== '0000-00-00' ? data.end_date._text : '???', true);
|
||||
return msg.embed(embed);
|
||||
} catch (err) {
|
||||
if (err.message === 'Parse Error') return msg.say('Could not find any results.');
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,55 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const snekfetch = require('snekfetch');
|
||||
const { xml2js } = require('xml-js');
|
||||
const { shorten, cleanXML } = require('../../util/Util');
|
||||
const { MAL_LOGIN } = process.env;
|
||||
|
||||
module.exports = class MyAnimeListMangaCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'my-anime-list-manga',
|
||||
aliases: ['mal-manga', 'manga'],
|
||||
group: 'search',
|
||||
memberName: 'my-anime-list-manga',
|
||||
description: 'Searches My Anime List for your query, getting manga results.',
|
||||
clientPermissions: ['EMBED_LINKS'],
|
||||
args: [
|
||||
{
|
||||
key: 'query',
|
||||
prompt: 'What manga would you like to search for?',
|
||||
type: 'string'
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg, { query }) {
|
||||
try {
|
||||
const { text } = await snekfetch
|
||||
.get(`https://${MAL_LOGIN}@myanimelist.net/api/manga/search.xml`)
|
||||
.query({ q: query });
|
||||
const body = xml2js(text, { compact: true }).manga;
|
||||
const data = body.length ? body.entry[0] : body.entry;
|
||||
const embed = new MessageEmbed()
|
||||
.setColor(0x2D54A2)
|
||||
.setAuthor('My Anime List', 'https://i.imgur.com/5rivpMM.png')
|
||||
.setURL(`https://myanimelist.net/manga/${data.id._text}`)
|
||||
.setThumbnail(data.image._text)
|
||||
.setTitle(data.title._text)
|
||||
.setDescription(shorten(cleanXML(data.synopsis._text)))
|
||||
.addField('❯ Type',
|
||||
`${data.type._text} - ${data.status._text}`, true)
|
||||
.addField('❯ Volumes / Chapters',
|
||||
`${parseInt(data.volumes._text, 10) || '???'} / ${parseInt(data.chapters._text, 10) || '???'}`, true)
|
||||
.addField('❯ Start Date',
|
||||
data.start_date._text !== '0000-00-00' ? data.start_date._text : '???', true)
|
||||
.addField('❯ End Date',
|
||||
data.end_date._text !== '0000-00-00' ? data.end_date._text : '???', true);
|
||||
return msg.embed(embed);
|
||||
} catch (err) {
|
||||
if (err.message === 'Parse Error') return msg.say('Could not find any results.');
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
};
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiaobot",
|
||||
"version": "50.0.0",
|
||||
"version": "51.0.0",
|
||||
"description": "Your personal server companion.",
|
||||
"main": "XiaoBot.js",
|
||||
"scripts": {
|
||||
|
||||
@@ -56,6 +56,19 @@ class Util {
|
||||
return obj;
|
||||
}
|
||||
|
||||
static cleanXML(text) {
|
||||
return text
|
||||
.replace(/<br \/>/g, '')
|
||||
.replace(/'|�?39;/g, '\'')
|
||||
.replace(/—/g, '—')
|
||||
.replace(/–/g, '–')
|
||||
.replace(/"|�?34;/g, '"')
|
||||
.replace(/<|�?60;/g, '<')
|
||||
.replace(/>|�?62;/g, '>')
|
||||
.replace(/&|�?38;/g, '&')
|
||||
.replace(/\[i\]|\[\/i\]/g, '*')
|
||||
}
|
||||
|
||||
static greyscale(ctx, x, y, width, height) {
|
||||
const data = ctx.getImageData(x, y, width, height);
|
||||
for (let i = 0; i < data.data.length; i += 4) {
|
||||
|
||||
Reference in New Issue
Block a user