From 0e9f556406d3aacac7843025e6f5394c5cfaec5a Mon Sep 17 00:00:00 2001 From: Changhua Date: Thu, 21 Sep 2023 22:53:16 +0800 Subject: [PATCH] Impl get alias in chatroom --- clients/python/wcferry/client.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/clients/python/wcferry/client.py b/clients/python/wcferry/client.py index d2b47d4..a77d92d 100644 --- a/clients/python/wcferry/client.py +++ b/clients/python/wcferry/client.py @@ -660,3 +660,35 @@ class Wcf(): members[member.wxid] = member.name if member.name else contacts.get(member.wxid, "") return members + + def get_alias_in_chatroom(self, wxid: str, roomid: str) -> str: + """获取群名片 + + Args: + wxid (str): wxid + roomid (str): 群的 id + + Returns: + str: 群名片 + """ + nickname = self.query_sql("MicroMsg.db", f"SELECT NickName FROM Contact WHERE UserName = '{wxid}';") + if not nickname: + return "" + + nickname = nickname[0].get("NickName", "") + + crs = self.query_sql("MicroMsg.db", f"SELECT RoomData FROM ChatRoom WHERE ChatRoomName = '{roomid}';") + if not crs: + return "" + + bs = crs[0].get("RoomData") + if not bs: + return "" + + crd = RoomData() + crd.ParseFromString(bs) + for member in crd.members: + if member.wxid == wxid: + return member.name if member.name else nickname + + return ""