diff --git a/commands/search/sakugabooru.js b/commands/search/sakugabooru.js new file mode 100644 index 00000000..a92d853d --- /dev/null +++ b/commands/search/sakugabooru.js @@ -0,0 +1,45 @@ +const Command = require('../../structures/Command'); +const request = require('node-superfetch'); + +module.exports = class SakugabooruCommand extends Command { + constructor(client) { + super(client, { + name: 'sakugabooru', + aliases: ['sakuga'], + group: 'search', + memberName: 'sakugabooru', + description: 'Responds with an image from Sakugabooru, with optional query.', + nsfw: true, + credit: [ + { + name: 'Danbooru', + url: 'https://danbooru.donmai.us/', + reason: 'API' + } + ], + args: [ + { + key: 'query', + prompt: 'What would you like to search for?', + type: 'string', + default: '' + } + ] + }); + } + + async run(msg, { query }) { + try { + const { body } = await request + .get('https://www.sakugabooru.com/post.json') + .query({ + tags: `${query} order:random`, + limit: 1 + }); + if (!body.length || !body[0].file_url) return msg.say('Could not find any results.'); + return msg.say(body[0].file_url); + } catch (err) { + return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } +}; diff --git a/package.json b/package.json index d78f87f3..6fff8c32 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "132.4.0", + "version": "132.5.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {