From e3da6ff7190d469bd1a74d6e90c6106d13ca0ce3 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Wed, 1 Aug 2018 21:24:41 -0400 Subject: [PATCH] Derpibooru Command --- README.md | 5 +++-- commands/search/derpibooru.js | 37 +++++++++++++++++++++++++++++++++++ package.json | 2 +- 3 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 commands/search/derpibooru.js diff --git a/README.md b/README.md index 43c2919c..9790de52 100644 --- a/README.md +++ b/README.md @@ -8,14 +8,14 @@ Xiao is a Discord bot coded in JavaScript with [discord.js](https://discord.js.org/) using the -[Commando](https://github.com/discordjs/Commando) command framework. With nearly +[Commando](https://github.com/discordjs/Commando) command framework. With 300 commands, she is one of the most feature-filled bots out there. ## Invite The bot is no longer available for invite. You can self-host the bot, or use her on the [home server](https://discord.gg/sbMe32W). -## Commands (299) +## Commands (300) ### Utility: * **eval**: Executes JavaScript code. @@ -117,6 +117,7 @@ on the [home server](https://discord.gg/sbMe32W). * **bulbapedia**: Searches Bulbapedia for your query. * **danbooru**: Responds with an image from Danbooru, with optional query. +* **derpibooru**: Responds with an image from Derpibooru. * **deviantart**: Responds with an image from a DeviantArt section, with optional query. * **dictionary**: Defines a word. * **discord-js-docs**: Searches the Discord.js docs for your query. diff --git a/commands/search/derpibooru.js b/commands/search/derpibooru.js new file mode 100644 index 00000000..45e79543 --- /dev/null +++ b/commands/search/derpibooru.js @@ -0,0 +1,37 @@ +const Command = require('../../structures/Command'); +const request = require('node-superfetch'); + +module.exports = class DerpibooruCommand extends Command { + constructor(client) { + super(client, { + name: 'derpibooru', + aliases: ['derpibooru-image'], + group: 'search', + memberName: 'derpibooru', + description: 'Responds with an image from Derpibooru.', + args: [ + { + key: 'query', + prompt: 'What image would you like to search for?', + type: 'string' + } + ] + }); + } + + async run(msg, { query }) { + try { + const search = await request + .get('https://derpibooru.org/search.json') + .query({ + q: query, + random_image: 1 + }); + if (!search.body) return msg.say('Could not find any results.'); + const { body } = await request.get(`https://derpibooru.org/images/${search.body.id}.json`); + return msg.say(`https:${body.representations.full}`); + } catch (err) { + return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } +}; diff --git a/package.json b/package.json index 7761809e..0ef2410a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "85.9.3", + "version": "85.10.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {