优化ai消息内容

This commit is contained in:
liuwei
2026-02-02 16:02:44 +08:00
parent 0626eceb62
commit 4cac7c04a0

View File

@@ -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: