From 412ff5af71dbd552c7edca6daf8ff85c6c5ffa30 Mon Sep 17 00:00:00 2001 From: HornCopper Date: Fri, 27 Sep 2024 00:14:07 +0800 Subject: [PATCH 1/3] feat(event): FriendRequest --- lagrange/client/events/friend.py | 9 ++++++++- lagrange/client/server_push/msg.py | 21 ++++++++++++++++++--- lagrange/pb/status/friend.py | 11 ++++++++++- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/lagrange/client/events/friend.py b/lagrange/client/events/friend.py index 7beae68..8374eee 100644 --- a/lagrange/client/events/friend.py +++ b/lagrange/client/events/friend.py @@ -29,4 +29,11 @@ class FriendMessage(FriendEvent): class FriendRecall(FriendEvent): seq: int msg_id: int - timestamp: int \ No newline at end of file + timestamp: int + +@dataclass +class FriendRequest(FriendEvent): + from_uid: str + to_uid: str + message: str + source: str \ No newline at end of file diff --git a/lagrange/client/server_push/msg.py b/lagrange/client/server_push/msg.py index 9ef034f..d2577d8 100644 --- a/lagrange/client/server_push/msg.py +++ b/lagrange/client/server_push/msg.py @@ -18,7 +18,8 @@ PBGroupInvite, ) from lagrange.pb.status.friend import ( - PBFriendRecall + PBFriendRecall, + PBFriendRequest ) from lagrange.utils.binary.protobuf import proto_decode, ProtoStruct, proto_encode from lagrange.utils.binary.reader import Reader @@ -40,7 +41,8 @@ GroupMemberJoinedByInvite ) from ..events.friend import ( - FriendRecall + FriendRecall, + FriendRequest ) from ..wtlogin.sso import SSOPacket from .log import logger @@ -98,7 +100,20 @@ async def msg_push_handler(client: "Client", sso: SSOPacket): inn = pb.info.inner return GroupMemberJoinRequest(grp_id=inn.grp_id, uid=inn.uid, invitor_uid=inn.invitor_uid) elif typ == 0x210: # friend event, 528 / group file upload notice event - if sub_typ == 138: # friend recall + if sub_typ == 35: # friend request + try: + pb = PBFriendRequest.decode(pkg.message.buf2) + except KeyError: # 空包wdnmd + return + return FriendRequest( + pkg.response_head.from_uin, + pb.info.from_uid, + pkg.response_head.to_uin, + pb.info.to_uid, + pb.info.verify, + pb.info.source + ) + elif sub_typ == 138: # friend recall pb = PBFriendRecall.decode(pkg.message.buf2) return FriendRecall( pkg.response_head.from_uin, diff --git a/lagrange/pb/status/friend.py b/lagrange/pb/status/friend.py index 1538d9b..a6d5a86 100644 --- a/lagrange/pb/status/friend.py +++ b/lagrange/pb/status/friend.py @@ -12,4 +12,13 @@ class FriendRecallInfo(ProtoStruct): div_seq: int = proto_field(9) class PBFriendRecall(ProtoStruct): - info: FriendRecallInfo = proto_field(1) \ No newline at end of file + info: FriendRecallInfo = proto_field(1) + +class FriendRequestInfo(ProtoStruct): + to_uid: str = proto_field(1) + from_uid: str = proto_field(2) + verify: str = proto_field(10) # 验证消息:我是... + source: str = proto_field(11) + +class PBFriendRequest(ProtoStruct): + info: FriendRequestInfo = proto_field(1) \ No newline at end of file From 109293360077b75e9d5a86bc8e8577f1db0713d8 Mon Sep 17 00:00:00 2001 From: HornCopper <68726147+HornCopper@users.noreply.github.com> Date: Sun, 29 Sep 2024 05:16:50 +0800 Subject: [PATCH 2/3] Update lagrange/pb/status/friend.py Co-authored-by: nullcat --- lagrange/pb/status/friend.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lagrange/pb/status/friend.py b/lagrange/pb/status/friend.py index a6d5a86..1e3eafd 100644 --- a/lagrange/pb/status/friend.py +++ b/lagrange/pb/status/friend.py @@ -17,7 +17,7 @@ class PBFriendRecall(ProtoStruct): class FriendRequestInfo(ProtoStruct): to_uid: str = proto_field(1) from_uid: str = proto_field(2) - verify: str = proto_field(10) # 验证消息:我是... + verify: str = proto_field(10) # 验证消息:我是... source: str = proto_field(11) class PBFriendRequest(ProtoStruct): From df8c17a18de667b82cfe26ee20f02ff0ac79c742 Mon Sep 17 00:00:00 2001 From: Copper <68726147+HornCopper@users.noreply.github.com> Date: Thu, 10 Oct 2024 01:02:13 +0800 Subject: [PATCH 3/3] feat(event): ignore exception. --- lagrange/client/server_push/msg.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lagrange/client/server_push/msg.py b/lagrange/client/server_push/msg.py index d2577d8..3fa375b 100644 --- a/lagrange/client/server_push/msg.py +++ b/lagrange/client/server_push/msg.py @@ -101,10 +101,7 @@ async def msg_push_handler(client: "Client", sso: SSOPacket): return GroupMemberJoinRequest(grp_id=inn.grp_id, uid=inn.uid, invitor_uid=inn.invitor_uid) elif typ == 0x210: # friend event, 528 / group file upload notice event if sub_typ == 35: # friend request - try: - pb = PBFriendRequest.decode(pkg.message.buf2) - except KeyError: # 空包wdnmd - return + pb = PBFriendRequest.decode(pkg.message.buf2) return FriendRequest( pkg.response_head.from_uin, pb.info.from_uid,