From 7886e5b5d034ebdf850a36e972c6ea50066034fc Mon Sep 17 00:00:00 2001 From: liuwei Date: Wed, 30 Apr 2025 16:19:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E5=85=A5=E7=BE=A4=E6=8F=90?= =?UTF-8?q?=E9=86=92=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/group_member_change/main.py | 53 +++++++++++++++++++++++++++-- wechat_ipad/client/group.py | 26 ++++++++++++-- 2 files changed, 74 insertions(+), 5 deletions(-) diff --git a/plugins/group_member_change/main.py b/plugins/group_member_change/main.py index b5a7c69..177a7a4 100644 --- a/plugins/group_member_change/main.py +++ b/plugins/group_member_change/main.py @@ -119,12 +119,61 @@ class GroupMemberChangePlugin(MessagePluginInterface): wxid = member["wxid"] nickname = member["nickname"] - # now = datetime.now().strftime("%Y-%m-%d %H:%M:%S") + 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_contract_detail(member_wxids, roomid) + members = await bot.get_chatroom_member_detail(wxid, roomid) + head_url = members.get("SmallHeadImgUrl") or members.get("BigHeadImgUrl") or "" + xml_content = f""" + + 👏欢迎 {nickname} 加入群聊!🎉 + ⌚时间:{now} + view + 5 + 0 + + https://hot.imsyy.top/#/ + + + + + {head_url} + + + + + + + + 0 + + + + + + + + 0 + + + + + + 0 + + + + Jyunere + 0 + + 1 + + + + """ + await bot.send_link_xml_message(xml_content, roomid) # if members: # gewe_client.client.post_link(gewe_client.client.app_id, sender, # title=f"👏欢迎 {nickname} 加入群聊!🎉", diff --git a/wechat_ipad/client/group.py b/wechat_ipad/client/group.py index 2a2d384..fc26df8 100644 --- a/wechat_ipad/client/group.py +++ b/wechat_ipad/client/group.py @@ -44,7 +44,8 @@ class ChatroomMixin(WechatAPIClientBase): async with aiohttp.ClientSession() as session: json_param = {"Wxid": self.wxid, "QID": chatroom} - response = await session.post(f'http://{self.ip}:{self.port}/api/Group/GetChatRoomInfoDetail', json=json_param) + response = await session.post(f'http://{self.ip}:{self.port}/api/Group/GetChatRoomInfoDetail', + json=json_param) json_resp = await response.json() if json_resp.get("Success"): @@ -90,7 +91,8 @@ class ChatroomMixin(WechatAPIClientBase): async with aiohttp.ClientSession() as session: json_param = {"Wxid": self.wxid, "QID": chatroom} - response = await session.post(f'http://{self.ip}:{self.port}/api/Group/GetChatRoomMemberDetail', json=json_param) + response = await session.post(f'http://{self.ip}:{self.port}/api/Group/GetChatRoomMemberDetail', + json=json_param) json_resp = await response.json() if json_resp.get("Success"): @@ -159,7 +161,7 @@ class ChatroomMixin(WechatAPIClientBase): Union[str, list[str]]: 如果输入单个wxid返回str,如果输入wxid列表则返回对应的昵称列表 """ data = await self.get_chatroom_member_list(chatroom) - + if isinstance(wxid, str): # 单个wxid的情况 for member in data: @@ -181,3 +183,21 @@ class ChatroomMixin(WechatAPIClientBase): if not found: result.append("") # 如果没找到对应的成员,添加空字符串 return result + + async def get_chatroom_member_detail(self, wxid: str, chatroom: str) -> dict: + """获取用户昵称 + + Args: + wxid: 用户wxid,可以是单个wxid或最多20个wxid的列表 + chatroom: 群聊id + + Returns: + Union[str, list[str]]: 如果输入单个wxid返回str,如果输入wxid列表则返回对应的昵称列表 + """ + data = await self.get_chatroom_member_list(chatroom) + + for member in data: + if member.get("UserName") == wxid: + # 优先返回DisplayName,如果不存在则返回NickName + return member + return {} # 如果没找到对应的成员,返回空字符串