diff --git a/nonebot/adapters/dodo/event.py b/nonebot/adapters/dodo/event.py index e055a6c..f3611e8 100644 --- a/nonebot/adapters/dodo/event.py +++ b/nonebot/adapters/dodo/event.py @@ -119,7 +119,7 @@ class MessageEvent(Event): message_type: MessageType = Field(alias="messageType") message_body: MessageBody = Field(alias="messageBody") - to_me: bool = Field(default=False, alias="toMe") + to_me: bool = False @property def message(self) -> Message: @@ -127,9 +127,7 @@ def message(self) -> Message: @property def origin_message(self) -> Message: - if not hasattr(self, "_origin_message"): - return self.get_message() - return getattr(self, "_origin_message") + return getattr(self, "_origin_message", self.get_message()) @property def reply(self) -> Optional[Reference]: @@ -367,7 +365,7 @@ class PersonalMessageEvent(MessageEvent): default=EventType.PERSONAL_MESSAGE, alias="eventType" ) - to_me: bool = Field(default=True, alias="toMe") + to_me: bool = True EventClass = Union[ diff --git a/nonebot/adapters/dodo/message.py b/nonebot/adapters/dodo/message.py index f2c3edb..ccef716 100644 --- a/nonebot/adapters/dodo/message.py +++ b/nonebot/adapters/dodo/message.py @@ -9,6 +9,7 @@ Tuple, Type, TypedDict, + Union, ) from typing_extensions import Self, override @@ -147,6 +148,22 @@ def card( # }, # ) + @override + def __add__( + self, other: Union[str, "MessageSegment", Iterable["MessageSegment"]] + ) -> "Message": + return Message(self) + ( + MessageSegment.text(other) if isinstance(other, str) else other + ) + + @override + def __radd__( + self, other: Union[str, "MessageSegment", Iterable["MessageSegment"]] + ) -> "Message": + return ( + MessageSegment.text(other) if isinstance(other, str) else Message(other) + ) + self + class _TextData(TypedDict): text: str @@ -352,6 +369,22 @@ class Message(BaseMessage[MessageSegment]): def get_segment_class(cls) -> Type[MessageSegment]: return MessageSegment + @override + def __add__( + self, other: Union[str, MessageSegment, Iterable[MessageSegment]] + ) -> "Message": + return super().__add__( + MessageSegment.text(other) if isinstance(other, str) else other + ) + + @override + def __radd__( + self, other: Union[str, MessageSegment, Iterable[MessageSegment]] + ) -> "Message": + return super().__radd__( + MessageSegment.text(other) if isinstance(other, str) else other + ) + @staticmethod @override def _construct(msg: str) -> Iterable[MessageSegment]: