Sorry, something went wrong.
There was a problem hiding this comment.
Hey - I've found 3 issues, and left some high level feedback:
Sorry, something went wrong.
| from .aiocqhttp_message_event import AiocqhttpMessageEvent | ||
|
|
||
|
|
||
| def _looks_like_resolved_media_ref(value: str) -> bool: |
There was a problem hiding this comment.
issue (complexity): Consider refactoring the new media resolution helpers into a small MediaResolver class with shared helpers and action templates to reduce duplication and make the control flow easier to follow.
You can reduce the new complexity without changing behavior by:
Instead of threading bot, message_type, group_id, seg_type through multiple helpers and call sites, wrap them in a small resolver. This keeps the public surface small while keeping functionality identical:
Call site becomes simpler and avoids repeated parameters:
This keeps all behavior but removes a lot of cross‑cutting arguments and makes the flow easier to follow.
You currently repeat:
across _pick_usable_media_source, _normalize_onebot_media_data, _resolve_onebot_file_reference.
Extract this into a single helper that returns either a normalized string or None:
Then simplify callers, e.g.:
and in the resolver:
This reduces branching and duplication without changing semantics.
The actions.extend([...]) pattern is verbose and repeated per candidate. You can describe the patterns once and instantiate them:
Then _resolve_onebot_file_reference (or MediaResolver._resolve_file_reference) becomes clearer:
This removes duplicated action construction logic and makes it obvious what variations exist.
These changes keep your new media resolution behavior intact, but:
Sorry, something went wrong.
There was a problem hiding this comment.
This pull request refactors media source resolution for Record and Video components and introduces a normalization layer in the aiocqhttp adapter to resolve OneBot V11 media references. Review feedback identifies a copy-paste error in the Record component where audio files were being saved with an image extension and suggests using Exception instead of BaseException for safer error handling.
Sorry, something went wrong.
| if source.startswith("base64://"): | ||
| bs64_data = source.removeprefix("base64://") | ||
| image_bytes = base64.b64decode(bs64_data) | ||
| file_path = os.path.join( | ||
| get_astrbot_temp_path(), f"recordseg_{uuid.uuid4()}.jpg" | ||
| ) | ||
| with open(file_path, "wb") as f: | ||
| f.write(image_bytes) | ||
| return os.path.abspath(file_path) |
There was a problem hiding this comment.
In the Record component, the temporary file is being saved with a .jpg extension and uses image_bytes, which is a copy-paste error from the Image component. Please fix the extension and variable names. Additionally, since this logic is similar to other attachment components, refactor it into a shared helper function to avoid code duplication. Ensure this functionality is accompanied by unit tests.
| if source.startswith("base64://"): | |
| bs64_data = source.removeprefix("base64://") | |
| image_bytes = base64.b64decode(bs64_data) | |
| file_path = os.path.join( | |
| get_astrbot_temp_path(), f"recordseg_{uuid.uuid4()}.jpg" | |
| ) | |
| with open(file_path, "wb") as f: | |
| f.write(image_bytes) | |
| return os.path.abspath(file_path) | |
| if source.startswith("base64://"): | |
| bs64_data = source.removeprefix("base64://") | |
| audio_bytes = base64.b64decode(bs64_data) | |
| file_path = os.path.join( | |
| get_astrbot_temp_path(), f"recordseg_{uuid.uuid4().hex}.amr" | |
| ) | |
| with open(file_path, "wb") as f: | |
| f.write(audio_bytes) | |
| return os.path.abspath(file_path) |
Sorry, something went wrong.
| for action, params in actions: | ||
| try: | ||
| ret = await bot.call_action(action=action, **params) | ||
| except BaseException: |
There was a problem hiding this comment.
Sorry, something went wrong.
Fixes #8049 .
修复 aiocqhttp / OneBot v11 场景下,引用消息中的语音、视频、文件媒体段在进入 AstrBot 后无法被正确消费的问题。
此前在 QQ/NapCat 的引用消息场景中,媒体段里的 file 字段经常只是平台内部文件名或引用值,例如 0f47835d687410ab50cfed981e80c15c.amr、BV1y9Gj6****.mp4,并不是 AstrBot 当前进程可直接访问的本地路径,也不是可直接下载的 URL。
旧逻辑会将这类 file 原样交给上层组件,导致:
本次修改将 quoted media 的修复前移到正确层级:
从而确保引用消息中的语音、视频、文件媒体段在进入后续 Agent / Provider / Plugin 链路前,就已经具备可直接消费的来源信息。
Modifications / 改动点
本次改动主要补齐了 aiocqhttp 引用媒体段的来源解析逻辑,并统一了 Record / Video 组件对多来源字段的消费方式。
核心改动包括:
在 astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py 中新增 OneBot 媒体来源规范化逻辑:
在 astrbot/core/message/components.py 中增强 Record 组件的 source 选择逻辑:
在 astrbot/core/message/components.py 中修正 Record 的 base64 临时文件落地逻辑:
在 astrbot/core/message/components.py 中增强 Video 组件的 source 选择逻辑:
在测试侧保留并补充了稳定的组件层单元测试,覆盖:
This is NOT a breaking change. / 这不是一个破坏性变更。
Screenshots or Test Results / 运行截图或测试结果
修复前引用语音消息时:
修复后不再报错。
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.txt and pyproject.toml.
/ 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到 requirements.txt 和 pyproject.toml 文件相应位置。
😮 My changes do not introduce malicious code.
/ 我的更改没有引入恶意代码。
Summary by Sourcery
Normalize aiocqhttp/OneBot v11 media sources in quoted messages so that audio, video, and file segments are resolved to directly consumable URLs or paths before reaching higher-level components.
Bug Fixes:
Enhancements:
Tests: