refactor: 所有的 json 加载统一到启动阶段中

This commit is contained in:
RockChinQ 2024-03-16 15:41:59 +08:00
parent 98bebfddaa
commit 302d86056d
7 changed files with 29 additions and 19 deletions

View File

@ -33,6 +33,8 @@ class Application:
tool_mgr: llm_tool_mgr.ToolManager = None
# ======= 配置管理器 =======
command_cfg: config_mgr.ConfigManager = None
pipeline_cfg: config_mgr.ConfigManager = None
@ -43,6 +45,16 @@ class Application:
system_cfg: config_mgr.ConfigManager = None
# ======= 元数据配置管理器 =======
sensitive_meta: config_mgr.ConfigManager = None
adapter_qq_botpy_meta: config_mgr.ConfigManager = None
plugin_setting_meta: config_mgr.ConfigManager = None
# =========================
ctr_mgr: center_mgr.V2CenterAPI = None
plugin_mgr: plugin_mgr.PluginManager = None

View File

@ -13,7 +13,6 @@ required_files = {
"data/config/platform.json": "templates/platform.json",
"data/config/provider.json": "templates/provider.json",
"data/config/system.json": "templates/system.json",
"data/config/sensitive-words.json": "templates/sensitive-words.json",
"data/scenario/default.json": "templates/scenario-template.json",
}

View File

@ -17,3 +17,13 @@ class LoadConfigStage(stage.BootingStage):
ap.platform_cfg = await config.load_json_config("data/config/platform.json", "templates/platform.json")
ap.provider_cfg = await config.load_json_config("data/config/provider.json", "templates/provider.json")
ap.system_cfg = await config.load_json_config("data/config/system.json", "templates/system.json")
ap.plugin_setting_meta = await config.load_json_config("plugins/plugins.json", "templates/plugin-settings.json")
await ap.plugin_setting_meta.dump_config()
ap.sensitive_meta = await config.load_json_config("data/metadata/sensitive-words.json", "templates/metadata/sensitive-words.json")
await ap.sensitive_meta.dump_config()
ap.adapter_qq_botpy_meta = await config.load_json_config("data/metadata/adapter-qq-botpy.json", "templates/metadata/adapter-qq-botpy.json")
await ap.adapter_qq_botpy_meta.dump_config()

View File

@ -10,31 +10,26 @@ from ....config import manager as cfg_mgr
class BanWordFilter(filter_model.ContentFilter):
"""根据内容禁言"""
sensitive: cfg_mgr.ConfigManager
async def initialize(self):
self.sensitive = await cfg_mgr.load_json_config(
"data/config/sensitive-words.json",
"templates/sensitive-words.json"
)
pass
async def process(self, message: str) -> entities.FilterResult:
found = False
for word in self.sensitive.data['words']:
for word in self.ap.sensitive_meta.data['words']:
match = re.findall(word, message)
if len(match) > 0:
found = True
for i in range(len(match)):
if self.sensitive.data['mask_word'] == "":
if self.ap.sensitive_meta.data['mask_word'] == "":
message = message.replace(
match[i], self.sensitive.data['mask'] * len(match[i])
match[i], self.ap.sensitive_meta.data['mask'] * len(match[i])
)
else:
message = message.replace(
match[i], self.sensitive.data['mask_word']
match[i], self.ap.sensitive_meta.data['mask_word']
)
return entities.FilterResult(

View File

@ -506,10 +506,7 @@ class OfficialAdapter(adapter_model.MessageSourceAdapter):
async def run_async(self):
self.metadata = await cfg_mgr.load_json_config(
"data/metadata/adapter-qq-botpy.json",
"templates/metadata/adapter-qq-botpy.json",
)
self.metadata = self.ap.adapter_qq_botpy_meta
self.member_openid_mapping = OpenIDMapping(
map=self.metadata.data["mapping"]["members"],

View File

@ -16,10 +16,7 @@ class SettingManager:
self.ap = ap
async def initialize(self):
self.settings = await cfg_mgr.load_json_config(
'plugins/plugins.json',
'templates/plugin-settings.json'
)
self.settings = self.ap.plugin_setting_meta
async def sync_setting(
self,