Store the messages for future conversation

Signed-off-by: loicbersier <loic.bersier1@gmail.com>
This commit is contained in:
loicbersier 2020-05-11 20:58:28 +02:00
parent 9fc87f42be
commit bdac7fc268

View file

@ -1,5 +1,6 @@
const { Command } = require('discord-akairo'); const { Command } = require('discord-akairo');
const cleverbot = require('cleverbot-free'); const cleverbot = require('cleverbot-free');
let conversation = {};
class CleverBotCommand extends Command { class CleverBotCommand extends Command {
constructor() { constructor() {
@ -19,16 +20,32 @@ class CleverBotCommand extends Command {
], ],
description: { description: {
content: 'Talk to cleverbot!', content: 'Talk to cleverbot!',
usage: '', usage: '[message]',
examples: [''] examples: ['Hello']
} }
}); });
} }
async exec(message, args) { async exec(message, args) {
cleverbot(args.message).then(response => { let loadingmsg = await message.channel.send('Processing <a:loadingmin:527579785212329984>');
return message.channel.send(response); if (!conversation[message.guild.id]) conversation[message.guild.id] = [];
});
if (!conversation[0]) {
cleverbot(args.message).then(response => {
conversation[message.guild.id].push(args.message);
conversation[message.guild.id].push(response);
return message.channel.send(response);
});
} else {
cleverbot(args.message, conversation[message.guild.id]).then(response => {
conversation[message.guild.id].push(args.message);
conversation[message.guild.id].push(response);
return message.channel.send(response);
});
}
console.log(conversation);
loadingmsg.delete();
} }
} }
module.exports = CleverBotCommand; module.exports = CleverBotCommand;