From 4e7592de98f6bb17f108d1c8b6d12e159f2ee863 Mon Sep 17 00:00:00 2001 From: yanyongyu Date: Tue, 30 Mar 2021 16:21:56 +0800 Subject: [PATCH] :lock: ensure cqhttp str radd escaped --- .../nonebot/adapters/cqhttp/message.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/nonebot-adapter-cqhttp/nonebot/adapters/cqhttp/message.py b/packages/nonebot-adapter-cqhttp/nonebot/adapters/cqhttp/message.py index 07c463c5..acdef22e 100644 --- a/packages/nonebot-adapter-cqhttp/nonebot/adapters/cqhttp/message.py +++ b/packages/nonebot-adapter-cqhttp/nonebot/adapters/cqhttp/message.py @@ -38,7 +38,8 @@ class MessageSegment(BaseMessageSegment): @overrides(BaseMessageSegment) def __radd__(self, other) -> "Message": - return Message(other) + self + return (MessageSegment.text(other) + if isinstance(other, str) else Message(other)) + self @overrides(BaseMessageSegment) def is_text(self) -> bool: @@ -211,6 +212,11 @@ class Message(BaseMessage): CQHTTP 协议 Message 适配。 """ + def __radd__(self, other: Union[str, MessageSegment, + "Message"]) -> "Message": + result = MessageSegment.text(other) if isinstance(other, str) else other + return super(Message, self).__radd__(result) + @staticmethod @overrides(BaseMessage) def _construct(