From 8510ff5f6adcaf34105f601ccf489987c73bcbbe Mon Sep 17 00:00:00 2001 From: blackfur <64478051+theblackfurguy@users.noreply.github.com> Date: Sun, 17 Jan 2021 13:41:19 +0100 Subject: [PATCH] Fixed various issues including --download option not getting recognised and train function failing on reading the logs + Added Warning comments at the code + Added Info when the Bot finishes a task such as training or downloading --- .gitignore | 2 +- run.py | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 5da55af..c95bdc2 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,6 @@ venv/ # Exclude ChatLogs, DataBases and the API Token -chatlogs/* +chatlogs/ db.sqlite3 token \ No newline at end of file diff --git a/run.py b/run.py index 2e0c3ca..088d8fe 100644 --- a/run.py +++ b/run.py @@ -1,3 +1,4 @@ +# DO NOT CHANGE THIS import os import sys import yaml @@ -5,7 +6,6 @@ import discord from chatterbot import ChatBot from chatterbot.trainers import ChatterBotCorpusTrainer, ListTrainer -# Last Check # Change this to set the settings config = {"botname": "Sheepy", "filterpings": True, @@ -13,6 +13,7 @@ config = {"botname": "Sheepy", "trainchannels": [[492412566430154783, 1000], [761462125696385047, 1000]], "corpus": ["chatterbot.corpus.english"]} +# DO NOT CHANGE THIS with open("token", "r") as tokenfile: token = tokenfile.read() @@ -50,7 +51,7 @@ async def train(): for corpus in config["corpus"]: corpustrainer.train(corpus) for log in os.listdir("chatlogs"): - with open(log, "r") as logfile: + with open(f"chatlogs/{log}", "r") as logfile: log = yaml.load(logfile) listtrainer.train(log) @@ -65,13 +66,13 @@ async def on_ready(): printhelp() await bot.close() raise SystemExit(0) - if arg == "--version" or arg == "-v": + elif arg == "--version" or arg == "-v": printversion() await bot.close() raise SystemExit(0) - if arg == "--download" or arg == "-d": + elif arg == "--download" or arg == "-d": tasks[0] = True - if arg == "--train" or arg == "-t": + elif arg == "--train" or arg == "-t": tasks[1] = True else: print(f"Unexspected {arg}") @@ -80,11 +81,13 @@ async def on_ready(): raise SystemExit(1) if tasks[0]: await download() + print("Finished download!") if tasks[1]: os.system("rm db.sqlite3") global chatbot chatbot = ChatBot(config["botname"]) await train() + print("Finished train!") else: chatbot = ChatBot(config["botname"])