From c5e6db79a0b4562476bc39e0439637981f66397c Mon Sep 17 00:00:00 2001 From: profitroll Date: Wed, 26 Oct 2022 13:30:24 +0200 Subject: [PATCH] Debug mode added --- .gitignore | 1 + config_example.json | 1 + modules/utils.py | 13 ++++++++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 90e4a84..2e6303b 100644 --- a/.gitignore +++ b/.gitignore @@ -154,6 +154,7 @@ cython_debug/ # Custom config.json +config_debug.json *.session *.session-journal users diff --git a/config_example.json b/config_example.json index c76be67..03b2c87 100644 --- a/config_example.json +++ b/config_example.json @@ -1,5 +1,6 @@ { "locale": "uk", + "debug": false, "owner": 0, "age_allowed": 0, "birthdays_notify": true, diff --git a/modules/utils.py b/modules/utils.py index 6a761e0..6cf6744 100644 --- a/modules/utils.py +++ b/modules/utils.py @@ -47,6 +47,12 @@ def configSet(key: str, value, *args: str, file: str = "config"): else: filepath = f"data{sep}users{sep}" this_dict = jsonLoad(f"{filepath}{file}.json") + if this_dict["debug"]: + try: + this_dict = jsonLoad("config_debug.json") + file = "config_debug" + except FileNotFoundError: + print("Debug mode is set but config_debug.json is not there! Falling back to config.json", flush=True) string = "this_dict" for arg in args: string += f'["{arg}"]' @@ -71,8 +77,13 @@ def configGet(key: str, *args: str, file: str = "config"): try: this_dict = jsonLoad("config.json") except FileNotFoundError: - print("Config file not found! Copy config_example.json to config.json, configure it and rerun the bot!") + print("Config file not found! Copy config_example.json to config.json, configure it and rerun the bot!", flush=True) exit() + if this_dict["debug"]: + try: + this_dict = jsonLoad("config_debug.json") + except FileNotFoundError: + print("Debug mode is set but config_debug.json is not there! Falling back to config.json", flush=True) else: this_dict = jsonLoad(f"data{sep}users{sep}{file}.json") this_key = this_dict