Skip to content

Commit 412ff5a

Browse files
committed
feat(event): FriendRequest
1 parent 02d7636 commit 412ff5a

3 files changed

Lines changed: 36 additions & 5 deletions

File tree

lagrange/client/events/friend.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,11 @@ class FriendMessage(FriendEvent):
2929
class FriendRecall(FriendEvent):
3030
seq: int
3131
msg_id: int
32-
timestamp: int
32+
timestamp: int
33+
34+
@dataclass
35+
class FriendRequest(FriendEvent):
36+
from_uid: str
37+
to_uid: str
38+
message: str
39+
source: str

lagrange/client/server_push/msg.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
PBGroupInvite,
1919
)
2020
from lagrange.pb.status.friend import (
21-
PBFriendRecall
21+
PBFriendRecall,
22+
PBFriendRequest
2223
)
2324
from lagrange.utils.binary.protobuf import proto_decode, ProtoStruct, proto_encode
2425
from lagrange.utils.binary.reader import Reader
@@ -40,7 +41,8 @@
4041
GroupMemberJoinedByInvite
4142
)
4243
from ..events.friend import (
43-
FriendRecall
44+
FriendRecall,
45+
FriendRequest
4446
)
4547
from ..wtlogin.sso import SSOPacket
4648
from .log import logger
@@ -98,7 +100,20 @@ async def msg_push_handler(client: "Client", sso: SSOPacket):
98100
inn = pb.info.inner
99101
return GroupMemberJoinRequest(grp_id=inn.grp_id, uid=inn.uid, invitor_uid=inn.invitor_uid)
100102
elif typ == 0x210: # friend event, 528 / group file upload notice event
101-
if sub_typ == 138: # friend recall
103+
if sub_typ == 35: # friend request
104+
try:
105+
pb = PBFriendRequest.decode(pkg.message.buf2)
106+
except KeyError: # 空包wdnmd
107+
return
108+
return FriendRequest(
109+
pkg.response_head.from_uin,
110+
pb.info.from_uid,
111+
pkg.response_head.to_uin,
112+
pb.info.to_uid,
113+
pb.info.verify,
114+
pb.info.source
115+
)
116+
elif sub_typ == 138: # friend recall
102117
pb = PBFriendRecall.decode(pkg.message.buf2)
103118
return FriendRecall(
104119
pkg.response_head.from_uin,

lagrange/pb/status/friend.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,13 @@ class FriendRecallInfo(ProtoStruct):
1212
div_seq: int = proto_field(9)
1313

1414
class PBFriendRecall(ProtoStruct):
15-
info: FriendRecallInfo = proto_field(1)
15+
info: FriendRecallInfo = proto_field(1)
16+
17+
class FriendRequestInfo(ProtoStruct):
18+
to_uid: str = proto_field(1)
19+
from_uid: str = proto_field(2)
20+
verify: str = proto_field(10) # 验证消息:我是...
21+
source: str = proto_field(11)
22+
23+
class PBFriendRequest(ProtoStruct):
24+
info: FriendRequestInfo = proto_field(1)

0 commit comments

Comments
 (0)