feat: QQOfficialPlatformAdapter 消息解析新增 appid 参数以确保能获取用户头像地址;移除多余的 At 组件,仅给群聊类型添加 At 组件 (#6741)#7289
feat: QQOfficialPlatformAdapter 消息解析新增 appid 参数以确保能获取用户头像地址;移除多余的 At 组件,仅给群聊类型添加 At 组件 (#6741)#7289FlanChanXwO wants to merge 4 commits intoAstrBotDevs:masterfrom
Conversation
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- The type hint change in
PipelineStage.processfromAsyncGenerator[None, None]toAsyncGenerator[None]is not valid forAsyncGenerator(it expects two type parameters: yield and send); if you only need a stream of values, consider keepingAsyncGenerator[None, None]or switching toAsyncIterator[None]instead.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The type hint change in `PipelineStage.process` from `AsyncGenerator[None, None]` to `AsyncGenerator[None]` is not valid for `AsyncGenerator` (it expects two type parameters: yield and send); if you only need a stream of values, consider keeping `AsyncGenerator[None, None]` or switching to `AsyncIterator[None]` instead.
## Individual Comments
### Comment 1
<location path="tests/test_local_filesystem_component.py" line_range="30" />
<code_context>
skill_path = tmp_path / "skills" / "demo.txt"
skill_path.parent.mkdir(parents=True, exist_ok=True)
- skill_path.write_bytes("技能内容".encode("utf-8"))
+ skill_path.write_bytes("技能内容".encode())
result = asyncio.run(LocalFileSystemComponent().read_file(str(skill_path)))
</code_context>
<issue_to_address>
**issue (testing):** Using `.encode()` without an explicit encoding makes this test dependent on the environment’s default encoding and weakens its intent.
Given the test name (`...prefers_utf8_before_windows_locale`), using `encode("utf-8")` made the file content unambiguously UTF‑8 and aligned with the test’s intent. With plain `.encode()`, the bytes now vary with the system locale (e.g., cp1252/cp936 on Windows), so the test may behave differently across environments.
To keep the test deterministic and accurately exercise `LocalFileSystemComponent`’s UTF‑8 preference, please restore `encode("utf-8")` (or pass an explicit UTF‑8 encoding via the API you use).
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
|
||
| skill_path = tmp_path / "skills" / "demo.txt" | ||
| skill_path.parent.mkdir(parents=True, exist_ok=True) | ||
| skill_path.write_bytes("技能内容".encode("utf-8")) |
There was a problem hiding this comment.
issue (testing): Using .encode() without an explicit encoding makes this test dependent on the environment’s default encoding and weakens its intent.
Given the test name (...prefers_utf8_before_windows_locale), using encode("utf-8") made the file content unambiguously UTF‑8 and aligned with the test’s intent. With plain .encode(), the bytes now vary with the system locale (e.g., cp1252/cp936 on Windows), so the test may behave differently across environments.
To keep the test deterministic and accurately exercise LocalFileSystemComponent’s UTF‑8 preference, please restore encode("utf-8") (or pass an explicit UTF‑8 encoding via the API you use).
There was a problem hiding this comment.
Pull request overview
This PR updates the QQ Official platform adapters’ message parsing so downstream plugins can correctly identify the bot (self_id) and avoid receiving misleading At components (especially in private chats), addressing #6741.
Changes:
- Add an
appidparameter toQQOfficialPlatformAdapter._parse_from_qqofficialand passself.platform.appidfrom all entrypoints. - Fix
self_idassignment to useappid, and only prepend anAt(qq=appid)component for group messages (not private/C2C). - Includes a few unrelated refactors/adjustments in pipeline typing and tests.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
astrbot/core/platform/sources/qqofficial/qqofficial_platform_adapter.py |
Pass appid into parsing, set self_id more accurately, restrict At insertion to group messages. |
astrbot/core/platform/sources/qqofficial_webhook/qo_webhook_adapter.py |
Propagate appid into the shared parsing helper for webhook mode. |
astrbot/core/pipeline/stage.py |
Adjust Stage process() return type annotation (currently introduces an invalid AsyncGenerator generic). |
tests/test_local_filesystem_component.py |
Make UTF-8 test setup use implicit .encode() instead of explicit UTF-8. |
tests/fixtures/helpers.py |
Switch Callable import to collections.abc. |
astrbot/utils/__init__.py |
Remove empty __init__.py. |
| self, | ||
| event: AstrMessageEvent, | ||
| ) -> None | AsyncGenerator[None, None]: | ||
| ) -> None | AsyncGenerator[None]: |
There was a problem hiding this comment.
collections.abc.AsyncGenerator expects two type parameters (yield type, send type). Using AsyncGenerator[None] is not a valid generic specialization for type checkers and is inconsistent with other Stage implementations in this repo (which use AsyncGenerator[None, None]). Consider changing this back to None | AsyncGenerator[None, None] (or switching to AsyncIterator[None] if you don’t need .asend() typing) and keep the docstring’s return type in sync.
| ) -> None | AsyncGenerator[None]: | |
| ) -> None | AsyncGenerator[None, None]: |
| skill_path = tmp_path / "skills" / "demo.txt" | ||
| skill_path.parent.mkdir(parents=True, exist_ok=True) | ||
| skill_path.write_bytes("技能内容".encode("utf-8")) | ||
| skill_path.write_bytes("技能内容".encode()) |
There was a problem hiding this comment.
This test is specifically about UTF-8 vs Windows locale fallbacks; using .encode() makes the intended encoding implicit. Consider keeping .encode('utf-8') here to make the test’s setup unambiguous.
| skill_path.write_bytes("技能内容".encode()) | |
| skill_path.write_bytes("技能内容".encode("utf-8")) |
There was a problem hiding this comment.
Code Review
This pull request updates the QQ Official platform adapter to use a unified appid for identifying the bot across different message types, replacing hardcoded strings. It also includes minor refactoring in the pipeline stage type hints and test helper imports. The review identified a potential IndexError risk in the channel message handling logic where message.mentions[0].id is used, and suggested maintaining consistency by using appid for At components in channel messages to ensure compatibility with plugins that rely on message chain metadata.
Closes #6741
Modifications / 改动点
1.
_parse_from_qqofficial方法新增appid参数appid: str参数self.platform.appid2. 修复
self_id的赋值逻辑"unknown_selfid"或"qq_official"appid,正确标识机器人身份3. 优化
At组件的添加逻辑At(qq="qq_official"),这是不正确的At(qq=appid)用于 @ 机器人自身涉及文件
astrbot/core/platform/sources/qqofficial/qqofficial_platform_adapter.pyastrbot/core/platform/sources/qqofficial_webhook/qo_webhook_adapter.pyThis is NOT a breaking change. / 这不是一个破坏性变更。
Screenshots or Test Results / 运行截图或测试结果
self_id使用appid后这使得一些需要获取头像的插件可以正常使用,可以使用https://q.qlogo.cn/qqapp/{self_id}/{user_id}/100以获取用户头像;以及避免了无效的 At 组件影响判断私聊和群聊的判断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
Update QQ Official platform message parsing to use the platform appid for self-identification and adjust mention handling for different message types.
New Features:
Bug Fixes:
Enhancements:
Tests: