mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-07 06:45:31 +02:00
Manga Command
This commit is contained in:
@@ -30,7 +30,7 @@ module.exports = class GuildInfoCommand extends Command {
|
||||
stripIndents`
|
||||
${moment(msg.guild.createdTimestamp).format('MMMM Do YYYY h:mm:ss A')}
|
||||
${moment.duration(Date.now() - msg.guild.createdTimestamp).format('y[ years], M[ months], w[ weeks, and ]d[ days]')} ago.
|
||||
`, true)
|
||||
`)
|
||||
.addField('Default Channel',
|
||||
msg.guild.defaultChannel, true)
|
||||
.addField('Region',
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const { RichEmbed } = require('discord.js');
|
||||
const snekfetch = require('snekfetch');
|
||||
const { promisify } = require('tsubaki');
|
||||
const xml = promisify(require('xml2js').parseString);
|
||||
const { ANIMELIST_LOGIN } = process.env;
|
||||
|
||||
module.exports = class MangaCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'manga',
|
||||
group: 'search',
|
||||
memberName: 'manga',
|
||||
description: 'Searches My Anime List for a specified manga.',
|
||||
args: [
|
||||
{
|
||||
key: 'query',
|
||||
prompt: 'What manga would you like to search for?',
|
||||
type: 'string'
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg, args) {
|
||||
if (msg.channel.type !== 'dm')
|
||||
if (!msg.channel.permissionsFor(this.client.user).has('EMBED_LINKS'))
|
||||
return msg.say('This Command requires the `Embed Links` Permission.');
|
||||
const { query } = args;
|
||||
try {
|
||||
const { text } = await snekfetch
|
||||
.get(`https://${ANIMELIST_LOGIN}@myanimelist.net/api/manga/search.xml`)
|
||||
.query({
|
||||
q: query
|
||||
});
|
||||
const { anime } = await xml(text);
|
||||
const synopsis = anime.entry[0].synopsis[0].substr(0, 2000)
|
||||
.replace(/(<br \/>)/g, '')
|
||||
.replace(/(')/g, '\'')
|
||||
.replace(/(—)/g, '—')
|
||||
.replace(/(")/g, '"')
|
||||
.replace(/(&)/g, '&');
|
||||
const embed = new RichEmbed()
|
||||
.setColor(0x2D54A2)
|
||||
.setAuthor('My Anime List', 'https://i.imgur.com/R4bmNFz.png')
|
||||
.setURL(`https://myanimelist.net/anime/${anime.entry[0].id[0]}`)
|
||||
.setThumbnail(anime.entry[0].image[0])
|
||||
.setTitle(`${anime.entry[0].title[0]} (English: ${anime.entry[0].english[0] || 'N/A'})`)
|
||||
.setDescription(synopsis)
|
||||
.addField('Type',
|
||||
`${anime.entry[0].type[0]} - ${anime.entry[0].status[0]}`, true)
|
||||
.addField('Volumes / Chapters',
|
||||
`${anime.entry[0].volumes[0]} / ${anime.entry[0].chapters[0]}`, true)
|
||||
.addField('Start Date',
|
||||
anime.entry[0].start_date[0], true)
|
||||
.addField('End Date',
|
||||
anime.entry[0].end_date[0], true);
|
||||
return msg.embed(embed);
|
||||
} catch (err) {
|
||||
return msg.say('Error: No Results.');
|
||||
}
|
||||
}
|
||||
};
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiaobot",
|
||||
"version": "19.5.0",
|
||||
"version": "19.6.0",
|
||||
"description": "A Discord Bot",
|
||||
"main": "shardingmanager.js",
|
||||
"scripts": {
|
||||
|
||||
Reference in New Issue
Block a user