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

This commit is contained in:
blackfur 2021-01-17 13:41:19 +01:00
parent 8f345cd25b
commit 8510ff5f6a
2 changed files with 9 additions and 6 deletions

2
.gitignore vendored
View file

@ -6,6 +6,6 @@ venv/
# Exclude ChatLogs, DataBases and the API Token # Exclude ChatLogs, DataBases and the API Token
chatlogs/* chatlogs/
db.sqlite3 db.sqlite3
token token

13
run.py
View file

@ -1,3 +1,4 @@
# DO NOT CHANGE THIS
import os import os
import sys import sys
import yaml import yaml
@ -5,7 +6,6 @@ import discord
from chatterbot import ChatBot from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer, ListTrainer from chatterbot.trainers import ChatterBotCorpusTrainer, ListTrainer
# Last Check
# Change this to set the settings # Change this to set the settings
config = {"botname": "Sheepy", config = {"botname": "Sheepy",
"filterpings": True, "filterpings": True,
@ -13,6 +13,7 @@ config = {"botname": "Sheepy",
"trainchannels": [[492412566430154783, 1000], [761462125696385047, 1000]], "trainchannels": [[492412566430154783, 1000], [761462125696385047, 1000]],
"corpus": ["chatterbot.corpus.english"]} "corpus": ["chatterbot.corpus.english"]}
# DO NOT CHANGE THIS
with open("token", "r") as tokenfile: with open("token", "r") as tokenfile:
token = tokenfile.read() token = tokenfile.read()
@ -50,7 +51,7 @@ async def train():
for corpus in config["corpus"]: for corpus in config["corpus"]:
corpustrainer.train(corpus) corpustrainer.train(corpus)
for log in os.listdir("chatlogs"): for log in os.listdir("chatlogs"):
with open(log, "r") as logfile: with open(f"chatlogs/{log}", "r") as logfile:
log = yaml.load(logfile) log = yaml.load(logfile)
listtrainer.train(log) listtrainer.train(log)
@ -65,13 +66,13 @@ async def on_ready():
printhelp() printhelp()
await bot.close() await bot.close()
raise SystemExit(0) raise SystemExit(0)
if arg == "--version" or arg == "-v": elif arg == "--version" or arg == "-v":
printversion() printversion()
await bot.close() await bot.close()
raise SystemExit(0) raise SystemExit(0)
if arg == "--download" or arg == "-d": elif arg == "--download" or arg == "-d":
tasks[0] = True tasks[0] = True
if arg == "--train" or arg == "-t": elif arg == "--train" or arg == "-t":
tasks[1] = True tasks[1] = True
else: else:
print(f"Unexspected {arg}") print(f"Unexspected {arg}")
@ -80,11 +81,13 @@ async def on_ready():
raise SystemExit(1) raise SystemExit(1)
if tasks[0]: if tasks[0]:
await download() await download()
print("Finished download!")
if tasks[1]: if tasks[1]:
os.system("rm db.sqlite3") os.system("rm db.sqlite3")
global chatbot global chatbot
chatbot = ChatBot(config["botname"]) chatbot = ChatBot(config["botname"])
await train() await train()
print("Finished train!")
else: else:
chatbot = ChatBot(config["botname"]) chatbot = ChatBot(config["botname"])