From 771e1f51f503e4ca8f684cd63d87e7bd93610ba2 Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Fri, 3 Nov 2017 23:03:22 +0000 Subject: [PATCH] Add some stuff --- commands/other/cleverbot.js | 41 +++++++++++++++++++++++++++++++++++ commands/text-edit/webhook.js | 34 +++++++++++++++++++++++++++++ package.json | 2 +- 3 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 commands/other/cleverbot.js create mode 100644 commands/text-edit/webhook.js diff --git a/commands/other/cleverbot.js b/commands/other/cleverbot.js new file mode 100644 index 00000000..6bd91e82 --- /dev/null +++ b/commands/other/cleverbot.js @@ -0,0 +1,41 @@ +const { Command } = require('discord.js-commando'); +const snekfetch = require('snekfetch'); +const { CLEVERBOT_KEY } = process.env; + +module.exports = class CleverbotCommand extends Command { + constructor(client) { + super(client, { + name: 'cleverbot', + aliases: ['clevs'], + group: 'other', + memberName: 'cleverbot', + description: 'Talk to Cleverbot!', + ownerOnly: true, + args: [ + { + key: 'message', + prompt: 'What do you want to say to Cleverbot?', + type: 'string' + } + ] + }); + + this.convos = new Map(); + } + + async run(msg, { message }) { + try { + const { body } = await snekfetch + .get('https://www.cleverbot.com/getreply') + .query({ + key: CLEVERBOT_KEY, + cs: this.convos.get(msg.channel.id), + input: message + }); + this.convos.set(msg.channel.id, body.cs); + return msg.reply(body.output); + } catch (err) { + return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } +}; diff --git a/commands/text-edit/webhook.js b/commands/text-edit/webhook.js new file mode 100644 index 00000000..d26ea79e --- /dev/null +++ b/commands/text-edit/webhook.js @@ -0,0 +1,34 @@ +const { Command } = require('discord.js-commando'); +const snekfetch = require('snekfetch'); +const { WEBHOOK_URL } = process.env; + +module.exports = class WebhookCommand extends Command { + constructor(client) { + super(client, { + name: 'webhook', + aliases: ['rin', 'rin-say'], + group: 'text-edit', + memberName: 'webhook', + description: 'Posts a message to the webhook defined in your `process.env`.', + ownerOnly: true, + clientPermissions: ['MANAGE_MESSAGES'], + args: [ + { + key: 'content', + prompt: 'What text would you like the webhook to say?', + type: 'string' + } + ] + }); + } + + async run(msg, { content }) { + if (msg.channel.type === 'text') await msg.delete(); + try { + await snekfetch.post(WEBHOOK_URL).send({ content }); + return null; + } catch (err) { + return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } +}; diff --git a/package.json b/package.json index 85624d41..f24df4da 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "51.3.3", + "version": "51.4.0", "description": "Your personal server companion.", "main": "XiaoBot.js", "scripts": {