From 041a3f30d86d4b73ff035944f16ac0b76b5ebc30 Mon Sep 17 00:00:00 2001 From: liuwei Date: Thu, 16 Apr 2026 11:38:08 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=8F=92=E4=BB=B6=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E9=A1=BA=E5=BA=8F=EF=BC=9Aai=5Fauto=5Fresponse?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E6=9C=80=E5=90=8E=E5=85=9C=E5=BA=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在消息插件调度中增加排序逻辑\n- 通过 feature_key/模块名/插件名识别 ai_auto_response\n- 保持其他插件原有顺序,确保命令类插件优先命中\n- ai_auto_response 放到末位执行,避免前置抢占 --- robot.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/robot.py b/robot.py index 881edbf..af77ed9 100644 --- a/robot.py +++ b/robot.py @@ -569,6 +569,7 @@ class Robot: self.LOG.info(f"夜间休眠时间(00:30-05:00),忽略消息: {msg}") return False message_plugins = self.plugin_registry.get_plugins_by_type(MessagePluginInterface) + message_plugins = self._sort_message_plugins(message_plugins) if not message_plugins: return False @@ -608,6 +609,26 @@ class Robot: return False + @staticmethod + def _sort_message_plugins(message_plugins): + """将兜底型插件放到最后执行,避免影响其他插件命中。""" + if not message_plugins: + return [] + + def is_fallback_plugin(plugin): + feature_key = str(getattr(plugin, "feature_key", "") or "").strip().upper() + module_name = str(getattr(plugin.__class__, "__module__", "") or "").lower() + plugin_name = str(getattr(plugin, "name", "") or "").strip().lower() + return ( + feature_key == "AI_AUTO_RESPONSE" + or "plugins.ai_auto_response" in module_name + or plugin_name in {"小牛群聊bot", "ai_auto_response"} + ) + + normal_plugins = [plugin for plugin in message_plugins if not is_fallback_plugin(plugin)] + fallback_plugins = [plugin for plugin in message_plugins if is_fallback_plugin(plugin)] + return normal_plugins + fallback_plugins + def get_all_contacts(self) -> dict: """获取所有联系人信息并返回字典格式 {wxid: nickname}""" try: