From 4bcdc1c835a57029cef8ab6eff1bb2d73943ab18 Mon Sep 17 00:00:00 2001
From: rf_tar_railt <3165388245@qq.com>
Date: Mon, 29 Apr 2024 17:50:52 +0800
Subject: [PATCH] :bug: version 0.11.3 resolve #18
---
nonebot/adapters/satori/message.py | 13 +++++++++++--
pyproject.toml | 2 +-
tests/test_message.py | 3 +++
3 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/nonebot/adapters/satori/message.py b/nonebot/adapters/satori/message.py
index 44d8bc3..65c4396 100644
--- a/nonebot/adapters/satori/message.py
+++ b/nonebot/adapters/satori/message.py
@@ -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
@@ -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()
@@ -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":
diff --git a/pyproject.toml b/pyproject.toml
index 4900ca7..3fa342f 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -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"},
diff --git a/tests/test_message.py b/tests/test_message.py
index dcfc779..61b7929 100644
--- a/tests/test_message.py
+++ b/tests/test_message.py
@@ -21,6 +21,9 @@ def test_message():
parse("")
)[0].data == {"id": "265", "name": "[辣眼睛]", "platform": "chronocat"}
+ test_message1 = MessageSegment(type="chronocat:face", data={"id": 12}) + "\n" + "Hello Yoshi"
+ assert str(test_message1) == '\nHello Yoshi'
+
@pytest.mark.asyncio
async def test_message_rich_expr():