From f36c73b30b10a01df1c0e9d44d38140742362cab Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Sat, 26 Nov 2022 20:18:42 -0500 Subject: [PATCH] Sledgehammer config approach --- BotResources.py | 28 ++++++++++++++++------------ main.py | 4 ++++ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/BotResources.py b/BotResources.py index ea8e993..027cfc6 100644 --- a/BotResources.py +++ b/BotResources.py @@ -53,20 +53,24 @@ def read_config_file(): config = configparser.ConfigParser() config.read('./config.ini') - config_return = { - 'Bot Token': config['Bot_Info']['Token'], - 'Device ID': int(config['Device']['ID']), - 'Device Name': str(config['Device']['Name']), - 'Mention Group': str(config['Bot_Info']['Mention_Group']), - 'Channel ID': int(config['Bot_Info']['Channel_ID']), - 'Handler': str(config['Config']['Handler']) - } + try: + config_return = { + 'Bot Token': config['Bot_Info']['Token'], + 'Device ID': int(config['Device']['ID']), + 'Device Name': str(config['Device']['Name']), + 'Mention Group': str(config['Bot_Info']['Mention_Group']), + 'Channel ID': int(config['Bot_Info']['Channel_ID']), + 'Handler': str(config['Config']['Handler']) + } - LOGGER.debug("Found config options:") - for key in config_return.keys(): - LOGGER.debug(f"\t{key} : {config_return[key]}") + LOGGER.debug("Found config options:") + for key in config_return.keys(): + LOGGER.debug(f"\t{key} : {config_return[key]}") - return config_return + return config_return + except Exception as err: + LOGGER.warning(err) + return None def write_config_file(**kwargs): diff --git a/main.py b/main.py index 88aa9af..00825ed 100644 --- a/main.py +++ b/main.py @@ -39,6 +39,10 @@ def main(**passed_config): config = BotResources.read_config_file() + if not config: + LOGGER.warning("No config file exists, please enter this information now") + BotResources.write_config_file(init=True) + # Overwrite config options if they were passed if len(passed_config.keys()) == 0: for sub in config: