diff --git a/pkg/core/app.py b/pkg/core/app.py index 0d726a4..e1df54e 100644 --- a/pkg/core/app.py +++ b/pkg/core/app.py @@ -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 diff --git a/pkg/core/bootutils/files.py b/pkg/core/bootutils/files.py index ab4b15c..9bab382 100644 --- a/pkg/core/bootutils/files.py +++ b/pkg/core/bootutils/files.py @@ -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", } diff --git a/pkg/core/stages/load_config.py b/pkg/core/stages/load_config.py index 0ee2c1e..cdba5f8 100644 --- a/pkg/core/stages/load_config.py +++ b/pkg/core/stages/load_config.py @@ -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() \ No newline at end of file diff --git a/pkg/pipeline/cntfilter/filters/banwords.py b/pkg/pipeline/cntfilter/filters/banwords.py index 9391971..5cd7dcf 100644 --- a/pkg/pipeline/cntfilter/filters/banwords.py +++ b/pkg/pipeline/cntfilter/filters/banwords.py @@ -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( diff --git a/pkg/platform/sources/qqbotpy.py b/pkg/platform/sources/qqbotpy.py index ab981cf..5d731d3 100644 --- a/pkg/platform/sources/qqbotpy.py +++ b/pkg/platform/sources/qqbotpy.py @@ -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"], diff --git a/pkg/plugin/setting.py b/pkg/plugin/setting.py index c193493..7e715af 100644 --- a/pkg/plugin/setting.py +++ b/pkg/plugin/setting.py @@ -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, diff --git a/templates/sensitive-words.json b/templates/metadata/sensitive-words.json similarity index 100% rename from templates/sensitive-words.json rename to templates/metadata/sensitive-words.json