Debug mode added

This commit is contained in:
Profitroll 2022-10-26 13:30:24 +02:00
parent de0df8f0f6
commit c5e6db79a0
3 changed files with 14 additions and 1 deletions

1
.gitignore vendored
View File

@ -154,6 +154,7 @@ cython_debug/
# Custom # Custom
config.json config.json
config_debug.json
*.session *.session
*.session-journal *.session-journal
users users

View File

@ -1,5 +1,6 @@
{ {
"locale": "uk", "locale": "uk",
"debug": false,
"owner": 0, "owner": 0,
"age_allowed": 0, "age_allowed": 0,
"birthdays_notify": true, "birthdays_notify": true,

View File

@ -47,6 +47,12 @@ def configSet(key: str, value, *args: str, file: str = "config"):
else: else:
filepath = f"data{sep}users{sep}" filepath = f"data{sep}users{sep}"
this_dict = jsonLoad(f"{filepath}{file}.json") 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" string = "this_dict"
for arg in args: for arg in args:
string += f'["{arg}"]' string += f'["{arg}"]'
@ -71,8 +77,13 @@ def configGet(key: str, *args: str, file: str = "config"):
try: try:
this_dict = jsonLoad("config.json") this_dict = jsonLoad("config.json")
except FileNotFoundError: 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() 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: else:
this_dict = jsonLoad(f"data{sep}users{sep}{file}.json") this_dict = jsonLoad(f"data{sep}users{sep}{file}.json")
this_key = this_dict this_key = this_dict