mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-21 05:54:33 +02:00
xml2js
This commit is contained in:
+11
-10
@@ -1,7 +1,8 @@
|
|||||||
const { Command } = require('discord.js-commando');
|
const { Command } = require('discord.js-commando');
|
||||||
const { RichEmbed } = require('discord.js');
|
const { RichEmbed } = require('discord.js');
|
||||||
const request = require('superagent');
|
const request = require('superagent');
|
||||||
const cheerio = require('cheerio');
|
const { promisify } = require('tsubaki');
|
||||||
|
const xml = promisify(require('xml2js').parseString);
|
||||||
const { ANIMELIST_LOGIN } = process.env;
|
const { ANIMELIST_LOGIN } = process.env;
|
||||||
|
|
||||||
module.exports = class AnimeCommand extends Command {
|
module.exports = class AnimeCommand extends Command {
|
||||||
@@ -31,8 +32,8 @@ module.exports = class AnimeCommand extends Command {
|
|||||||
const { text } = await request
|
const { text } = await request
|
||||||
.get(`https://${ANIMELIST_LOGIN}@myanimelist.net/api/anime/search.xml?q=${query}`)
|
.get(`https://${ANIMELIST_LOGIN}@myanimelist.net/api/anime/search.xml?q=${query}`)
|
||||||
.buffer(true);
|
.buffer(true);
|
||||||
const $ = cheerio.load(text, { xmlMode: true });
|
const { anime } = await xml(text);
|
||||||
const synopsis = $('synopsis').first().text().substr(0, 2000)
|
const synopsis = anime.entry[0].synopsis[0].substr(0, 2000)
|
||||||
.replace(/(<br \/>)/g, '')
|
.replace(/(<br \/>)/g, '')
|
||||||
.replace(/(')/g, '\'')
|
.replace(/(')/g, '\'')
|
||||||
.replace(/(—)/g, '—')
|
.replace(/(—)/g, '—')
|
||||||
@@ -41,18 +42,18 @@ module.exports = class AnimeCommand extends Command {
|
|||||||
const embed = new RichEmbed()
|
const embed = new RichEmbed()
|
||||||
.setColor(0x2D54A2)
|
.setColor(0x2D54A2)
|
||||||
.setAuthor('My Anime List', 'https://i.imgur.com/R4bmNFz.png')
|
.setAuthor('My Anime List', 'https://i.imgur.com/R4bmNFz.png')
|
||||||
.setURL(`https://myanimelist.net/anime/${$('id').first().text()}`)
|
.setURL(`https://myanimelist.net/anime/${anime.entry[0].id[0]}`)
|
||||||
.setThumbnail($('image').first().text())
|
.setThumbnail(anime.entry[0].image[0])
|
||||||
.setTitle(`${$('title').first().text()} (English: ${$('english').first().text() || 'N/A'})`)
|
.setTitle(`${anime.entry[0].title[0]} (English: ${anime.entry[0].english[0] || 'N/A'})`)
|
||||||
.setDescription(synopsis)
|
.setDescription(synopsis)
|
||||||
.addField('Type',
|
.addField('Type',
|
||||||
`${$('type').first().text()} - ${$('status').first().text()}`, true)
|
`${anime.entry[0].type[0]} - ${anime.entry[0].status[0]}`, true)
|
||||||
.addField('Episodes',
|
.addField('Episodes',
|
||||||
$('episodes').first().text(), true)
|
anime.entry[0].episodes[0], true)
|
||||||
.addField('Start Date',
|
.addField('Start Date',
|
||||||
$('start_date').first().text(), true)
|
anime.entry[0].start_date[0], true)
|
||||||
.addField('End Date',
|
.addField('End Date',
|
||||||
$('end_date').first().text(), true);
|
anime.entry[0].end_date[0], true);
|
||||||
return msg.embed(embed);
|
return msg.embed(embed);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return msg.say('Error: No Results.');
|
return msg.say('Error: No Results.');
|
||||||
|
|||||||
@@ -47,7 +47,6 @@
|
|||||||
"node-opus": "^0.2.6",
|
"node-opus": "^0.2.6",
|
||||||
"pg": "^6.1.5",
|
"pg": "^6.1.5",
|
||||||
"sequelize": "^3.30.4",
|
"sequelize": "^3.30.4",
|
||||||
"snekfetch": "devsnek/snekfetch",
|
|
||||||
"superagent": "^3.5.2",
|
"superagent": "^3.5.2",
|
||||||
"tsubaki": "^1.1.0",
|
"tsubaki": "^1.1.0",
|
||||||
"xml2js": "^0.4.17",
|
"xml2js": "^0.4.17",
|
||||||
|
|||||||
Reference in New Issue
Block a user