PaiGram/config.py
luoshuijs 63d71262fe
添加 utils 模块
添加 utils 模块
移除 job_queue 模块
修改获取配置文件信息函数
重构部分类以及函数
2022-06-09 23:35:31 +08:00

30 lines
914 B
Python

import os
import ujson
class Config:
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)
self.DEBUG = self.get_config("debug")
if type(self.DEBUG) != bool:
self.DEBUG = False
self.ADMINISTRATORS = self.get_config("administrators")
self.MYSQL = self.get_config("mysql")
self.REDIS = self.get_config("redis")
self.TELEGRAM = self.get_config("telegram")
self.FUNCTION = self.get_config("function")
def get_config(self, name: str):
return self._config_json.get(name, {})
config = Config()