优化自动对话逻辑

This commit is contained in:
liuwei
2026-02-02 14:20:43 +08:00
parent 1a2ca4f808
commit a5c0d70b9f

View File

@@ -6,6 +6,7 @@ from typing import Dict, Any, List, Optional, Tuple
from base.plugin_common.message_plugin_interface import MessagePluginInterface
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 .bot_ai import InterventionBot
@@ -112,11 +113,20 @@ class AIAutoResponsePlugin(MessagePluginInterface):
if roomid not in self.group_messages:
self.group_messages[roomid] = []
# 获取发送者昵称
sender_id = message.get("sender", "")
try:
members = ContactManager.get_instance().get_group_members(roomid)
sender_name = members.get(sender_id, sender_id)
except Exception:
sender_name = sender_id
# 添加新消息
current_message = {
"timestamp": message.get("timestamp", ""),
"message": content,
"sender": message.get("sender", "")
"sender": sender_id,
"sender_name": sender_name
}
# 添加新消息
@@ -181,7 +191,8 @@ class AIAutoResponsePlugin(MessagePluginInterface):
context_str_list = []
for msg in recent_msgs:
sender = msg.get("sender", "Unknown")
# 优先使用昵称如果没有则使用sender ID
sender = msg.get("sender_name") or msg.get("sender", "Unknown")
content = msg.get("message", "")
context_str_list.append(f"{sender}: {content}")