diff --git a/core.py b/core.py index 808d6a4..dec6d04 100644 --- a/core.py +++ b/core.py @@ -42,8 +42,8 @@ def main(): # Copy the template file to the config file user_cfg_file.write(template_cfg_file.read()) - print("A config file has been created in config/config.toml." - " Edit it with your configuration, then restart this script.") + log.fatal("A config file has been created in config/config.toml." + " Customize it, then restart greed!") exit(1) # Compare the template config with the user-made one @@ -52,8 +52,10 @@ def main(): template_cfg = nuconfig.NuConfig(template_cfg_file) user_cfg = nuconfig.NuConfig(user_cfg_file) if not template_cfg.cmplog(user_cfg): - log.fatal("Invalid configuration, refusing to start.") + log.fatal("There were errors while parsing the config.toml file. Please fix them and restart greed!") exit(2) + else: + log.debug("Configuration parsed successfully!") # Finish logging setup logging.root.setLevel(user_cfg["Logging"]["level"]) @@ -109,9 +111,10 @@ def main(): # Main loop of the program while True: # Get a new batch of 100 updates and mark the last 100 parsed as read - log.debug("Getting updates from Telegram") + update_timeout = user_cfg["Telegram"]["long_polling_timeout"] + log.debug(f"Getting updates from Telegram with a timeout of {update_timeout} seconds") updates = bot.get_updates(offset=next_update, - timeout=int(user_cfg["Telegram"]["long_polling_timeout"])) + timeout=update_timeout) # Parse all the updates for update in updates: # If the update is a message... diff --git a/nuconfig.py b/nuconfig.py index 24d655a..e77cca8 100644 --- a/nuconfig.py +++ b/nuconfig.py @@ -25,12 +25,12 @@ class NuConfig: def __cmplog_log(compare_report: CompareReport, root: str = "") -> None: """The recursive portion of :meth:`.cmplog`.""" for item in compare_report.get("__missing__", []): - log.error(f"Missing config key: {root}{item}") + log.error(f"Missing key: {root}{item}") for item in compare_report.get("__invalid__", []): - log.error(f"Invalid config key: {root}{item}") + log.error(f"Key has an invalid type: {root}{item}") - for key, value in compare_report: + for key, value in compare_report.items(): if key == "__missing__" or key == "__invalid__": continue NuConfig.__cmplog_log(value, root=f"{root}{key}.")