From 3e0773ee1ea9d380ba9f9dbf606cbbd8a667258a Mon Sep 17 00:00:00 2001 From: Bobloy Date: Thu, 3 May 2018 14:31:56 -0400 Subject: [PATCH] changes --- chatter/chat.py | 25 ++++++++++++++----------- chatter/chatterbot/trainers.py | 2 +- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/chatter/chat.py b/chatter/chat.py index 2b3d8ea..8301411 100644 --- a/chatter/chat.py +++ b/chatter/chat.py @@ -26,7 +26,7 @@ class Chatter: self.chatbot = ChatBot( "ChatterBot", storage_adapter='chatter.chatterbot.storage.SQLStorageAdapter', - database='chatter/database/database.sqlite3' + database='./database.sqlite3' ) self.chatbot.set_trainer(ListTrainer) @@ -95,16 +95,17 @@ class Chatter: async def backup(self, ctx, backupname): """ Backup your training data to a json for later use - :param ctx: - :param backupname: - :return: """ + await ctx.send("Backing up data, this may take a while") + future = await self.loop.run_in_executor(None, self.chatbot.trainer.export_for_training, './{}.json'.format(backupname)) - self.chatbot.trainer.export_for_training('./{}.json'.format(backupname)) - + if future: + await ctx.send("Backup successful!") + else: + await ctx.send("Error occurred :(") @chatter.command() - async def train(self, ctx: commands.Context, channel: discord.TextChannel = None): + async def train(self, ctx: commands.Context, channel: discord.TextChannel): """ Trains the bot based on language in this guild """ @@ -146,7 +147,9 @@ class Chatter: return text = text.replace(to_strip, "", 1) async with channel.typing(): - response = self.chatbot.get_response(text) - if not response: - response = ":thinking:" - await channel.send(response) + future = await self.loop.run_in_executor(None, self.chatbot.get_response, text) + + if future: + await channel.send(str(future)) + else: + await channel.send(':thinking:') diff --git a/chatter/chatterbot/trainers.py b/chatter/chatterbot/trainers.py index 456176c..42ccd47 100644 --- a/chatter/chatterbot/trainers.py +++ b/chatter/chatterbot/trainers.py @@ -85,7 +85,7 @@ class Trainer(object): import json export = {'conversations': self._generate_export_data()} with open(file_path, 'w+') as jsonfile: - json.dump(export, jsonfile, ensure_ascii=False) + json.dump(export, jsonfile, ensure_ascii=True) class ListTrainer(Trainer):