From 17d9a4a013c1d377986abe3b6d9f7194dd050498 Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Fri, 23 Mar 2018 21:18:38 +0000 Subject: [PATCH] A fun little command. --- README.md | 3 ++- commands/search/rule34.js | 44 +++++++++++++++++++++++++++++++++++++++ package.json | 2 +- 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 commands/search/rule34.js diff --git a/README.md b/README.md index 3beaf51c..c05bcbfa 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Xiao is a Discord bot coded in JavaScript with 300 commands, she is one of the most feature-filled bots out there, and formerly served over 10,000 servers with a uniquely devoted fanbase. -## Commands (296) +## Commands (297) ### Utility: * **prefix**: Shows or sets the command prefix. @@ -151,6 +151,7 @@ served over 10,000 servers with a uniquely devoted fanbase. * **recipe**: Searches for recipes based on your query. * **rotten-tomatoes**: Searches Rotten Tomatoes for your query. * **rule-of-the-internet**: Responds with a rule of the internet. +* **rule34**: Responds with an image from Rule34, with optional query. * **safebooru**: Responds with an image from Safebooru, with optional query. * **spoopy-link**: Determines if a link is spoopy or not. * **stack-overflow**: Searches Stack Overflow for your query. diff --git a/commands/search/rule34.js b/commands/search/rule34.js new file mode 100644 index 00000000..99ee1696 --- /dev/null +++ b/commands/search/rule34.js @@ -0,0 +1,44 @@ +const Command = require('../../structures/Command'); +const snekfetch = require('snekfetch'); + +module.exports = class Rule34Command extends Command { + constructor(client) { + super(client, { + name: 'rule34', + aliases: ['rule34-image'], + group: 'search', + memberName: 'rule34', + description: 'Responds with an image from Rule34, 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 { text } = await snekfetch + .get('https://rule34.xxx/index.php') + .query({ + page: 'dapi', + s: 'post', + q: 'index', + json: 1, + tags: query, + limit: 200 + }); + if (!text) return msg.say('Could not find any results.'); + const body = JSON.parse(text); + const data = body[Math.floor(Math.random() * body.length)]; + return msg.say(`https://rule34.xxx/images/${data.directory}/${data.image}`); + } catch (err) { + return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } +}; diff --git a/package.json b/package.json index 447696fe..eed24689 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "70.2.0", + "version": "70.3.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {