From 08fc6577555f7aa5fddea80b42e7fa2a24302706 Mon Sep 17 00:00:00 2001 From: qingyun Date: Sat, 14 Mar 2026 18:18:14 +0800 Subject: [PATCH] fix: preserve whitespace in Plain.toDict() for @ mentions (#6244) * fix: preserve whitespace in Plain.toDict() for @ mentions - Remove .strip() from Plain.toDict() to match async to_dict() behavior - Fixes #6237: QQ @mentions no longer lose trailing spaces - This ensures '@user message' displays correctly instead of '@usermessage' * refactor: remove redundant to_dict() from Plain class - Let Plain inherit to_dict() from BaseMessageComponent - BaseMessageComponent.to_dict() calls toDict() by default - Reduces code duplication and prevents future divergence - Addressed code review feedback from @gemini-code-assist and @sourcery-ai * feat: add async to_dict method to Plain message component * fix: add return type hint to Plain.toDict method --------- Co-authored-by: ccsang Co-authored-by: Soulter <905617992@qq.com> --- astrbot/core/message/components.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/astrbot/core/message/components.py b/astrbot/core/message/components.py index d9ea6aa26..6311681cd 100644 --- a/astrbot/core/message/components.py +++ b/astrbot/core/message/components.py @@ -96,10 +96,10 @@ class Plain(BaseMessageComponent): def __init__(self, text: str, convert: bool = True, **_) -> None: super().__init__(text=text, convert=convert, **_) - def toDict(self): - return {"type": "text", "data": {"text": self.text.strip()}} + def toDict(self) -> dict: + return {"type": "text", "data": {"text": self.text}} - async def to_dict(self): + async def to_dict(self) -> dict: return {"type": "text", "data": {"text": self.text}}