Skip to content

Commit

Permalink
🐛 version 0.11.3
Browse files Browse the repository at this point in the history
resolve #18
  • Loading branch information
RF-Tar-Railt committed Apr 29, 2024
1 parent ab854bb commit 4bcdc1c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
13 changes: 11 additions & 2 deletions nonebot/adapters/satori/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from nonebot.adapters import Message as BaseMessage
from nonebot.adapters import MessageSegment as BaseMessageSegment

from .element import Element, parse, escape, param_case
from .element import Element, escape, param_case


@dataclass
Expand Down Expand Up @@ -735,6 +735,15 @@ class Message(BaseMessage[MessageSegment]):
def get_segment_class(cls) -> Type[MessageSegment]:
return MessageSegment

def __init__(
self,
message: Union[str, None, Iterable[MessageSegment], MessageSegment] = None,
):
if isinstance(message, str):
super().__init__(MessageSegment.raw(message))
else:
super().__init__(message)

@override
def __add__(self, other: Union[str, MessageSegment, Iterable[MessageSegment]]) -> "Message":
result = self.copy()
Expand All @@ -749,7 +758,7 @@ def __radd__(self, other: Union[str, MessageSegment, Iterable[MessageSegment]])
@staticmethod
@override
def _construct(msg: str) -> Iterable[MessageSegment]:
yield from Message.from_satori_element(parse(msg))
yield Text(msg)

@classmethod
def from_satori_element(cls, elements: List[Element]) -> "Message":
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "nonebot-adapter-satori"
version = "0.11.2"
version = "0.11.3"
description = "Satori Protocol Adapter for Nonebot2"
authors = [
{name = "RF-Tar-Railt",email = "rf_tar_railt@qq.com"},
Expand Down
3 changes: 3 additions & 0 deletions tests/test_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ def test_message():
parse("<chronocat:face id='265' name='[辣眼睛]' platform='chronocat'/>")
)[0].data == {"id": "265", "name": "[辣眼睛]", "platform": "chronocat"}

test_message1 = MessageSegment(type="chronocat:face", data={"id": 12}) + "\n" + "Hello Yoshi"
assert str(test_message1) == '<chronocat:face id="12"/>\nHello Yoshi'


@pytest.mark.asyncio
async def test_message_rich_expr():
Expand Down

0 comments on commit 4bcdc1c

Please sign in to comment.