From 0ba8311ad6af30ae2476b1984e9354ef720332dd Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Tue, 9 May 2017 01:59:39 +0000 Subject: [PATCH] Optional Konachan Query --- commands/randomimg/konachan.js | 19 ++++++++++++++----- package.json | 3 ++- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/commands/randomimg/konachan.js b/commands/randomimg/konachan.js index a072d1f6..7569626c 100644 --- a/commands/randomimg/konachan.js +++ b/commands/randomimg/konachan.js @@ -7,19 +7,28 @@ module.exports = class KonachanCommand extends Command { name: 'konachan', group: 'randomimg', memberName: 'konachan', - description: 'Sends a random (Possibly NSFW!) anime image from Konachan.', - guildOnly: true + description: 'Sends a random (Possibly NSFW!) anime image from Konachan, with optional query.', + guildOnly: true, + args: [ + { + key: 'query', + prompt: 'What would you like to search for?', + type: 'string', + default: '' + } + ] }); } - async run(msg) { + async run(msg, args) { if (!msg.channel.nsfw) return msg.say('This Command can only be used in NSFW Channels.'); if (!msg.channel.permissionsFor(this.client.user).has('ATTACH_FILES')) return msg.say('This Command requires the `Attach Files` Permission.'); + const { query } = args; try { const { body } = await request - .get('https://konachan.net/post.json?tags=order:random&limit=1'); - return msg.channel.send({ files: [`https:${body[0].file_url}`] }) + .get(`https://konachan.net/post.json?tags=${query ? `${query}%20` : ''}order:random&limit=1`); + return msg.channel.send(query ? `Result for ${query}:` : 'Random Image:', { files: [`https:${body[0].file_url}`] }) .catch(err => msg.say(err)); } catch (err) { return msg.say(err); diff --git a/package.json b/package.json index dd29c8e5..dd1d2261 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "18.8.2", + "version": "18.8.3", "description": "A Discord Bot", "main": "shardingmanager.js", "scripts": { @@ -43,6 +43,7 @@ "pg": "^6.1.5", "sequelize": "^3.30.4", "superagent": "^3.5.2", + "uws": "^0.14.5", "zalgolize": "^1.2.4" } }