Files
xiao/commands/other/cleverbot.js
T
Daniel Odendahl Jr 771e1f51f5 Add some stuff
2017-11-03 23:03:22 +00:00

42 lines
966 B
JavaScript

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!`);
}
}
};