Add initial code

This commit is contained in:
James H
2021-11-29 23:13:52 +00:00
parent cffc46bd45
commit 0f3416c11b
8 changed files with 200 additions and 0 deletions

35
src/main.py Normal file
View File

@@ -0,0 +1,35 @@
import json
from core.bot import Bot
def main():
try:
with open("config.json", "rt") as config_file:
config = json.load(config_file)
except OSError as e:
print(f"Could not open config.json! Error: {e.strerror}")
return
except Exception as e:
print(f"Error loading config. Error: {e}")
return
# Load token from token file if not in JSON config
if config["token"] == "":
try:
with open("token.txt", "rt") as token_file:
config["token"] = token_file.readline()
except OSError as e:
print(f"Could not open token.txt! Error: {e.strerror}")
return
try:
bot = Bot()
bot.load_config(config)
bot.run(config["token"])
except Exception as e:
print(f"Exception running bot! Error: {e}")
return
if __name__ == "__main__":
main()