Fix: 修复群聊回复命令解析 - #222
Merged
Merged
Conversation
根据 ref_msg_idx 精确匹配引用消息元素,并清理 QQ 群聊回复中客户端自动添加的被回复者提及,避免命令前置 MentionUser 阻断解析。 补充脱敏真实事件回归测试及 Python 3.10、3.14 测试工作流。
yanyongyu
approved these changes
Aug 9, 2026
Closed
he0119
added a commit
to he0119/CoolQBot
that referenced
this pull request
Aug 9, 2026
## 说明 将 nonebot-adapter-qq 从 1.7.1 更新至 1.7.2,并同步 uv 锁文件。 本次更新主要引入上游已合并的群聊回复命令解析修复:QQ 全量群聊回复事件中的自动提及会被适配器正确清理,使后续文本可被 Alconna 识别为命令。1.7.2 还包含引用元素类型容错、群成员事件与权限、自定义 WebSocket Gateway URL 等更新。 - [nonebot-adapter-qq 1.7.2 更新日志](https://github.com/nonebot/adapter-qq/releases/tag/v1.7.2) - [上游群聊回复命令解析修复 #222](nonebot/adapter-qq#222) ## 验证 - uv lock --check - uv run pytest -n auto -q:400 passed - uv run pre-commit run --all-files - git diff --check
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
原因
QQ 官方群聊在回复消息时会自动把被回复者的提及放在消息正文开头。开启群全量消息后,实际事件中适配器收到的是
MentionUser + 命令文本;同时,现有_check_reply没有按照引用索引识别真实引用元素,导致 Alconna 无法把后续文本解析为命令。QQ 官方文档将
message_type=103定义为引用消息,并通过message_scene.ext中的ref_msg_idx与msg_elements[].msg_idx关联被引用元素。本次修改据此解析引用消息,再结合真实事件 payload 清理 QQ 客户端自动添加的回复对象提及。修改
message_type=103和ref_msg_idx精确匹配引用消息元素to_me行为官方文档参考
GROUP_MESSAGE_CREATE,字段与群 @ 机器人消息一致message_type=103、message_scene.ext中的ref_msg_idx以及msg_elements[].msg_idx验证
uv run --python 3.10 pytestuv run --python 3.14 pytestuv run pre-commit run --all-files