From 3341b7398e88b716d31ab7c5224f466434be4b4d Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Mon, 9 Dec 2019 12:33:34 -0500 Subject: [PATCH] Allow specified users to use cleverbot with just a mention --- .env.example | 1 + commands/other/cleverbot.js | 13 ++++++++++--- package.json | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.env.example b/.env.example index c6f22050..7f852e2f 100644 --- a/.env.example +++ b/.env.example @@ -9,6 +9,7 @@ XIAO_WEBHOOK_TOKEN= POSTER_ID= POSTER_TOKEN= POSTER_TIME= +CLEVERBOT_PATTERN_USERS= # Emoji IDs GOLD_FISH_EMOJI_ID= diff --git a/commands/other/cleverbot.js b/commands/other/cleverbot.js index 1ddf144f..81c974f7 100644 --- a/commands/other/cleverbot.js +++ b/commands/other/cleverbot.js @@ -1,6 +1,7 @@ const Command = require('../../structures/Command'); const request = require('node-superfetch'); -const { CLEVERBOT_KEY } = process.env; +const { CLEVERBOT_KEY, CLEVERBOT_PATTERN_USERS } = process.env; +const allowedPatternUsers = CLEVERBOT_PATTERN_USERS ? CLEVERBOT_PATTERN_USERS.split(',') : []; const blankResponses = ['What?', 'Huh?', 'I don\'t understand.', 'Speak up, please.']; module.exports = class CleverbotCommand extends Command { @@ -23,13 +24,18 @@ module.exports = class CleverbotCommand extends Command { prompt: 'What do you want to say to Cleverbot?', type: 'string' } - ] + ], + patterns: [new RegExp(`^() (.+)`, 'i')] }); this.convos = new Map(); } - async run(msg, { text }) { + async run(msg, { text }, fromPattern) { + if (fromPattern) { + if (!allowedPatternUsers.includes(msg.author.id)) return null; + text = msg.patternMatches[2]; + } try { const convo = this.convos.get(msg.channel.id); const { body } = await request @@ -44,6 +50,7 @@ module.exports = class CleverbotCommand extends Command { this.convos.set(msg.channel.id, { cs: body.cs, timeout }); return msg.reply(body.output || blankResponses[Math.floor(Math.random() * blankResponses.length)]); } catch (err) { + if (fromPattern) return null; return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); } } diff --git a/package.json b/package.json index c71e1539..4d5feb2f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "109.2.1", + "version": "109.2.2", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {