Merge pull request #230 from LINSTCL/config_integrity_check

添加配置文件完整性校验
This commit is contained in:
Rock Chin 2023-03-06 12:35:59 +08:00 committed by GitHub
commit 8af4918048
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

22
main.py
View File

@ -129,13 +129,26 @@ def main(first_time_init=False):
config = importlib.import_module('config')
import pkg.utils.context
pkg.utils.context.set_config(config)
init_runtime_log_file()
sh = reset_logging()
# 配置完整性校验
is_integrity = True
config_template = importlib.import_module('config-template')
for key in dir(config_template):
if not key.startswith("__") and not hasattr(config, key):
setattr(config, key, getattr(config_template, key))
logging.warning("[{}]不存在".format(key))
is_integrity = False
if not is_integrity:
logging.warning("配置文件不完整请依据config-template.py检查config.py")
logging.warning("以上配置已被设为默认值将在5秒后继续启动... ")
time.sleep(5)
import pkg.utils.context
pkg.utils.context.set_config(config)
# 检查是否设置了管理员
if not (hasattr(config, 'admin_qq') and config.admin_qq != 0):
# logging.warning("未设置管理员QQ,管理员权限指令及运行告警将无法使用,如需设置请修改config.py中的admin_qq字段")
@ -182,8 +195,7 @@ def main(first_time_init=False):
# 初始化qq机器人
qqbot = pkg.qqbot.manager.QQBotManager(mirai_http_api_config=config.mirai_http_api_config,
timeout=config.process_message_timeout, retry=config.retry_times,
first_time_init=first_time_init,
pool_num=config.pool_num if hasattr(config, 'pool_num') else 10)
first_time_init=first_time_init, pool_num=config.pool_num)
# 加载插件
import pkg.plugin.host