Allow specified users to use cleverbot with just a mention

This commit is contained in:
Dragon Fire
2019-12-09 12:33:34 -05:00
parent b88206722f
commit 3341b7398e
3 changed files with 12 additions and 4 deletions
+1
View File
@@ -9,6 +9,7 @@ XIAO_WEBHOOK_TOKEN=
POSTER_ID=
POSTER_TOKEN=
POSTER_TIME=
CLEVERBOT_PATTERN_USERS=
# Emoji IDs
GOLD_FISH_EMOJI_ID=
+10 -3
View File
@@ -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(`^(<!?@${client.id}>) (.+)`, '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!`);
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "109.2.1",
"version": "109.2.2",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {