From efd035fce512be26b4012423afe82007e321cad1 Mon Sep 17 00:00:00 2001 From: Myned Date: Fri, 13 Oct 2017 23:38:27 -0400 Subject: [PATCH] Moved config file creation and loading into utils --- src/main/utils/utils.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/utils/utils.py b/src/main/utils/utils.py index debc16a..550d7d9 100644 --- a/src/main/utils/utils.py +++ b/src/main/utils/utils.py @@ -30,8 +30,16 @@ def dump(obj, filename): tasks = setdefault('./cogs/tasks.pkl', {}) -with open('config.json') as infile: - config = json.load(infile) +try: + with open('config.json') as infile: + config = json.load(infile) + print('\"config.json\" loaded.') +except FileNotFoundError: + with open('config.json', 'w') as outfile: + json.dump({'client_id': 0, 'listed_ids': [0], 'owner_id': 0, 'permissions': 126016, 'prefix': ',', + 'shutdown_channel': 0, 'startup_channel': 0, 'token': 'str'}, outfile, indent=4, sort_keys=True) + raise FileNotFoundError( + 'Config file not found: \"config.json\" created with abstract values. Restart \"run.py\" with correct values.') async def clear(obj, interval=10 * 60, replace=None):