Feature: 为消息类添加 has join include exclude 方法 (#1895)

This commit is contained in:
Ju4tCode
2023-04-04 21:42:01 +08:00
committed by GitHub
parent 20820e72ad
commit 1817102a7c
6 changed files with 356 additions and 54 deletions

View File

@ -13,7 +13,7 @@ def escape_text(s: str, *, escape_comma: bool = True) -> str:
def make_fake_message():
class FakeMessageSegment(MessageSegment):
class FakeMessageSegment(MessageSegment["FakeMessage"]):
@classmethod
def get_message_class(cls):
return FakeMessage
@ -36,7 +36,7 @@ def make_fake_message():
def is_text(self) -> bool:
return self.type == "text"
class FakeMessage(Message):
class FakeMessage(Message[FakeMessageSegment]):
@classmethod
def get_segment_class(cls):
return FakeMessageSegment
@ -50,7 +50,9 @@ def make_fake_message():
yield FakeMessageSegment(**seg)
return
def __add__(self, other):
def __add__(
self, other: Union[str, FakeMessageSegment, Iterable[FakeMessageSegment]]
):
other = escape_text(other) if isinstance(other, str) else other
return super().__add__(other)