From 8cb7e39f10f3c9e8388dfe93c040a50073b5183d Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Sat, 8 Dec 2018 12:46:40 +0000 Subject: [PATCH] Add Gelbooru, Danbooru, and Konachan commands --- README.md | 5 ++++- commands/search/danbooru.js | 41 +++++++++++++++++++++++++++++++++++++ commands/search/gelbooru.js | 40 ++++++++++++++++++++++++++++++++++++ commands/search/konachan.js | 37 +++++++++++++++++++++++++++++++++ package.json | 2 +- 5 files changed, 123 insertions(+), 2 deletions(-) create mode 100644 commands/search/danbooru.js create mode 100644 commands/search/gelbooru.js create mode 100644 commands/search/konachan.js diff --git a/README.md b/README.md index a16f2421..561ac74b 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ Xiao is a Discord bot coded in JavaScript with 7. Run `npm i -g pm2` to install PM2. 8. Run `pm2 start Xiao.js --name xiao` to run the bot. -## Commands (333) +## Commands (336) ### Utility: * **eval:** Executes JavaScript code. @@ -160,6 +160,7 @@ Xiao is a Discord bot coded in JavaScript with * **azur-lane:** Responds with information on an Azur Lane ship. * **book:** Searches Google Books for a book. * **bulbapedia:** Searches Bulbapedia for your query. +* **danbooru:** Responds with an image from Danbooru, with optional query. * **define:** Defines a word. * **derpibooru:** Responds with an image from Derpibooru. * **deviantart:** Responds with an image from a DeviantArt section, with optional query. @@ -168,6 +169,7 @@ Xiao is a Discord bot coded in JavaScript with * **esrb:** Searches ESRB for your query. * **flickr:** Searches Flickr for your query. * **forecast:** Responds with the seven-day forecast for a specific location. +* **gelbooru:** Responds with an image from Gelbooru, with optional query. * **giphy:** Searches Giphy for your query. * **github:** Responds with information on a GitHub repository. * **google-autofill:** Responds with a list of the Google Autofill results for a particular query. @@ -181,6 +183,7 @@ Xiao is a Discord bot coded in JavaScript with * **kh-wiki:** Searches the Kingdom Hearts Wiki for your query. * **kickstarter:** Searches Kickstarter for your query. * **know-your-meme:** Searches Know Your Meme for your query. +* **konachan:** Responds with an image from Konachan, with optional query. * **league-of-legends:** Responds with information on a League of Legends champion. * **manga:** Searches AniList for your query, getting manga results. * **map:** Responds with a map of a specific location. diff --git a/commands/search/danbooru.js b/commands/search/danbooru.js new file mode 100644 index 00000000..1a181f67 --- /dev/null +++ b/commands/search/danbooru.js @@ -0,0 +1,41 @@ +const Command = require('../../structures/Command'); +const request = require('node-superfetch'); + +module.exports = class DanbooruCommand extends Command { + constructor(client) { + super(client, { + name: 'danbooru', + group: 'search', + memberName: 'danbooru', + description: 'Responds with an image from Danbooru, with optional query.', + nsfw: true, + args: [ + { + key: 'query', + prompt: 'What image would you like to search for?', + type: 'string', + default: '', + validate: query => { + if (!query.includes(' ')) return true; + return 'Invalid query, please only search for one tag at a time.'; + } + } + ] + }); + } + + async run(msg, { query }) { + try { + const { body } = await request + .get('https://danbooru.donmai.us/posts.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/commands/search/gelbooru.js b/commands/search/gelbooru.js new file mode 100644 index 00000000..97504d75 --- /dev/null +++ b/commands/search/gelbooru.js @@ -0,0 +1,40 @@ +const Command = require('../../structures/Command'); +const request = require('node-superfetch'); + +module.exports = class GelbooruCommand extends Command { + constructor(client) { + super(client, { + name: 'gelbooru', + group: 'search', + memberName: 'gelbooru', + description: 'Responds with an image from Gelbooru, with optional query.', + nsfw: true, + args: [ + { + key: 'query', + prompt: 'What image would you like to search for?', + type: 'string', + default: '' + } + ] + }); + } + + async run(msg, { query }) { + try { + const { body } = await request + .get('https://gelbooru.org/index.php') + .query({ + page: 'dapi', + s: 'post', + q: 'index', + json: 1, + tags: query, + limit: 200 + }); + return msg.say(body[Math.floor(Math.random() * body.length)].file_url); + } catch (err) { + return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } +}; diff --git a/commands/search/konachan.js b/commands/search/konachan.js new file mode 100644 index 00000000..14c6e9b1 --- /dev/null +++ b/commands/search/konachan.js @@ -0,0 +1,37 @@ +const Command = require('../../structures/Command'); +const request = require('node-superfetch'); + +module.exports = class KonachanCommand extends Command { + constructor(client) { + super(client, { + name: 'konachan', + group: 'search', + memberName: 'konachan', + description: 'Responds with an image from Konachan, with optional query.', + nsfw: true, + args: [ + { + key: 'query', + prompt: 'What image would you like to search for?', + type: 'string', + default: '' + } + ] + }); + } + + async run(msg, { query }) { + try { + const { body } = await request + .get('https://konachan.net/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(`https:${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 6705e30f..0012be72 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "98.3.1", + "version": "98.4.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {