From 4cac7c04a0918a7b8228dfe21a33fc6ea1cff393 Mon Sep 17 00:00:00 2001 From: liuwei Date: Mon, 2 Feb 2026 16:02:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96ai=E6=B6=88=E6=81=AF=E5=86=85?= =?UTF-8?q?=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/ai_auto_response/main.py | 41 +++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/plugins/ai_auto_response/main.py b/plugins/ai_auto_response/main.py index 98796c6..43ffd34 100644 --- a/plugins/ai_auto_response/main.py +++ b/plugins/ai_auto_response/main.py @@ -8,6 +8,8 @@ from base.plugin_common.plugin_interface import PluginStatus from utils.robot_cmd.robot_command import Feature, PermissionStatus, GroupBotManager from utils.wechat.contact_manager import ContactManager from wechat_ipad import WechatAPIClient +from wechat_ipad.models.message import MessageType +import xml.etree.ElementTree as ET from .bot_ai import InterventionBot @@ -113,6 +115,7 @@ class AIAutoResponsePlugin(MessagePluginInterface): if roomid not in self.group_messages: self.group_messages[roomid] = [] + msg_type = message.get("type") # 获取发送者昵称 sender_id = message.get("sender", "") try: @@ -121,16 +124,38 @@ class AIAutoResponsePlugin(MessagePluginInterface): except Exception: sender_name = sender_id - # 添加新消息 - current_message = { - "timestamp": message.get("timestamp", ""), - "message": content, - "sender": sender_id, - "sender_name": sender_name - } + # 仅追加文本(1)与应用消息(49),并对49提取标题 + content_to_store = None + try: + if msg_type == MessageType.TEXT: + content_to_store = content + elif msg_type == MessageType.APP: + try: + root = ET.fromstring(content) + title_elem = root.find('.//title') + if title_elem is not None and title_elem.text: + content_to_store = title_elem.text + else: + content_to_store = "[应用消息]" + except Exception as e: + self.LOG.error(f"解析消息类型49出错: {e}") + content_to_store = "[应用消息]" + except Exception as e: + self.LOG.error(f"处理消息类型出错: {e}") + content_to_store = None + + if content_to_store is not None: + # 添加新消息 + current_message = { + "timestamp": message.get("timestamp", ""), + "message": content_to_store, + "sender": sender_id, + "sender_name": sender_name + } # 添加新消息 - self.group_messages[roomid].append(current_message) + if content_to_store is not None: + self.group_messages[roomid].append(current_message) # 限制消息数量 if len(self.group_messages[roomid]) > self.max_messages: