Skip to content

Commit 9b3a6a2

Browse files
Decrabbityyywyapx
andauthored
fix(event): right group member joined infomation (#43)
* fix: fix group notice detail * feat:maybe decode markdown * Update decoder.py * Update elems.py * Update elems.py --------- Co-authored-by: nullcat <[email protected]>
1 parent ce26c0b commit 9b3a6a2

File tree

7 files changed

+262
-36
lines changed

7 files changed

+262
-36
lines changed

lagrange/client/events/group.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class GroupMemberJoinRequest(GroupEvent):
8181

8282
@dataclass
8383
class GroupMemberJoined(GroupEvent):
84-
uin: int
84+
# uin: int //it cant get
8585
uid: str
8686
join_type: int
8787

@@ -152,4 +152,35 @@ class GroupInvite(GroupEvent):
152152
@dataclass
153153
class GroupMemberJoinedByInvite(GroupEvent):
154154
invitor_uin: int
155-
uin: int
155+
uin: int
156+
157+
158+
@dataclass
159+
class GroupSelfJoined(GroupEvent):
160+
grp_id: int
161+
op_uid: str
162+
163+
164+
@dataclass
165+
class GroupSelfRequireReject(GroupEvent):
166+
grp_id: int
167+
message: str
168+
169+
170+
@dataclass
171+
class GroupBotAdded(GroupEvent):
172+
bot_uid: str
173+
174+
175+
@dataclass
176+
class BotGrayTip(GroupEvent):
177+
content: str
178+
179+
180+
@dataclass
181+
class GroupBotJoined(GroupEvent):
182+
opqq_uin: int
183+
nick_name: str
184+
robot_name: str
185+
robot_schema: str
186+
user_schema: str

lagrange/client/message/decoder.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from .types import Element
1313
from lagrange.utils.binary.reader import Reader
1414
from lagrange.utils.binary.protobuf import proto_encode
15-
from lagrange.pb.message.rich_text.elems import GroupFileExtra, FileExtra
15+
from lagrange.pb.message.rich_text.elems import GroupFileExtra, FileExtra, PBKeyboard
1616
from lagrange.pb.highway.comm import MsgInfo
1717

1818
if TYPE_CHECKING:
@@ -163,6 +163,12 @@ async def parse_msg_new(
163163
f8=common.pb_elem[8],
164164
)
165165
)
166+
if common.service_type == 45:
167+
md_c: bytes = common.pb_elem[1]
168+
msg_chain.append(elems.Markdown(content=md_c.decode()))
169+
if common.service_type == 46:
170+
kb = PBKeyboard.decode(proto_encode(common.pb_elem)).keyboard
171+
msg_chain.append(elems.Keyboard(content=kb.content, bot_appid=kb.bot_appid))
166172
if common.bus_type in [10, 20]: # 10: friend, 20: group
167173
extra = MsgInfo.decode(proto_encode(raw.common_elem.pb_elem))
168174
index = extra.body[0].index

lagrange/client/message/elems.py

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def type(self) -> str:
2020
@dataclass
2121
class CompatibleText(BaseElem):
2222
"""仅用于兼容性变更,不应作为判断条件"""
23+
2324
@property
2425
def text(self) -> str:
2526
return self.display
@@ -28,6 +29,7 @@ def text(self) -> str:
2829
def text(self, text: str):
2930
"""ignore"""
3031

32+
3133
@dataclass
3234
class MediaInfo:
3335
name: str
@@ -215,9 +217,15 @@ def display(self) -> str:
215217
return f"[file:{self.file_name}]"
216218

217219
@classmethod
218-
def _paste_build(cls, file_size: int, file_name: str,
219-
file_md5: bytes, file_id: Optional[str] = None,
220-
file_uuid: Optional[str] = None, file_hash: Optional[str] = None) -> "File":
220+
def _paste_build(
221+
cls,
222+
file_size: int,
223+
file_name: str,
224+
file_md5: bytes,
225+
file_id: Optional[str] = None,
226+
file_uuid: Optional[str] = None,
227+
file_hash: Optional[str] = None,
228+
) -> "File":
221229
return cls(
222230
file_size=file_size,
223231
file_name=file_name,
@@ -244,8 +252,66 @@ class GreyTips(BaseElem):
244252
建议搭配Text使用
245253
冷却3分钟左右?
246254
"""
255+
247256
text: str
248257

249258
@property
250259
def display(self) -> str:
251260
return f"<GreyTips: {self.text}>"
261+
262+
263+
@dataclass
264+
class Markdown(BaseElem):
265+
content: str
266+
267+
@property
268+
def display(self) -> str:
269+
return f"[markdown:{self.md_c.decode()}]"
270+
271+
272+
class Permission:
273+
type: int
274+
specify_role_ids: Optional[list[str]]
275+
specify_user_ids: Optional[list[str]]
276+
277+
278+
class RenderData:
279+
label: Optional[str]
280+
visited_label: Optional[str]
281+
style: int
282+
283+
284+
class Action:
285+
type: Optional[int]
286+
permission: Optional[Permission]
287+
data: str
288+
reply: bool
289+
enter: bool
290+
anchor: Optional[int]
291+
unsupport_tips: Optional[str]
292+
click_limit: Optional[int] # deprecated
293+
at_bot_show_channel_list: bool # deprecated
294+
295+
296+
class Button:
297+
id: Optional[str]
298+
render_data: Optional[RenderData]
299+
action: Optional[Action]
300+
301+
302+
class InlineKeyboardRow:
303+
buttons: Optional[list[Button]]
304+
305+
306+
class InlineKeyboard:
307+
rows: list[InlineKeyboardRow]
308+
309+
310+
@dataclass
311+
class Keyboard(BaseElem):
312+
content: Optional[list[InlineKeyboard]]
313+
bot_appid: int
314+
315+
@property
316+
def display(self) -> str:
317+
return f"[keyboard:{self.bot_appid}]"

lagrange/client/message/types.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
GreyTips,
1818
Video,
1919
Service,
20-
File
20+
File,
21+
Markdown,
22+
Keyboard,
2123
)
2224

2325
# T = TypeVar(
@@ -49,5 +51,7 @@
4951
"GreyTips",
5052
"Video",
5153
"Service",
52-
"File"
54+
"File",
55+
"Markdown",
56+
"Keyboard",
5357
]

lagrange/client/server_push/msg.py

Lines changed: 51 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,21 @@
1414
MemberJoinRequest,
1515
MemberRecallMsg,
1616
GroupSub20Head,
17+
PBBotGrayTip,
1718
PBGroupAlbumUpdate,
19+
PBGroupBotAdded,
1820
PBGroupInvite,
21+
PBSelfJoinInGroup,
1922
)
20-
from lagrange.pb.status.friend import (
21-
PBFriendRecall,
22-
PBFriendRequest
23-
)
23+
from lagrange.pb.status.friend import PBFriendRecall, PBFriendRequest
2424
from lagrange.utils.binary.protobuf import proto_decode, ProtoStruct, proto_encode
2525
from lagrange.utils.binary.reader import Reader
2626
from lagrange.utils.operator import unpack_dict, timestamp
2727

2828
from ..events.group import (
29+
BotGrayTip,
30+
GroupBotAdded,
31+
GroupBotJoined,
2932
GroupInvite,
3033
GroupMemberGotSpecialTitle,
3134
GroupMemberJoined,
@@ -36,14 +39,13 @@
3639
GroupRecall,
3740
GroupNudge,
3841
GroupReaction,
42+
GroupSelfJoined,
43+
GroupSelfRequireReject,
3944
GroupSign,
4045
GroupAlbumUpdate,
41-
GroupMemberJoinedByInvite
42-
)
43-
from ..events.friend import (
44-
FriendRecall,
45-
FriendRequest
46+
GroupMemberJoinedByInvite,
4647
)
48+
from ..events.friend import FriendRecall, FriendRequest
4749
from ..wtlogin.sso import SSOPacket
4850
from .log import logger
4951

@@ -74,10 +76,9 @@ async def msg_push_handler(client: "Client", sso: SSOPacket):
7476
elif typ == 33: # member joined
7577
pb = MemberChanged.decode(pkg.message.buf2)
7678
return GroupMemberJoined(
77-
grp_id=pkg.response_head.from_uin,
78-
uin=pb.uin,
79-
uid=pb.uid,
80-
join_type=pb.join_type,
79+
grp_id=pb.uin,
80+
uid=pb.uid, # right u cant get uin
81+
join_type=pb.join_type_new,
8182
)
8283
elif typ == 34: # member exit
8384
pb = MemberChanged.decode(pkg.message.buf2)
@@ -91,26 +92,35 @@ async def msg_push_handler(client: "Client", sso: SSOPacket):
9192
elif typ == 84:
9293
pb = MemberJoinRequest.decode(pkg.message.buf2)
9394
return GroupMemberJoinRequest(grp_id=pb.grp_id, uid=pb.uid, answer=pb.request_field)
95+
elif typ == 85:
96+
pb = PBSelfJoinInGroup.decode(pkg.message.buf2)
97+
return GroupSelfJoined(grp_id=pb.gid, op_uid=pb.operator_uid)
98+
elif typ == 86:
99+
reader = Reader(pkg.message.buf2)
100+
grp_id = reader.read_u32() # it should have more infomation,but i cant guess it
101+
return GroupSelfRequireReject(grp_id, "")
94102
elif typ == 87:
95103
pb = PBGroupInvite.decode(pkg.message.buf2)
96104
return GroupInvite(grp_id=pb.gid, invitor_uid=pb.invitor_uid)
105+
elif typ == 167:
106+
print(pkg.message.encode().hex())
97107
elif typ == 525:
98108
pb = MemberInviteRequest.decode(pkg.message.buf2)
99109
if pb.cmd == 87:
100110
inn = pb.info.inner
101111
return GroupMemberJoinRequest(grp_id=inn.grp_id, uid=inn.uid, invitor_uid=inn.invitor_uid)
102112
elif typ == 0x210: # friend event, 528 / group file upload notice event
103-
if sub_typ == 35: # friend request
113+
if sub_typ == 35: # friend request
104114
pb = PBFriendRequest.decode(pkg.message.buf2)
105115
return FriendRequest(
106116
pkg.response_head.from_uin,
107117
pb.info.from_uid,
108118
pkg.response_head.to_uin,
109119
pb.info.to_uid,
110120
pb.info.verify,
111-
pb.info.source
121+
pb.info.source,
112122
)
113-
elif sub_typ == 138: # friend recall
123+
elif sub_typ == 138: # friend recall
114124
pb = PBFriendRecall.decode(pkg.message.buf2)
115125
return FriendRecall(
116126
pkg.response_head.from_uin,
@@ -119,10 +129,16 @@ async def msg_push_handler(client: "Client", sso: SSOPacket):
119129
pb.info.to_uid,
120130
pb.info.seq,
121131
pb.info.random,
122-
pb.info.time
132+
pb.info.time,
123133
)
134+
if sub_typ == 368:
135+
pass
136+
# print(pkg.message.encode().hex())
124137
logger.debug(f"unhandled friend event / group file upload notice event: {pkg}") # TODO: paste
125138
elif typ == 0x2DC: # grp event, 732
139+
if sub_typ == 1:
140+
# print(pkg.encode().hex())
141+
pass
126142
if sub_typ == 20: # nudge and group_sign(群打卡)
127143
if pkg.message:
128144
grp_id, pb = unpack(pkg.message.buf2, GroupSub20Head)
@@ -136,14 +152,19 @@ async def msg_push_handler(client: "Client", sso: SSOPacket):
136152
attrs[k.decode()] = int(v.decode())
137153
else:
138154
attrs[k.decode()] = v.decode()
155+
if pb.body.f2 == 19217:
156+
return GroupBotJoined(
157+
grp_id,
158+
attrs["mqq_uin"],
159+
attrs["nick_name"],
160+
attrs["robot_name"],
161+
attrs["robot_schema"],
162+
attrs["user_schema"],
163+
)
139164
if pb.body.type == 1:
140165
if "invitor" in attrs:
141166
# reserve: attrs["msg_nums"]
142-
return GroupMemberJoinedByInvite(
143-
grp_id,
144-
attrs["invitor"],
145-
attrs["invitee"]
146-
)
167+
return GroupMemberJoinedByInvite(grp_id, attrs["invitor"], attrs["invitee"])
147168
elif "user" in attrs and "uin" in attrs:
148169
# todo: 群代办
149170
pass
@@ -169,13 +190,17 @@ async def msg_push_handler(client: "Client", sso: SSOPacket):
169190
pb.body.attrs_xml,
170191
)
171192
else:
172-
raise ValueError(f"unknown type({pb.body.type}) on GroupSub20: {attrs}")
193+
raise ValueError(f"unknown type({pb.body.type}) f2({pb.body.f2}) on GroupSub20: {attrs}")
173194
else:
174195
# print(pkg.encode().hex(), 2)
175196
return
176197
elif sub_typ == 16: # rename & special_title & reaction
198+
# print(sso.data.hex())
177199
if pkg.message:
178200
grp_id, pb = unpack(pkg.message.buf2, GroupSub16Head)
201+
if pb.flag is None:
202+
_, pb = unpack(pkg.message.buf2, PBBotGrayTip) # 傻逼tx,我13号位呢
203+
return BotGrayTip(grp_id, pb.body.message)
179204
if pb.flag == 6: # special_title
180205
body = MemberGotTitleBody.decode(pb.body)
181206
for el in re.findall(r"<(\{.*?})>", body.string):
@@ -222,6 +247,9 @@ async def msg_push_handler(client: "Client", sso: SSOPacket):
222247
timestamp=pb.timestamp,
223248
image_id=q["i"],
224249
)
250+
elif pb.flag == 38:
251+
_, pb = unpack(pkg.message.buf2, PBGroupBotAdded)
252+
return GroupBotAdded(pb.body.grp_id, pb.body.bot_uid_1 or pb.body.bot_uid_2)
225253
else:
226254
raise ValueError(f"Unknown subtype_12 flag: {pb.flag}: {pb.body.hex() if pb.body else pb}")
227255
elif sub_typ == 17: # recall

0 commit comments

Comments
 (0)