From bdac7fc268288528d33a1921ebd0127028710437 Mon Sep 17 00:00:00 2001 From: loicbersier Date: Mon, 11 May 2020 20:58:28 +0200 Subject: [PATCH] Store the messages for future conversation Signed-off-by: loicbersier --- commands/fun/cleverbot.js | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/commands/fun/cleverbot.js b/commands/fun/cleverbot.js index 4e18d72f..81212f82 100644 --- a/commands/fun/cleverbot.js +++ b/commands/fun/cleverbot.js @@ -1,5 +1,6 @@ const { Command } = require('discord-akairo'); const cleverbot = require('cleverbot-free'); +let conversation = {}; class CleverBotCommand extends Command { constructor() { @@ -19,16 +20,32 @@ class CleverBotCommand extends Command { ], description: { content: 'Talk to cleverbot!', - usage: '', - examples: [''] + usage: '[message]', + examples: ['Hello'] } }); } async exec(message, args) { - cleverbot(args.message).then(response => { - return message.channel.send(response); - }); + let loadingmsg = await message.channel.send('Processing '); + 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; \ No newline at end of file