Safebooru

This commit is contained in:
Daniel Odendahl Jr
2017-08-12 05:03:54 +00:00
parent ee02963411
commit 3ccc5d779a
2 changed files with 45 additions and 1 deletions
+44
View File
@@ -0,0 +1,44 @@
const Command = require('../../structures/Command');
const { stripIndents } = require('common-tags');
const snekfetch = require('snekfetch');
const { promisifyAll } = require('tsubaki');
const xml = promisifyAll(require('xml2js'));
module.exports = class SafebooruCommand extends Command {
constructor(client) {
super(client, {
name: 'safebooru',
group: 'random-img',
memberName: 'safebooru',
description: 'Searches Safebooru with optional query.',
nsfw: true,
args: [
{
key: 'query',
prompt: 'What would you like to search for?',
type: 'string',
default: ''
}
]
});
}
async run(msg, args) {
const { query } = args;
const { text } = await snekfetch
.get('http://safebooru.org/index.php')
.query({
page: 'dapi',
s: 'post',
q: 'index',
tags: query,
limit: 200
});
const { posts } = await xml.parseStringAsync(text);
if (posts.$.count === '0') return msg.say('No Results.');
return msg.say(stripIndents`
${query ? `Result for ${query}:` : 'Random Image:'}
http:${posts.post[Math.floor(Math.random() * posts.post.length)].$.file_url}
`);
}
};
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiaobot",
"version": "29.1.7",
"version": "29.2.0",
"description": "Your personal server companion.",
"main": "Shard.js",
"scripts": {