feat: add message-level markdown control for QQ Official platform#6980
feat: add message-level markdown control for QQ Official platform#6980KBVsent wants to merge 2 commits intoAstrBotDevs:masterfrom
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the messaging capabilities for the QQ Official platform by providing granular control over message formatting. Previously, messages were always attempted as Markdown with an automatic fallback. This change allows plugins to explicitly dictate whether a message should be sent as plain text or Markdown, optimizing message delivery for various content types and reducing unnecessary overhead. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In
_post_send, consider avoidinggetattr(self.send_buffer, "use_markdown_", None)and instead givingsend_buffera concrete type (or cast) that includesuse_markdown_, so type checkers can catch misuse and refactors remain safer. - The hard-coded
msg_typevalues0and2would be clearer and less error-prone if they were defined as named constants or an enum for QQ Official message types and reused here.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `_post_send`, consider avoiding `getattr(self.send_buffer, "use_markdown_", None)` and instead giving `send_buffer` a concrete type (or cast) that includes `use_markdown_`, so type checkers can catch misuse and refactors remain safer.
- The hard-coded `msg_type` values `0` and `2` would be clearer and less error-prone if they were defined as named constants or an enum for QQ Official message types and reused here.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Code Review
This pull request introduces a new feature to control Markdown usage when sending messages. It adds a use_markdown_ attribute to the MessageChain class and a corresponding use_markdown method, allowing users to explicitly enable or disable Markdown for messages. The message sending logic in qqofficial_message_event.py has been updated to respect this new flag, enabling messages to be sent as either Markdown or plain text based on the use_markdown_ setting. Feedback includes a suggestion to remove unnecessary parentheses in the use_markdown_ attribute definition for better style consistency and a recommendation to refactor the if/else logic in qqofficial_message_event.py to reduce code duplication and improve maintainability.
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The new derive() helper on MessageChain manually copies a fixed set of attributes (use_t2i_, use_markdown_, type), which is easy to forget to update when new metadata fields are added; consider using dataclasses.replace or a more generic copy mechanism so future fields are automatically preserved.
- In post_send for QQ Official, the logic assumes that the platform default is always Markdown (msg_type=2) when use_markdown is None; if you ever change the platform default behavior, you may want to centralize this decision (e.g., a helper on MessageChain or the platform class) so that the meaning of None stays consistent with the actual default.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new derive() helper on MessageChain manually copies a fixed set of attributes (use_t2i_, use_markdown_, type), which is easy to forget to update when new metadata fields are added; consider using dataclasses.replace or a more generic copy mechanism so future fields are automatically preserved.
- In _post_send for QQ Official, the logic assumes that the platform default is always Markdown (msg_type=2) when use_markdown_ is None; if you ever change the platform default behavior, you may want to centralize this decision (e.g., a helper on MessageChain or the platform class) so that the meaning of None stays consistent with the actual default.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Related Issues: #5845
QQ Official platform currently always attempts to send messages as Markdown (msg_type=2) with an automatic fallback to plain text on rejection. There is no way for plugins to control this on a per-message basis. Some messages (e.g. structured data, plain notifications) should be sent as plain text directly without the Markdown attempt and fallback overhead. This change gives plugins explicit control over the sending mode, and the field is designed to be reusable by other Markdown-capable platforms in the future.
Modifications / 改动点
astrbot/core/message/message_event_result.py: Adduse_markdown_: bool | Nonefield anduse_markdown()chainable method to MessageChain, following the same pattern as use_t2i_.astrbot/core/platform/sources/qqofficial/qqofficial_message_event.py: Readsend_buffer.use_markdown_ in _post_send()to construct plain text payload (msg_type=0, content) when False, otherwise preserve existing Markdown behavior.Screenshots or Test Results / 运行截图或测试结果
event.plain_result(msg)event.plain_result(msg).use_markdown(False)Checklist / 检查清单
😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
/ 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。
👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
/ 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。
🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in
requirements.txtandpyproject.toml./ 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到
requirements.txt和pyproject.toml文件相应位置。😮 My changes do not introduce malicious code.
/ 我的更改没有引入恶意代码。
Summary by Sourcery
Add message-level control over Markdown usage and preserve message metadata across derived message chains.
New Features:
Enhancements: