Passed
Pull Request — main (#4)
by Bartosz
01:15
created

build.modules.get_settings   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 35
dl 0
loc 41
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A get_settings() 0 16 5
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
    "DB_P": "None"
22
}
23
24
25
@lru_cache()
26
def get_settings(key: str):
27
    """Get the selected key from the settings file"""
28
    try:
29
        with open("server_files/bot_settings.json", "r", encoding="UTF-8") as f:
30
            _json = json.load(f)
31
        return _json[key]
32
    except FileNotFoundError:
33
        with open("server_files/bot_settings.json", "w", encoding="UTF-8") as f:
34
            json.dump(template_json, f, indent=2)
35
        print("No bot_settings.json found. One has been created, please populate it and restart")
36
        exit(1)
37
    except KeyError:
38
        print(f"Incomplete bot_settings.json found\n"
39
              f"Check your file")
40
        exit(1)
41