|
1
|
|
|
import json |
|
2
|
|
|
from functools import lru_cache |
|
3
|
|
|
|
|
4
|
|
|
template_json = { |
|
5
|
|
|
"token": "None", |
|
6
|
|
|
"git_token": "None", |
|
7
|
|
|
"guild": [881161915689209936], |
|
8
|
|
|
"ADMIN": "None", |
|
9
|
|
|
"MOD_ROLES": [], |
|
10
|
|
|
"CH_ROLE_REQUEST": "None", |
|
11
|
|
|
"CH_TOTAL_MEMBERS": "None", |
|
12
|
|
|
"CH_NIGHTMARE_KILLED": "None", |
|
13
|
|
|
"CH_LEADERBOARDS": "None", |
|
14
|
|
|
"CH_TEMP": "None", |
|
15
|
|
|
"CH_COMMON": "None", |
|
16
|
|
|
"CH_LOGS": "None", |
|
17
|
|
|
"CH_VOICE_CHAT": "None", |
|
18
|
|
|
"CH_DISCUSSION_EN": "None", |
|
19
|
|
|
"CAT_SPOTTING": "None", |
|
20
|
|
|
"EXCEL_ID": "None" |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
|
|
24
|
|
View Code Duplication |
@lru_cache() |
|
25
|
|
|
def get_settings(key: str): |
|
26
|
|
|
"""Get the selected key from the settings file""" |
|
27
|
|
|
try: |
|
28
|
|
|
with open("json_files/bot_settings.json", "r", encoding="UTF-8") as f: |
|
29
|
|
|
_json = json.load(f) |
|
30
|
|
|
return _json[key] |
|
31
|
|
|
except FileNotFoundError: |
|
32
|
|
|
with open("json_files/bot_settings.json", "w", encoding="UTF-8") as f: |
|
33
|
|
|
json.dump(template_json, f, indent=2) |
|
34
|
|
|
print("No bot_settings.json found. One has been created, please populate it and restart") |
|
35
|
|
|
exit(1) |
|
36
|
|
|
except KeyError: |
|
37
|
|
|
print(f"Incomplete bot_settings.json found,") |
|
38
|
|
|
print("Adding missing keys to bot_settings.json...") |
|
39
|
|
|
with open("json_files/bot_settings.json", "r+", encoding="UTF-8") as f: |
|
40
|
|
|
_json = json.load(f) |
|
41
|
|
|
for key in template_json.keys(): |
|
42
|
|
|
if key not in _json.keys(): |
|
43
|
|
|
_json[key] = template_json[key] |
|
44
|
|
|
print(f"Added {key}") |
|
45
|
|
|
f.truncate(0) |
|
46
|
|
|
f.seek(0) |
|
47
|
|
|
json.dump(_json, f, indent=2) |
|
48
|
|
|
exit(1) |
|
49
|
|
|
|