Skip to content

Commit 545393e

Browse files
committed
Merge remote-tracking branch 'origin/broken' into broken
2 parents 5a28af4 + e129e9a commit 545393e

File tree

11 files changed

+360
-54
lines changed

11 files changed

+360
-54
lines changed

lagrange/client/client.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
Union,
1010
overload,
1111
Literal,
12+
TYPE_CHECKING,
13+
cast,
1214
)
1315
from collections.abc import Coroutine
1416

@@ -491,31 +493,30 @@ async def set_grp_request(self, grp_id: int, grp_req_seq: int, ev_type: int, act
491493
raise AssertionError(rsp.ret_code, rsp.err_msg)
492494

493495
@overload
494-
async def get_user_info(self, uid: str) -> UserInfo: ...
495-
496-
@overload
497-
async def get_user_info(self, uid: list[str]) -> list[UserInfo]: ...
498-
499-
@overload
500-
async def get_user_info(self, uin: int) -> UserInfo:
496+
async def get_user_info(self, uid_or_uin: Union[str, int], /) -> UserInfo:
501497
...
502498

503499
@overload
504-
async def get_user_info(self, uin: list[int]) -> list[UserInfo]:
500+
async def get_user_info(self, uid_or_uin: Union[list[str], list[int]], /) -> list[UserInfo]:
505501
...
506502

507503
async def get_user_info(
508-
self,
509-
uid: Union[str, list[str]] = None,
510-
uin: Union[int, list[int]] = None,
504+
self,
505+
uid_or_uin: Union[str, int, list[str], list[int]],
506+
/
511507
) -> Union[UserInfo, list[UserInfo]]:
512-
userid = uid or uin
513-
assert userid, "empty uid or uin"
514-
if not isinstance(userid, list):
515-
userid = [userid]
508+
if isinstance(uid_or_uin, list):
509+
assert uid_or_uin, "empty uid or uin"
510+
userid = uid_or_uin
511+
else:
512+
userid = [uid_or_uin]
516513
if isinstance(userid[0], int):
514+
if TYPE_CHECKING:
515+
userid = cast(list[int], userid)
517516
req, sc = PBGetInfoFromUinReq(uin=userid).encode(), 2
518517
elif isinstance(userid[0], str):
518+
if TYPE_CHECKING:
519+
userid = cast(list[str], userid)
519520
req, sc = PBGetInfoFromUidReq(uid=userid).encode(), 8
520521
else:
521522
raise TypeError(userid[0])

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.content}]"
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
]

0 commit comments

Comments
 (0)