From f1b600fd970494df2351761003eae4cfb658c642 Mon Sep 17 00:00:00 2001 From: LuiKlee Date: Thu, 9 Oct 2025 23:47:44 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E9=94=99=E8=AF=AF+=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit spatial_effects 配置 未在描述中定义但尝试加载 现已移除 炸了叫lui() --- .../built_in/tts_voice_plugin/plugin.py | 58 +++++++++++-------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/src/plugins/built_in/tts_voice_plugin/plugin.py b/src/plugins/built_in/tts_voice_plugin/plugin.py index d5348f6a5..2fa1d136f 100644 --- a/src/plugins/built_in/tts_voice_plugin/plugin.py +++ b/src/plugins/built_in/tts_voice_plugin/plugin.py @@ -49,41 +49,49 @@ class TTSVoicePlugin(BasePlugin): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.tts_service = None + # 新增配置缓存 + self._config_cache = None def _get_config_wrapper(self, key: str, default: Any = None) -> Any: """ 配置获取的包装器,用于解决 get_config 无法直接获取动态表(如 tts_styles)和未在 schema 中定义的节的问题。 由于插件系统的 schema 为空时不会加载未定义的键,这里手动读取配置文件以获取所需配置。 """ - # 需要手动加载的顶级配置节 - manual_load_keys = ["tts_styles", "spatial_effects", "tts_advanced", "tts"] + # 需要手动加载的顶级配置节(移除未定义的 spatial_effects) + manual_load_keys = ["tts_styles", "tts_advanced", "tts"] top_key = key.split('.')[0] - if top_key in manual_load_keys: + # 仅当需要手动加载且缓存为空时加载配置 + if top_key in manual_load_keys and self._config_cache is None: try: - plugin_file = Path(__file__).resolve() - bot_root = plugin_file.parent.parent.parent.parent.parent - config_file = bot_root / "config" / "plugins" / self.plugin_name / self.config_file_name - - if not config_file.is_file(): - logger.error(f"TTS config file not found at robustly constructed path: {config_file}") - return default - - full_config = toml.loads(config_file.read_text(encoding="utf-8")) - - # 支持点状路径访问 - value = full_config - for k in key.split('.'): - if isinstance(value, dict): - value = value.get(k) - else: - return default - - return value if value is not None else default + # 优化:使用标准插件路径 + config_path = Path(__file__).parent / "config" / self.config_file_name + if not config_path.exists(): + logger.error(f"TTS config file not found at {config_path}") + self._config_cache = {} + else: + # 使用 toml.load 代替 toml.loads 以提高性能 + self._config_cache = toml.load(config_path) + except toml.TomlDecodeError as e: + logger.error(f"Invalid TOML syntax in config: {e}") + self._config_cache = {} + except FileNotFoundError: + logger.error(f"Config file missing: {config_path}") + self._config_cache = {} except Exception as e: - logger.error(f"Failed to manually load '{key}' from config: {e}", exc_info=True) - return default + logger.error(f"Unexpected config error: {e}", exc_info=True) + self._config_cache = {} + + # 从缓存中获取配置 + if top_key in manual_load_keys: + value = self._config_cache + for k in key.split('.'): + if isinstance(value, dict): + value = value.get(k) + else: + return default + return value if value is not None else default return self.get_config(key, default) @@ -106,7 +114,7 @@ class TTSVoicePlugin(BasePlugin): """ components = [] if self.get_config("components.action_enabled", True): - components.append((TTSVoiceAction.get_action_info(), TTSVoiceAction)) + components.appendTTSVoiceAction.get_action_info(), TTSVoiceAction)) if self.get_config("components.command_enabled", True): components.append((TTSVoiceCommand.get_plus_command_info(), TTSVoiceCommand)) return components From 4b960dba18ad331b8104f0543e683fff75c86239 Mon Sep 17 00:00:00 2001 From: LuiKlee Date: Thu, 9 Oct 2025 23:53:31 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dresponse=5Fset=20?= =?UTF-8?q?=E4=B8=BA=E7=A9=BA=E6=97=B6=E7=9A=84=E9=80=BB=E8=BE=91=E7=BC=BA?= =?UTF-8?q?=E9=99=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 感觉不改也没问题 应该不至于炸( From 9f8a5c9612f2d15baa356daba160882a188d5085 Mon Sep 17 00:00:00 2001 From: LuiKlee Date: Fri, 10 Oct 2025 10:38:04 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dtts=5Fvoice=5Fplugin/plug?= =?UTF-8?q?in.py117=E8=A1=8C=E7=9A=84=EF=BC=88=EF=BC=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/built_in/tts_voice_plugin/plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/built_in/tts_voice_plugin/plugin.py b/src/plugins/built_in/tts_voice_plugin/plugin.py index 2fa1d136f..34f9c1a11 100644 --- a/src/plugins/built_in/tts_voice_plugin/plugin.py +++ b/src/plugins/built_in/tts_voice_plugin/plugin.py @@ -114,7 +114,7 @@ class TTSVoicePlugin(BasePlugin): """ components = [] if self.get_config("components.action_enabled", True): - components.appendTTSVoiceAction.get_action_info(), TTSVoiceAction)) + components.append((TTSVoiceAction.get_action_info(), TTSVoiceAction)) if self.get_config("components.command_enabled", True): components.append((TTSVoiceCommand.get_plus_command_info(), TTSVoiceCommand)) return components