fix: preserve qq official quoted message context#9164
Conversation
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The patched message classes (PatchedMessage, PatchedDirectMessage, PatchedC2CMessage, PatchedGroupMessage) duplicate the same slots and init logic; consider introducing a shared base/mixin to reduce repetition and keep future changes to raw field handling in one place.
- The quoted message detection relies on the hard-coded
message_type == 103value; it would be clearer and safer to centralize this as a named constant or helper function so its meaning is explicit and easy to adjust if QQ changes the type codes. - In
_append_attachments, the dict/object branching and repeated content-type/URL/filename extraction logic could be simplified via a small normalization helper, and the sets of file extensions could be moved to module-level constants to avoid reallocation on each call.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The patched message classes (PatchedMessage, PatchedDirectMessage, PatchedC2CMessage, PatchedGroupMessage) duplicate the same __slots__ and __init__ logic; consider introducing a shared base/mixin to reduce repetition and keep future changes to raw field handling in one place.
- The quoted message detection relies on the hard-coded `message_type == 103` value; it would be clearer and safer to centralize this as a named constant or helper function so its meaning is explicit and easy to adjust if QQ changes the type codes.
- In `_append_attachments`, the dict/object branching and repeated content-type/URL/filename extraction logic could be simplified via a small normalization helper, and the sets of file extensions could be moved to module-level constants to avoid reallocation on each call.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 adds support for parsing quoted messages (replies) and retaining raw message fields from the official QQ platform. It introduces patched message classes, registers multiple message parsers dynamically, and updates attachment parsing to handle dictionary payloads. The review feedback suggests defensive programming improvements, specifically ensuring that the message payload and data dictionaries are safely guarded against None or invalid types before accessing their keys, as well as adding debug logging for received message events.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| def parse_message(self, payload: dict[str, Any]) -> None: | ||
| qq_message = message_cls( | ||
| self.api, | ||
| payload.get("id", None), | ||
| payload.get("d", {}), | ||
| ) | ||
| self._dispatch(event_name, qq_message) |
There was a problem hiding this comment.
Defensive programming & logging: If "d" is explicitly set to None in the payload, payload.get("d", {}) will return None, which can cause downstream issues. Using payload.get("d") or {} is safer. Additionally, adding generic debug logging for received message events helps significantly with troubleshooting.
| def parse_message(self, payload: dict[str, Any]) -> None: | |
| qq_message = message_cls( | |
| self.api, | |
| payload.get("id", None), | |
| payload.get("d", {}), | |
| ) | |
| self._dispatch(event_name, qq_message) | |
| def parse_message(self, payload: dict[str, Any]) -> None: | |
| payload = payload or {} | |
| qq_message = message_cls( | |
| self.api, | |
| payload.get("id", None), | |
| payload.get("d") or {}, | |
| ) | |
| logger.debug("[QQOfficial] Received message event %s: %s", event_name, qq_message) | |
| self._dispatch(event_name, qq_message) |
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
astrbot-docs | 8f6d393 | Commit Preview URL Branch Preview URL |
Jul 06 2026, 03:01 PM |
…dapter.py Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Summary
Tests
Summary by Sourcery
Preserve QQOfficial quoted message context by patching message parsers to retain raw payload fields, converting quoted content and attachments into Reply components, and extending tests to cover quoted group messages with image attachments.
New Features:
Bug Fixes:
Enhancements:
Tests: