Skip to content

Commit 4130abb

Browse files
committed
chore(msg): split parser
1 parent 545393e commit 4130abb

File tree

1 file changed

+15
-3
lines changed
  • lagrange/client/server_push

1 file changed

+15
-3
lines changed

lagrange/client/server_push/msg.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,17 @@ def unpack(buf2: bytes, decoder: type[T]) -> tuple[int, T]:
6262
return grp_id, decoder.decode(reader.read_bytes_with_length("u16", False))
6363

6464

65+
def parse_quoted_str(string: str) -> list[dict[str, Union[str, int]]]:
66+
"""
67+
example data: 'test data <{"cmd": 1, "text": "updated"}> <{"cmd": 2}>!'
68+
to: [{"cmd": 1, "text": "updated"}, {"cmd": 2}]
69+
"""
70+
return [
71+
json.loads(el)
72+
for el in re.findall(r"<(\{.*?})>", string)
73+
]
74+
75+
6576
async def msg_push_handler(client: "Client", sso: SSOPacket):
6677
pkg = MsgPush.decode(sso.data).body
6778
typ = pkg.content_head.type
@@ -195,16 +206,14 @@ async def msg_push_handler(client: "Client", sso: SSOPacket):
195206
# print(pkg.encode().hex(), 2)
196207
return
197208
elif sub_typ == 16: # rename & special_title & reaction
198-
# print(sso.data.hex())
199209
if pkg.message:
200210
grp_id, pb = unpack(pkg.message.buf2, GroupSub16Head)
201211
if pb.flag is None:
202212
_, pb = unpack(pkg.message.buf2, PBBotGrayTip) # 傻逼tx,我13号位呢
203213
return BotGrayTip(grp_id, pb.body.message)
204214
if pb.flag == 6: # special_title
205215
body = MemberGotTitleBody.decode(pb.body)
206-
for el in re.findall(r"<(\{.*?})>", body.string):
207-
el = json.loads(el)
216+
for el in parse_quoted_str(body.string):
208217
if el["cmd"] == 1:
209218
title = el["text"]
210219
url = el["data"]
@@ -239,6 +248,9 @@ async def msg_push_handler(client: "Client", sso: SSOPacket):
239248
)
240249
elif pb.flag == 23: # 群幸运字符?
241250
pass
251+
elif pb.flag == 21: # 位置实时分享(不完整)
252+
pass
253+
#print(sso.data.hex())
242254
elif pb.flag == 37: # 群相册上传(手Q专用:()
243255
_, pb = unpack(pkg.message.buf2, PBGroupAlbumUpdate) # 塞 就硬塞,可以把你的顾辉盒也给塞进来
244256
q = dict(parse_qsl(pb.body.args))

0 commit comments

Comments
 (0)