Skip to content

Commit a7b541a

Browse files
authored
Merge pull request #35 from Decrabbityyy/fix/#34
2 parents 6a8a174 + bc28ce1 commit a7b541a

File tree

4 files changed

+50
-41
lines changed

4 files changed

+50
-41
lines changed

lagrange/client/events/group.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,8 @@ class GroupAlbumUpdate(GroupEvent):
142142

143143
timestamp: int
144144
image_id: str
145+
146+
147+
@dataclass
148+
class GroupInvite(GroupEvent):
149+
invitor_uid: str

lagrange/client/message/decoder.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ def parse_friend_info(pkg: MsgPushBody) -> tuple[int, str, int, str]:
3838
return from_uin, from_uid, to_uin, to_uid
3939

4040

41-
async def parse_msg_new(client: "Client", pkg: MsgPushBody,
42-
fri_id: Union[str, None] = None, grp_id: Union[int, None] = None) -> Sequence[Element]:
41+
async def parse_msg_new(
42+
client: "Client", pkg: MsgPushBody, fri_id: Union[str, None] = None, grp_id: Union[int, None] = None
43+
) -> Sequence[Element]:
4344
if not pkg.message or not pkg.message.body:
4445
if pkg.content_head.sub_type == 4:
4546
data = FileExtra.decode(pkg.message.buf2)
@@ -66,7 +67,7 @@ async def parse_msg_new(client: "Client", pkg: MsgPushBody,
6667
time=ptt.time,
6768
file_key=ptt.group_file_key if ptt.group_file_key else ptt.friend_file_key,
6869
qmsg=None,
69-
url=await client.fetch_audio_url(file_key, uid=fri_id, gid=grp_id)
70+
url=await client.fetch_audio_url(file_key, uid=fri_id, gid=grp_id),
7071
)
7172
]
7273
el: list[Elems] = rich.content
@@ -174,9 +175,7 @@ async def parse_msg_new(client: "Client", pkg: MsgPushBody,
174175
size=index.info.size,
175176
id=0,
176177
md5=bytes.fromhex(index.info.hash),
177-
text=extra.biz_info.pic.summary
178-
if extra.biz_info.pic.summary
179-
else "[图片]",
178+
text=extra.biz_info.pic.summary if extra.biz_info.pic.summary else "[图片]",
180179
width=index.info.width,
181180
height=index.info.height,
182181
url=url,
@@ -196,7 +195,7 @@ async def parse_msg_new(client: "Client", pkg: MsgPushBody,
196195
file_size=file_extra.inner.info.file_size,
197196
file_name=file_extra.inner.info.file_name,
198197
file_md5=file_extra.inner.info.file_md5,
199-
file_id=file_extra.inner.info.file_id
198+
file_id=file_extra.inner.info.file_id,
200199
)
201200
)
202201
elif raw.rich_msg:
@@ -208,16 +207,10 @@ async def parse_msg_new(client: "Client", pkg: MsgPushBody,
208207
content = zlib.decompress(jr[1:])
209208
else:
210209
content = jr[1:]
211-
msg_chain.append(
212-
elems.Service(id=sid, raw=content, text=f"[service:{sid}]")
213-
)
210+
msg_chain.append(elems.Service(id=sid, raw=content, text=f"[service:{sid}]"))
214211
ignore_next = True
215212
elif raw.open_data:
216-
msg_chain.append(
217-
elems.Raw(
218-
text=f"[raw:{len(raw.open_data.data)}]", data=raw.open_data.data
219-
)
220-
)
213+
msg_chain.append(elems.Raw(text=f"[raw:{len(raw.open_data.data)}]", data=raw.open_data.data))
221214
elif raw.src_msg: # msg source info
222215
src = raw.src_msg
223216
msg_text = ""
@@ -284,7 +277,7 @@ async def parse_msg_new(client: "Client", pkg: MsgPushBody,
284277
width=video.width,
285278
height=video.height,
286279
qmsg=None,
287-
url="" # TODO: fetch video url
280+
url="", # TODO: fetch video url
288281
)
289282
)
290283
else:

lagrange/client/server_push/msg.py

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
MemberRecallMsg,
1616
GroupSub20Head,
1717
PBGroupAlbumUpdate,
18+
PBGroupInvite,
1819
)
1920
from lagrange.utils.binary.protobuf import proto_decode, ProtoStruct, proto_encode
2021
from lagrange.utils.binary.reader import Reader
2122
from lagrange.utils.operator import unpack_dict, timestamp
2223

2324
from ..events.group import (
25+
GroupInvite,
2426
GroupMemberGotSpecialTitle,
2527
GroupMemberJoined,
2628
GroupMemberJoinRequest,
@@ -58,7 +60,8 @@ async def msg_push_handler(client: "Client", sso: SSOPacket):
5860
if typ == 82: # grp msg
5961
return await parse_grp_msg(client, pkg)
6062
elif typ in [166, 208, 529]: # frd msg
61-
return await parse_friend_msg(client, pkg)
63+
if pkg.message:
64+
return await parse_friend_msg(client, pkg)
6265
elif typ == 33: # member joined
6366
pb = MemberChanged.decode(pkg.message.buf2)
6467
return GroupMemberJoined(
@@ -78,16 +81,15 @@ async def msg_push_handler(client: "Client", sso: SSOPacket):
7881
)
7982
elif typ == 84:
8083
pb = MemberJoinRequest.decode(pkg.message.buf2)
81-
return GroupMemberJoinRequest(
82-
grp_id=pb.grp_id, uid=pb.uid, answer=pb.request_field
83-
)
84+
return GroupMemberJoinRequest(grp_id=pb.grp_id, uid=pb.uid, answer=pb.request_field)
85+
elif typ == 87:
86+
pb = PBGroupInvite.decode(pkg.message.buf2)
87+
return GroupInvite(grp_id=pb.gid, invitor_uid=pb.invitor_uid)
8488
elif typ == 525:
8589
pb = MemberInviteRequest.decode(pkg.message.buf2)
8690
if pb.cmd == 87:
8791
inn = pb.info.inner
88-
return GroupMemberJoinRequest(
89-
grp_id=inn.grp_id, uid=inn.uid, invitor_uid=inn.invitor_uid
90-
)
92+
return GroupMemberJoinRequest(grp_id=inn.grp_id, uid=inn.uid, invitor_uid=inn.invitor_uid)
9193
elif typ == 0x210: # friend event / group file upload notice event
9294
logger.debug(f"unhandled friend event / group file upload notice event: {pkg}") # TODO: paste
9395
elif typ == 0x2DC: # grp event, 732
@@ -109,9 +111,7 @@ async def msg_push_handler(client: "Client", sso: SSOPacket):
109111
grp_id,
110112
attrs["uin_str1"],
111113
attrs["uin_str2"],
112-
attrs["action_str"]
113-
if "action_str" in attrs
114-
else attrs["alt_str1"], # ?
114+
attrs["action_str"] if "action_str" in attrs else attrs["alt_str1"], # ?
115115
attrs["suffix_str"],
116116
attrs,
117117
pb.body.attrs_xml,
@@ -126,9 +126,7 @@ async def msg_push_handler(client: "Client", sso: SSOPacket):
126126
pb.body.attrs_xml,
127127
)
128128
else:
129-
raise ValueError(
130-
f"unknown type({pb.body.type}) on GroupSub20: {attrs}"
131-
)
129+
raise ValueError(f"unknown type({pb.body.type}) on GroupSub20: {attrs}")
132130
else:
133131
# print(pkg.encode().hex(), 2)
134132
return
@@ -174,19 +172,15 @@ async def msg_push_handler(client: "Client", sso: SSOPacket):
174172
elif pb.flag == 23: # 群幸运字符?
175173
pass
176174
elif pb.flag == 37: # 群相册上传(手Q专用:()
177-
_, pb = unpack(
178-
pkg.message.buf2, PBGroupAlbumUpdate
179-
) # 塞 就硬塞,可以把你的顾辉盒也给塞进来
175+
_, pb = unpack(pkg.message.buf2, PBGroupAlbumUpdate) # 塞 就硬塞,可以把你的顾辉盒也给塞进来
180176
q = dict(parse_qsl(pb.body.args))
181177
return GroupAlbumUpdate(
182178
grp_id=pb.grp_id,
183179
timestamp=pb.timestamp,
184180
image_id=q["i"],
185181
)
186182
else:
187-
raise ValueError(
188-
f"Unknown subtype_12 flag: {pb.flag}: {pb.body.hex() if pb.body else pb}"
189-
)
183+
raise ValueError(f"Unknown subtype_12 flag: {pb.flag}: {pb.body.hex() if pb.body else pb}")
190184
elif sub_typ == 17: # recall
191185
grp_id, pb = unpack(pkg.message.buf2, MemberRecallMsg)
192186

@@ -214,9 +208,7 @@ async def msg_push_handler(client: "Client", sso: SSOPacket):
214208
"unknown sub_type %d: %s"
215209
% (
216210
sub_typ,
217-
pkg.message.buf2.hex()
218-
if getattr(pkg.message, "buf2", None)
219-
else pkg,
211+
pkg.message.buf2.hex() if getattr(pkg.message, "buf2", None) else pkg,
220212
)
221213
)
222214
else:

lagrange/pb/status/group.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,7 @@ class GroupSub16Head(ProtoStruct):
106106
timestamp: int = proto_field(2, default=0)
107107
uin: Optional[int] = proto_field(4, default=None)
108108
body: Optional[bytes] = proto_field(5, default=None)
109-
flag: int = proto_field(
110-
13
111-
) # 12: renamed, 6: set special_title, 13: unknown, 35: set reaction
109+
flag: int = proto_field(13) # 12: renamed, 6: set special_title, 13: unknown, 35: set reaction
112110
operator_uid: str = proto_field(21, default="")
113111
f44: Optional[PBGroupReaction] = proto_field(44, default=None) # set reaction only
114112

@@ -141,3 +139,24 @@ class PBGroupAlbumUpdate(ProtoStruct):
141139
grp_id: int = proto_field(4)
142140
# f13: 37
143141
body: PBGroupAlbumUpdateBody = proto_field(46)
142+
143+
144+
# class InviteInner_what(ProtoStruct):
145+
# f1: int = proto_field(1) # 0
146+
# f3: int = proto_field(3) # 32
147+
# f4: bytes = proto_field(4)
148+
# f5: int = proto_field(5)
149+
# f6: str = proto_field(6)
150+
151+
152+
# class InviteInfo_what(ProtoStruct):
153+
# inner: InviteInner_what = proto_field(1)
154+
155+
156+
class PBGroupInvite(ProtoStruct):
157+
gid: int = proto_field(1)
158+
f2: int = proto_field(2) # 1
159+
f3: int = proto_field(3) # 4
160+
f4: int = proto_field(4) # 0
161+
invitor_uid: str = proto_field(5)
162+
invite_info: bytes = proto_field(6)

0 commit comments

Comments
 (0)