优化联系人信息,解决总结时使用了其他群的备注信息

This commit is contained in:
liuwei
2025-05-28 15:33:23 +08:00
parent 3c460ce4a7
commit 6c9b99afcf
7 changed files with 91 additions and 72 deletions

View File

@@ -6,6 +6,7 @@ import xml.etree.ElementTree as ET
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
@@ -118,10 +119,12 @@ class GroupMemberChangePlugin(MessagePluginInterface):
now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
member_wxids = [wxid]
await bot.send_at_message(roomid, f"👏欢迎 {nickname} 加入群聊!🎉", member_wxids)
members = await bot.get_chatroom_member_detail(wxid, roomid)
head_url = members.get("SmallHeadImgUrl") or members.get("BigHeadImgUrl") or ""
# 更新联系人信息
ContactManager.get_instance().update_head_image(wxid, head_url)
ContactManager.get_instance().update_group_members(roomid, wxid, nickname)
xml_content = f"""
<appmsg appid="" sdkver="1">

View File

@@ -9,6 +9,7 @@ import requests
from utils.revoke.message_auto_revoke import MessageAutoRevoke
from utils.string_utils import remove_trailing_content
from utils.wechat.contact_manager import ContactManager
from utils.wechat.message_to_db import MessageStorage
from utils.compress_chat_data import compress_chat_data
from base.plugin_common.message_plugin_interface import MessagePluginInterface
@@ -109,8 +110,9 @@ class MessageSummaryPlugin(MessagePluginInterface):
return False, None
# 从消息历史中获取群聊记录
all_contacts: dict = message.get("all_contacts")
group_members: dict = ContactManager.get_instance().get_group_members()
chat_content = self.message_storage.get_messages(group_id, all_contacts)
chat_content = self.message_storage.get_messages(group_id, group_members)
if len(chat_content) < 100:
return False, None
@@ -141,11 +143,13 @@ class MessageSummaryPlugin(MessagePluginInterface):
await self.bot.send_image_message(group_id, Path(image_path))
else:
client_msg_id, create_time, new_msg_id = await self.bot.send_text_message(group_id, "❌ 生成总结图片失败")
client_msg_id, create_time, new_msg_id = await self.bot.send_text_message(group_id,
"❌ 生成总结图片失败")
self.revoke.add_message_to_revoke(group_id, client_msg_id, create_time, new_msg_id, 5)
except Exception as e:
self.LOG.error(f"异步生成总结失败: {e}")
client_msg_id, create_time, new_msg_id = await self.bot.send_text_message(group_id, f"❌ 生成总结失败: {str(e)}")
client_msg_id, create_time, new_msg_id = await self.bot.send_text_message(group_id,
f"❌ 生成总结失败: {str(e)}")
self.revoke.add_message_to_revoke(group_id, client_msg_id, create_time, new_msg_id, 5)
def _sanitize_group_name(self, group_name: str) -> str: