mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-24 14:19:56 +02:00
Bye XML
This commit is contained in:
@@ -1,8 +1,5 @@
|
|||||||
const { Command } = require('discord.js-commando');
|
const { Command } = require('discord.js-commando');
|
||||||
const snekfetch = require('snekfetch');
|
const snekfetch = require('snekfetch');
|
||||||
const { parseString } = require('xml2js');
|
|
||||||
const { promisify } = require('util');
|
|
||||||
const xml = promisify(parseString);
|
|
||||||
|
|
||||||
module.exports = class GelbooruCommand extends Command {
|
module.exports = class GelbooruCommand extends Command {
|
||||||
constructor(client) {
|
constructor(client) {
|
||||||
@@ -26,19 +23,18 @@ module.exports = class GelbooruCommand extends Command {
|
|||||||
|
|
||||||
async run(msg, { query }) {
|
async run(msg, { query }) {
|
||||||
try {
|
try {
|
||||||
const { text } = await snekfetch
|
const { body } = await snekfetch
|
||||||
.get('https://gelbooru.com/index.php')
|
.get('https://gelbooru.com/index.php')
|
||||||
.query({
|
.query({
|
||||||
page: 'dapi',
|
page: 'dapi',
|
||||||
s: 'post',
|
s: 'post',
|
||||||
q: 'index',
|
q: 'index',
|
||||||
|
json: 1,
|
||||||
tags: query,
|
tags: query,
|
||||||
limit: 200
|
limit: 200
|
||||||
});
|
});
|
||||||
const body = await xml(text);
|
if (!body) return msg.say('Could not find any results.');
|
||||||
const data = body.posts.post;
|
return msg.say(body[Math.floor(Math.random() * body.length)].file_url);
|
||||||
if (!data || !data.length) return msg.say('Could not find any results.');
|
|
||||||
return msg.say(data[Math.floor(Math.random() * data.length)].$.file_url);
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
const { Command } = require('discord.js-commando');
|
const { Command } = require('discord.js-commando');
|
||||||
const snekfetch = require('snekfetch');
|
const snekfetch = require('snekfetch');
|
||||||
const { parseString } = require('xml2js');
|
|
||||||
const { promisify } = require('util');
|
|
||||||
const xml = promisify(parseString);
|
|
||||||
|
|
||||||
module.exports = class SafebooruCommand extends Command {
|
module.exports = class SafebooruCommand extends Command {
|
||||||
constructor(client) {
|
constructor(client) {
|
||||||
@@ -25,19 +22,19 @@ module.exports = class SafebooruCommand extends Command {
|
|||||||
|
|
||||||
async run(msg, { query }) {
|
async run(msg, { query }) {
|
||||||
try {
|
try {
|
||||||
const { text } = await snekfetch
|
const { body } = await snekfetch
|
||||||
.get('https://safebooru.org/index.php')
|
.get('https://safebooru.org/index.php')
|
||||||
.query({
|
.query({
|
||||||
page: 'dapi',
|
page: 'dapi',
|
||||||
s: 'post',
|
s: 'post',
|
||||||
q: 'index',
|
q: 'index',
|
||||||
|
json: 1,
|
||||||
tags: query,
|
tags: query,
|
||||||
limit: 200
|
limit: 200
|
||||||
});
|
});
|
||||||
const body = await xml(text);
|
if (!body) return msg.say('Could not find any results.');
|
||||||
const data = body.posts.post;
|
const data = body[Math.floor(Math.random() * body.length)];
|
||||||
if (!data || !data.length) return msg.say('Could not find any results.');
|
return msg.say(`https://safebooru.org/images/${data.directory}/${data.image}`);
|
||||||
return msg.say(`https:${data[Math.floor(Math.random() * data.length)].$.file_url}`);
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user