Skip to content

feat(event): GroupInviteAccept event & GroupRecall event #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lagrange/client/events/friend.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,10 @@ class FriendMessage(FriendEvent):
timestamp: int
msg: str
msg_chain: list[Element]


@dataclass
class FriendRecall(FriendEvent):
seq: int
msg_id: int
timestamp: int
6 changes: 6 additions & 0 deletions lagrange/client/events/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,9 @@ class GroupAlbumUpdate(GroupEvent):
@dataclass
class GroupInvite(GroupEvent):
invitor_uid: str


@dataclass
class GroupInviteAccept(GroupEvent):
invitor_uin: int
uin: int
26 changes: 25 additions & 1 deletion lagrange/client/server_push/msg.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
PBGroupAlbumUpdate,
PBGroupInvite,
)
from lagrange.pb.status.friend import (
PBFriendRecall
)
from lagrange.utils.binary.protobuf import proto_decode, ProtoStruct, proto_encode
from lagrange.utils.binary.reader import Reader
from lagrange.utils.operator import unpack_dict, timestamp
Expand All @@ -34,6 +37,10 @@
GroupReaction,
GroupSign,
GroupAlbumUpdate,
GroupInviteAccept
)
from ..events.friend import (
FriendRecall
)
from ..wtlogin.sso import SSOPacket
from .log import logger
Expand Down Expand Up @@ -90,7 +97,18 @@ async def msg_push_handler(client: "Client", sso: SSOPacket):
if pb.cmd == 87:
inn = pb.info.inner
return GroupMemberJoinRequest(grp_id=inn.grp_id, uid=inn.uid, invitor_uid=inn.invitor_uid)
elif typ == 0x210: # friend event / group file upload notice event
elif typ == 0x210: # friend event, 528 / group file upload notice event
if sub_typ == 138: # friend recall
pb = PBFriendRecall.decode(pkg.message.buf2)
return FriendRecall(
pkg.response_head.from_uin,
pb.info.from_uid,
pkg.response_head.to_uin,
pb.info.to_uid,
pb.info.seq,
pb.info.random,
pb.info.time
)
logger.debug(f"unhandled friend event / group file upload notice event: {pkg}") # TODO: paste
elif typ == 0x2DC: # grp event, 732
if sub_typ == 20: # nudge and group_sign(群打卡)
Expand All @@ -106,6 +124,12 @@ async def msg_push_handler(client: "Client", sso: SSOPacket):
attrs[k.decode()] = int(v.decode())
else:
attrs[k.decode()] = v.decode()
if pb.body.type == 1:
return GroupInviteAccept(
grp_id,
attrs["invitor"],
attrs["invitee"]
)
if pb.body.type == 12:
return GroupNudge(
grp_id,
Expand Down
15 changes: 15 additions & 0 deletions lagrange/pb/status/friend.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from lagrange.utils.binary.protobuf import proto_field, ProtoStruct

class FriendRecallInfo(ProtoStruct):
from_uid: str = proto_field(1)
to_uid: str = proto_field(2)
seq: int = proto_field(3)
new_id: int = proto_field(4)
time: int = proto_field(5)
random: int = proto_field(6)
package_num: int = proto_field(7)
package_index: int = proto_field(8)
div_seq: int = proto_field(9)

class PBFriendRecall(ProtoStruct):
info: FriendRecallInfo = proto_field(1)