优化自动对话逻辑
This commit is contained in:
@@ -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.message_plugin_interface import MessagePluginInterface
|
||||||
from base.plugin_common.plugin_interface import PluginStatus
|
from base.plugin_common.plugin_interface import PluginStatus
|
||||||
from utils.robot_cmd.robot_command import Feature, PermissionStatus, GroupBotManager
|
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 import WechatAPIClient
|
||||||
|
|
||||||
from .bot_ai import InterventionBot
|
from .bot_ai import InterventionBot
|
||||||
@@ -112,11 +113,20 @@ class AIAutoResponsePlugin(MessagePluginInterface):
|
|||||||
if roomid not in self.group_messages:
|
if roomid not in self.group_messages:
|
||||||
self.group_messages[roomid] = []
|
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 = {
|
current_message = {
|
||||||
"timestamp": message.get("timestamp", ""),
|
"timestamp": message.get("timestamp", ""),
|
||||||
"message": content,
|
"message": content,
|
||||||
"sender": message.get("sender", "")
|
"sender": sender_id,
|
||||||
|
"sender_name": sender_name
|
||||||
}
|
}
|
||||||
|
|
||||||
# 添加新消息
|
# 添加新消息
|
||||||
@@ -181,7 +191,8 @@ class AIAutoResponsePlugin(MessagePluginInterface):
|
|||||||
|
|
||||||
context_str_list = []
|
context_str_list = []
|
||||||
for msg in recent_msgs:
|
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", "")
|
content = msg.get("message", "")
|
||||||
context_str_list.append(f"{sender}: {content}")
|
context_str_list.append(f"{sender}: {content}")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user