2022-04-14 07:18:45 +00:00
|
|
|
import os
|
|
|
|
|
2022-06-09 07:12:06 +00:00
|
|
|
import ujson
|
|
|
|
|
2022-04-14 07:18:45 +00:00
|
|
|
|
2022-06-09 11:55:23 +00:00
|
|
|
class Config:
|
2022-04-14 07:18:45 +00:00
|
|
|
def __init__(self):
|
|
|
|
project_path = os.path.dirname(__file__)
|
|
|
|
config_file = os.path.join(project_path, './config', 'config.json')
|
|
|
|
if not os.path.exists(config_file):
|
|
|
|
config_file = os.path.join(project_path, './config', 'config.example.json')
|
|
|
|
|
|
|
|
with open(config_file, 'r', encoding='utf-8') as f:
|
|
|
|
self._config_json: dict = ujson.load(f)
|
|
|
|
|
2022-05-28 12:32:09 +00:00
|
|
|
self.DEBUG = self.get_config("debug")
|
2022-06-27 15:40:32 +00:00
|
|
|
if not isinstance(self.DEBUG, bool):
|
2022-05-28 12:32:09 +00:00
|
|
|
self.DEBUG = False
|
|
|
|
self.ADMINISTRATORS = self.get_config("administrators")
|
|
|
|
self.MYSQL = self.get_config("mysql")
|
2022-06-09 12:04:38 +00:00
|
|
|
self.REDIS = self.get_config("redis")
|
2022-05-28 12:32:09 +00:00
|
|
|
self.TELEGRAM = self.get_config("telegram")
|
|
|
|
self.FUNCTION = self.get_config("function")
|
2022-04-14 07:18:45 +00:00
|
|
|
|
|
|
|
def get_config(self, name: str):
|
2022-06-08 08:06:36 +00:00
|
|
|
return self._config_json.get(name, {})
|
2022-04-14 07:18:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
config = Config()
|