调整插件执行顺序:ai_auto_response改为最后兜底
- 在消息插件调度中增加排序逻辑\n- 通过 feature_key/模块名/插件名识别 ai_auto_response\n- 保持其他插件原有顺序,确保命令类插件优先命中\n- ai_auto_response 放到末位执行,避免前置抢占
This commit is contained in:
21
robot.py
21
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:
|
||||
|
||||
Reference in New Issue
Block a user