测试入群提醒。

This commit is contained in:
liuwei
2025-04-30 16:19:08 +08:00
parent d2cd6a66d2
commit 7886e5b5d0
2 changed files with 74 additions and 5 deletions

View File

@@ -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"""
<appmsg appid="" sdkver="1">
<title>👏欢迎 {nickname} 加入群聊!🎉</title>
<des>⌚时间:{now}</des>
<action>view</action>
<type>5</type>
<showtype>0</showtype>
<content />
<url>https://hot.imsyy.top/#/</url>
<dataurl />
<lowurl />
<lowdataurl />
<recorditem />
<thumburl>{head_url}</thumburl>
<messageaction />
<laninfo />
<extinfo />
<sourceusername />
<sourcedisplayname />
<commenturl />
<appattach>
<totallen>0</totallen>
<attachid />
<emoticonmd5 />
<fileext />
<aeskey />
</appattach>
<webviewshared>
<publisherId />
<publisherReqId>0</publisherReqId>
</webviewshared>
<weappinfo>
<pagepath />
<username />
<appid />
<appservicetype>0</appservicetype>
</weappinfo>
<websearch />
</appmsg>
<fromusername>Jyunere</fromusername>
<scene>0</scene>
<appinfo>
<version>1</version>
<appname></appname>
</appinfo>
<commenturl></commenturl>
"""
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} 加入群聊!🎉",

View File

@@ -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 {} # 如果没找到对应的成员,返回空字符串