mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-08 06:46:02 +00:00
refactor: 重构会话封禁功能处理逻辑
This commit is contained in:
@@ -28,6 +28,9 @@ class Application:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
async def initialize(self):
|
||||
await self.im_mgr.initialize()
|
||||
|
||||
async def run(self):
|
||||
# TODO make it async
|
||||
plugin_host.initialize_plugins()
|
||||
|
||||
@@ -50,7 +50,10 @@ async def make_app() -> app.Application:
|
||||
# 生成标识符
|
||||
identifier.init()
|
||||
|
||||
cfg_mgr = await config.load_config()
|
||||
cfg_mgr = await config.load_python_module_config(
|
||||
"config.py",
|
||||
"config-template.py"
|
||||
)
|
||||
context.set_config_manager(cfg_mgr)
|
||||
cfg = cfg_mgr.data
|
||||
|
||||
@@ -63,7 +66,10 @@ async def make_app() -> app.Application:
|
||||
if overrided:
|
||||
qcg_logger.info("以下配置项已使用 override.json 覆盖:" + ",".join(overrided))
|
||||
|
||||
tips_mgr = await config.load_tips()
|
||||
tips_mgr = await config.load_python_module_config(
|
||||
"tips.py",
|
||||
"tips-custom-template.py"
|
||||
)
|
||||
|
||||
# 初始化文字转图片
|
||||
from pkg.utils import text2img
|
||||
@@ -121,4 +127,5 @@ async def make_app() -> app.Application:
|
||||
|
||||
async def main():
|
||||
app_inst = await make_app()
|
||||
await app_inst.initialize()
|
||||
await app_inst.run()
|
||||
|
||||
@@ -4,11 +4,11 @@ from ..config import manager as config_mgr
|
||||
from ..config.impls import pymodule
|
||||
|
||||
|
||||
async def load_config() -> config_mgr.ConfigManager:
|
||||
"""加载配置文件"""
|
||||
async def load_python_module_config(config_name: str, template_name: str) -> config_mgr.ConfigManager:
|
||||
"""加载Python模块配置文件"""
|
||||
cfg_inst = pymodule.PythonModuleConfigFile(
|
||||
"config.py",
|
||||
"config-template.py"
|
||||
config_name,
|
||||
template_name
|
||||
)
|
||||
|
||||
cfg_mgr = config_mgr.ConfigManager(cfg_inst)
|
||||
@@ -17,19 +17,6 @@ async def load_config() -> config_mgr.ConfigManager:
|
||||
return cfg_mgr
|
||||
|
||||
|
||||
async def load_tips() -> config_mgr.ConfigManager:
|
||||
"""加载提示文件"""
|
||||
tips_inst = pymodule.PythonModuleConfigFile(
|
||||
"tips.py",
|
||||
"tips-custom-template.py"
|
||||
)
|
||||
|
||||
tips_mgr = config_mgr.ConfigManager(tips_inst)
|
||||
await tips_mgr.load_config()
|
||||
|
||||
return tips_mgr
|
||||
|
||||
|
||||
async def override_config_manager(cfg_mgr: config_mgr.ConfigManager) -> list[str]:
|
||||
override_json = json.load(open("override.json", "r", encoding="utf-8"))
|
||||
overrided = []
|
||||
@@ -39,5 +26,5 @@ async def override_config_manager(cfg_mgr: config_mgr.ConfigManager) -> list[str
|
||||
if key in config:
|
||||
config[key] = override_json[key]
|
||||
overrided.append(key)
|
||||
|
||||
|
||||
return overrided
|
||||
|
||||
Reference in New Issue
Block a user