Skip to content

Commit 73d6400

Browse files
committed
feat(client): get_user_info can use uin as args
1 parent d51c7c9 commit 73d6400

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

lagrange/client/client.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
PBGetInfoFromUidReq,
5353
PBGetGrpLastSeq,
5454
GetGrpLastSeqRsp,
55+
PBGetInfoFromUinReq,
5556
)
5657
from lagrange.pb.service.oidb import OidbRequest, OidbResponse
5758
from lagrange.pb.highway.comm import IndexNode
@@ -495,10 +496,31 @@ async def get_user_info(self, uid: str) -> UserInfo: ...
495496
@overload
496497
async def get_user_info(self, uid: list[str]) -> list[UserInfo]: ...
497498

498-
async def get_user_info(self, uid: Union[str, list[str]]) -> Union[UserInfo, list[UserInfo]]:
499-
if isinstance(uid, str):
500-
uid = [uid]
501-
rsp = GetInfoFromUidRsp.decode((await self.send_oidb_svc(0xFE1, 8, PBGetInfoFromUidReq(uid=uid).encode())).data)
499+
@overload
500+
async def get_user_info(self, uin: int) -> UserInfo:
501+
...
502+
503+
@overload
504+
async def get_user_info(self, uin: list[int]) -> list[UserInfo]:
505+
...
506+
507+
async def get_user_info(
508+
self,
509+
uid: Union[str, list[str]] = None,
510+
uin: Union[int, list[int]] = None,
511+
) -> Union[UserInfo, list[UserInfo]]:
512+
userid = uid or uin
513+
assert userid, "empty uid or uin"
514+
if not isinstance(userid, list):
515+
userid = [userid]
516+
if isinstance(userid[0], int):
517+
req, sc = PBGetInfoFromUinReq(uin=userid).encode(), 2
518+
elif isinstance(userid[0], str):
519+
req, sc = PBGetInfoFromUidReq(uid=userid).encode(), 8
520+
else:
521+
raise TypeError(userid[0])
522+
523+
rsp = GetInfoFromUidRsp.decode((await self.send_oidb_svc(0xFE1, sc, req)).data)
502524
if not rsp.body:
503525
raise AssertionError("Empty response")
504526
elif len(rsp.body) == 1:

lagrange/pb/service/group.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,7 @@ class GetGrpListResponse(ProtoStruct):
399399
grp_list: list[GrpInfo] = proto_field(2, default_factory=list)
400400

401401

402-
class PBGetInfoFromUidReq(ProtoStruct):
403-
uid: list[str] = proto_field(1)
402+
class _GetInfoCfg(ProtoStruct):
404403
cfg: bytes = proto_field(
405404
3,
406405
default=bytes.fromhex(
@@ -409,6 +408,13 @@ class PBGetInfoFromUidReq(ProtoStruct):
409408
),
410409
)
411410

411+
class PBGetInfoFromUidReq(_GetInfoCfg):
412+
uid: list[str] = proto_field(1)
413+
414+
415+
class PBGetInfoFromUinReq(_GetInfoCfg):
416+
uin: list[int] = proto_field(1)
417+
412418

413419
class GetInfoRspF1(ProtoStruct):
414420
type: int = proto_field(1)

0 commit comments

Comments
 (0)