-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
66 lines (52 loc) · 1.84 KB
/
Copy pathconfig.py
File metadata and controls
66 lines (52 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import os
import json
from typing import Dict, Any, List
class Config:
def __init__(self, config_file: str = "Config.json"):
self.config_file = config_file
self._config_data = {}
self.load_config()
def load_config(self) -> None:
try:
with open(self.config_file, "r") as file:
self._config_data = json.load(file)
except FileNotFoundError:
print(
f"Config file {self.config_file} not found. Using default configuration."
)
self._config_data = self._get_default_config()
except json.JSONDecodeError:
print(f"Invalid JSON in {self.config_file}. Using default configuration.")
self._config_data = self._get_default_config()
def _get_default_config(self) -> Dict[str, Any]:
return {
"trade_log": [],
"rand_channels": [],
"trade_channels": [],
"WEBHOOK_URL": "",
}
def save_config(self) -> None:
with open(self.config_file, "w") as file:
json.dump(self._config_data, file, indent=4)
@property
def trade_log(self) -> List[int]:
return self._config_data.get("trade_log", [])
@property
def rand_channels(self) -> List[int]:
return self._config_data.get("rand_channels", [])
@property
def trade_channels(self) -> List[int]:
return self._config_data.get("trade_channels", [])
@property
def admin_uids(self) -> List[int]:
return self._config_data.get("admin_uids", [])
@property
def webhook_url(self) -> str:
return self._config_data.get("WEBHOOK_URL", "")
@property
def bot_token(self) -> str:
return os.getenv("BOT_TOKEN", "")
@property
def admin_user_id(self) -> int:
return 988118054456152084
config = Config()