Impl get chatroom members
This commit is contained in:
parent
b4576b50da
commit
5a0b774c22
21
clients/python/roomdata.proto
Normal file
21
clients/python/roomdata.proto
Normal file
@ -0,0 +1,21 @@
|
||||
syntax = "proto3";
|
||||
package com.iamteer.wcf;
|
||||
|
||||
message RoomData {
|
||||
|
||||
message RoomMember {
|
||||
string wxid = 1;
|
||||
string name = 2;
|
||||
int32 state = 3;
|
||||
}
|
||||
|
||||
repeated RoomMember members = 1;
|
||||
|
||||
int32 field_2 = 2;
|
||||
int32 field_3 = 3;
|
||||
int32 field_4 = 4;
|
||||
int32 room_capacity = 5;
|
||||
int32 field_6 = 6;
|
||||
int64 field_7 = 7;
|
||||
int64 field_8 = 8;
|
||||
}
|
@ -19,6 +19,7 @@ import pynng
|
||||
import requests
|
||||
from google.protobuf import json_format
|
||||
from wcferry import wcf_pb2
|
||||
from wcferry.roomdata_pb2 import RoomData
|
||||
from wcferry.wxmsg import WxMsg
|
||||
|
||||
|
||||
@ -536,9 +537,9 @@ class Wcf():
|
||||
}
|
||||
friends = []
|
||||
for cnt in self.get_contacts():
|
||||
if (cnt["wxid"].endswith("@chatroom") # 群聊
|
||||
or cnt["wxid"].startswith("gh_") # 公众号
|
||||
or cnt["wxid"] in not_friends.keys() # 其他杂号
|
||||
if (cnt["wxid"].endswith("@chatroom") or # 群聊
|
||||
cnt["wxid"].startswith("gh_") or # 公众号
|
||||
cnt["wxid"] in not_friends.keys() # 其他杂号
|
||||
):
|
||||
continue
|
||||
friends.append(cnt)
|
||||
@ -629,3 +630,34 @@ class Wcf():
|
||||
req.m.wxids = wxids.replace(" ", "")
|
||||
rsp = self._send_request(req)
|
||||
return rsp.status
|
||||
|
||||
def get_chatroom_members(self, roomid: str) -> List[dict]:
|
||||
"""获取群成员
|
||||
|
||||
Args:
|
||||
roomid (str): 群的 id
|
||||
|
||||
Returns:
|
||||
List[dict]: 群成员列表: [{wxid: 昵称}, ...]
|
||||
"""
|
||||
pass
|
||||
contacts = self.query_sql("MicroMsg.db", "SELECT UserName, NickName FROM Contact;")
|
||||
contacts = {contact["UserName"]: contact["NickName"]for contact in contacts}
|
||||
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)
|
||||
if not bs:
|
||||
return []
|
||||
|
||||
names = {}
|
||||
for member in crd.members:
|
||||
names[member.wxid] = member.name if member.name else contacts.get(member.wxid, "")
|
||||
|
||||
return names
|
||||
|
27
clients/python/wcferry/roomdata_pb2.py
Normal file
27
clients/python/wcferry/roomdata_pb2.py
Normal file
@ -0,0 +1,27 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
# source: roomdata.proto
|
||||
"""Generated protocol buffer code."""
|
||||
from google.protobuf.internal import builder as _builder
|
||||
from google.protobuf import descriptor as _descriptor
|
||||
from google.protobuf import descriptor_pool as _descriptor_pool
|
||||
from google.protobuf import symbol_database as _symbol_database
|
||||
# @@protoc_insertion_point(imports)
|
||||
|
||||
_sym_db = _symbol_database.Default()
|
||||
|
||||
|
||||
|
||||
|
||||
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0eroomdata.proto\x12\x0f\x63om.iamteer.wcf\"\xf7\x01\n\x08RoomData\x12\x35\n\x07members\x18\x01 \x03(\x0b\x32$.com.iamteer.wcf.RoomData.RoomMember\x12\x0f\n\x07\x66ield_2\x18\x02 \x01(\x05\x12\x0f\n\x07\x66ield_3\x18\x03 \x01(\x05\x12\x0f\n\x07\x66ield_4\x18\x04 \x01(\x05\x12\x15\n\rroom_capacity\x18\x05 \x01(\x05\x12\x0f\n\x07\x66ield_6\x18\x06 \x01(\x05\x12\x0f\n\x07\x66ield_7\x18\x07 \x01(\x03\x12\x0f\n\x07\x66ield_8\x18\x08 \x01(\x03\x1a\x37\n\nRoomMember\x12\x0c\n\x04wxid\x18\x01 \x01(\t\x12\x0c\n\x04name\x18\x02 \x01(\t\x12\r\n\x05state\x18\x03 \x01(\x05\x62\x06proto3')
|
||||
|
||||
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals())
|
||||
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'roomdata_pb2', globals())
|
||||
if _descriptor._USE_C_DESCRIPTORS == False:
|
||||
|
||||
DESCRIPTOR._options = None
|
||||
_ROOMDATA._serialized_start=36
|
||||
_ROOMDATA._serialized_end=283
|
||||
_ROOMDATA_ROOMMEMBER._serialized_start=228
|
||||
_ROOMDATA_ROOMMEMBER._serialized_end=283
|
||||
# @@protoc_insertion_point(module_scope)
|
Loading…
Reference in New Issue
Block a user