From f4ec5cd4c89ce49e0695a3d3cc23d32d8670e1ef Mon Sep 17 00:00:00 2001 From: BuildTools Date: Tue, 12 Jan 2021 20:24:06 +0100 Subject: [PATCH] Added Config, Argument Parser and Download Function --- .gitignore | 5 +---- run.py | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 61 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 464e7f6..48a69bb 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,4 @@ .idea # Exclude VENV -/venv/ - -# Exclude Config Files -token \ No newline at end of file +/venv/ \ No newline at end of file diff --git a/run.py b/run.py index 98c9ef5..6941dc5 100644 --- a/run.py +++ b/run.py @@ -1,9 +1,67 @@ +import os +import sys +import yaml import discord +from chatterbot import ChatBot +from chatterbot.trainers import ChatterBotCorpusTrainer, ListTrainer -file = open("TOKEN", "r") +config = {"botname": "Sheepy", + "filterpings": True, + "usechannels": [717758904527880253, 772839872557088769, 773980809471197235], + "trainchannels": [[492412566430154783, 1000], [761462125696385047, 1000]], + "corpus": ["chatterbot.corpus.english", "chatterbot.corpus.uswest"], + "token": "NzU2NTgxNjQ0NTY3MTgzMzcw.X2T7kA.J7RthGGYMjgE_ZreLrGo2A3tCvg"} + +file = open("token", "r") token = file.read() file.close() bot = discord.Client() +chatbot = ChatBot(config["botname"]) -bot.run(token) \ No newline at end of file +tasks = [False, False] + + +def printhelp(): + print("Help lol") + + +def printversion(): + print("Somer Version") + + +async def download(): + for trainchannel in config["trainchannels"]: + channel = await bot.fetch_channel(trainchannel[0]) + counter = 0 + messages = [None] * trainchannel[1] + async for message in channel.history(limit=trainchannel[1]): + messages[counter] = message.content + counter += 1 + messages.reverse() + + +@bot.event +async def on_ready(): + print("Logged in!") + args = sys.argv + for arg in args: + if arg == "--help" or "-?": + printhelp() + await bot.close() + if arg == "--version" or "-v": + printversion() + await bot.close() + if arg == "--download" or "-d": + tasks[0] = True + if arg == "--train" or "-t": + tasks[1] = True + else: + print(f"Unexspected {arg}") + printhelp() + await bot.close() + if tasks[0]: + await download() + + +bot.run(token)