diff --git a/XiaoBot.js b/XiaoBot.js index d660c32f..029658ec 100644 --- a/XiaoBot.js +++ b/XiaoBot.js @@ -76,24 +76,6 @@ client.on('message', async (msg) => { if (msg.channel.permissionsFor(client.user).has('MANAGE_MESSAGES')) msg.delete(); else msg.channel.send('Message could not be deleted, missing the `Manage Messages` permission.'); return msg.reply('Invites are prohibited from being posted here.'); - } else - if (msg.isMentioned(client.user)) { - if (msg.author.bot) return; - if (msg.channel.type !== 'dm') { - if (!msg.channel.permissionsFor(client.user).has('SEND_MESSAGES')) return; - const role = msg.guild.settings.get('singleRole'); - if (role && !msg.member.roles.has(role)) return; - } - msg.channel.startTyping(); - const message = msg.content.replace(client.mentionRegex, ''); - try { - const { response } = await client.cleverbot.ask(message); - return msg.reply(response) - .then(() => msg.channel.stopTyping()); - } catch (err) { - return msg.reply(`${err.name}: ${err.message}`) - .then(() => msg.channel.stopTyping()); - } } else return; }); diff --git a/commands/random/cleverbot.js b/commands/random/cleverbot.js new file mode 100644 index 00000000..875f8efe --- /dev/null +++ b/commands/random/cleverbot.js @@ -0,0 +1,41 @@ +const { Command } = require('discord.js-commando'); +const Cleverbot = require('cleverio'); +const { CLEVS_KEY, CLEVS_USER, CLEVS_NICK } = process.env; + +module.exports = class CleverbotCommand extends Command { + constructor(client) { + super(client, { + name: 'cleverbot', + aliases: ['clevs', 'chat'], + group: 'random', + memberName: 'cleverbot', + description: 'Talk to Cleverbot!', + args: [ + { + key: 'text', + prompt: 'What do you want to say to Cleverbot?', + type: 'string' + } + ] + }); + + this.clevs = new Cleverbot({ + key: CLEVS_KEY, + user: CLEVS_USER, + nick: CLEVS_NICK + }); + this.clevs.create().then(res => console.log(res)); + } + + async run(msg, args) { + const { text } = args; + msg.channel.startTyping(); + try { + const { response } = await this.clevs.ask(text); + return msg.reply(response) + .then(() => msg.channel.stopTyping()); + } catch (err) { + return msg.say(`${err.name}: ${err.message}`); + } + } +}; diff --git a/structures/CommandoClient.js b/structures/CommandoClient.js index b47ecf75..3b7fe81d 100644 --- a/structures/CommandoClient.js +++ b/structures/CommandoClient.js @@ -1,24 +1,12 @@ const { Client } = require('discord.js-commando'); const Database = require('./PostgreSQL'); -const Cleverbot = require('cleverio'); -const { CLEVS_KEY, CLEVS_USER, CLEVS_NICK } = process.env; class CommandoClient extends Client { constructor(options) { super(options); this.database = Database.db; - this.cleverbot = new Cleverbot({ - key: CLEVS_KEY, - user: CLEVS_USER, - nick: CLEVS_NICK - }); Database.start(); - this.cleverbot.create(); - } - - get mentionRegex() { - return new RegExp(``, 'g'); } }