Skip to content

Commit 2a02b3c

Browse files
committed
fix(msg): error on parsing GroupNudge
1 parent d8bf6b0 commit 2a02b3c

File tree

2 files changed

+28
-16
lines changed

2 files changed

+28
-16
lines changed

lagrange/client/server_push/msg.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
MemberRecallMsg,
1515
GroupSub20Head,
1616
)
17-
from lagrange.utils.binary.protobuf import proto_decode, ProtoStruct
17+
from lagrange.utils.binary.protobuf import proto_decode, ProtoStruct, proto_encode
1818
from lagrange.utils.binary.reader import Reader
1919
from lagrange.utils.operator import unpack_dict
2020

@@ -87,29 +87,38 @@ async def msg_push_handler(client: "Client", sso: SSOPacket):
8787
elif typ == 0x210: # frd event
8888
logger.debug("unhandled friend event: %s" % pkg)
8989
elif typ == 0x2DC: # grp event, 732
90-
if sub_typ == 20: # nudget(grp_id only)
90+
if sub_typ == 20: # nudge and group_sign(群打卡)
9191
if pkg.message:
9292
grp_id, pb = unpack(pkg.message.buf2, GroupSub20Head)
9393
attrs: Dict[str, Union[str, int]] = {}
9494
for x in pb.body.attrs: # type: dict[bytes, bytes]
9595
k, v = x.values()
96+
if isinstance(v, dict):
97+
v = proto_encode(v)
9698
if v.isdigit():
9799
attrs[k.decode()] = int(v.decode())
98100
else:
99101
attrs[k.decode()] = v.decode()
100-
return GroupNudge(
101-
grp_id,
102-
attrs["uin_str1"],
103-
attrs["uin_str2"],
104-
attrs["action_str"],
105-
attrs["suffix_str"],
106-
attrs,
107-
pb.body.attrs_xml,
108-
)
102+
if pb.body.type == 12:
103+
return GroupNudge(
104+
grp_id,
105+
attrs["uin_str1"],
106+
attrs["uin_str2"],
107+
attrs["action_str"],
108+
attrs["suffix_str"],
109+
attrs,
110+
pb.body.attrs_xml,
111+
)
112+
elif pb.body.type == 14: # grp_sign
113+
pass
114+
else:
115+
raise ValueError(
116+
f"unknown type({pb.body.type}) on GroupSub20: {attrs}"
117+
)
109118
else:
110119
# print(pkg.encode().hex(), 2)
111120
return
112-
elif sub_typ == 16: # rename and special_title and reaction
121+
elif sub_typ == 16: # rename & special_title & reaction
113122
if pkg.message:
114123
grp_id, pb = unpack(pkg.message.buf2, GroupSub16Head)
115124
if pb.flag == 6: # special_title
@@ -136,7 +145,7 @@ async def msg_push_handler(client: "Client", sso: SSOPacket):
136145
timestamp=pb.timestamp,
137146
operator_uid=pb.operator_uid,
138147
)
139-
elif pb.flag == 35: # add reaction
148+
elif pb.flag == 35: # set reaction
140149
body = pb.f44.inner.body
141150
return GroupReaction(
142151
grp_id=grp_id,

lagrange/pb/status/group.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Push Events
33
"""
4+
45
from typing import Optional
56

67
from lagrange.utils.binary.protobuf import proto_field, ProtoStruct
@@ -105,19 +106,21 @@ class GroupSub16Head(ProtoStruct):
105106
timestamp: int = proto_field(2, default=0)
106107
uin: Optional[int] = proto_field(4, default=None)
107108
body: Optional[bytes] = proto_field(5, default=None)
108-
flag: int = proto_field(13) # 12: renamed, 6: set special_title, 13: unknown, 35: set reaction
109+
flag: int = proto_field(
110+
13
111+
) # 12: renamed, 6: set special_title, 13: unknown, 35: set reaction
109112
operator_uid: str = proto_field(21, default="")
110113
f44: Optional[GroupReaction] = proto_field(44, default=None) # set reaction only
111114

112115

113116
class GroupSub20Body(ProtoStruct):
114-
# f1: int = proto_field(1) # 12
117+
type: int = proto_field(1) # 12: nudge, 14: group_sign
115118
# f2: int = proto_field(2) # 1061
116119
# f3: int = proto_field(3) # 7
117120
# f6: int = proto_field(6) # 1132
118121
attrs: list[dict] = proto_field(7, default={})
119122
attrs_xml: str = proto_field(8, default=None)
120-
f10: int = proto_field(10)
123+
f10: int = proto_field(10) # rand?
121124

122125

123126
class GroupSub20Head(ProtoStruct):

0 commit comments

Comments
 (0)