Repository navigation
Conversation
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="astrbot/core/platform/sources/discord/discord_platform_event.py" line_range="393-395" />
<code_context>
+ elif isinstance(i, Video):
+ try:
+ path = Path(await i.convert_to_file_path())
+ video_bytes = await asyncio.to_thread(path.read_bytes)
+ files.append(
+ discord.File(BytesIO(video_bytes), filename=path.name),
+ )
+ except Exception:
</code_context>
<issue_to_address>
**Large videos exhaust memory**
When a video is large or several video uploads are processed concurrently, `path.read_bytes()` loads each entire video into memory, and `BytesIO(video_bytes)` retains another buffer through upload. The combined memory use can exhaust the bot process’s memory and interrupt service.
Stream the video file to Discord instead of loading it into `video_bytes` and wrapping it in `BytesIO`.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 1 finding to address first, and if the path conversion or attachment handling is wrong, Discord could receive an incorrect video or a malformed outbound message that cannot be undone by reverting the code. The impact is bounded to messages sent while the change is deployed, but those already-sent messages would remain.}}burugburuWinvalid_formats maybe score must integer. Good. 极速赛车. Wait.
Blocking findings: astrbot/core/platform/sources/discord/discord_platform_event.py:395
|
@sourcery-ai review |
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="astrbot/core/platform/sources/discord/discord_platform_event.py" line_range="393" />
<code_context>
+ elif isinstance(i, Video):
+ try:
+ path = Path(await i.convert_to_file_path())
+ files.append(discord.File(path, filename=path.name))
+ except Exception:
+ logger.warning(
</code_context>
<issue_to_address>
**Remote videos get generated names**
When a video URL is sent, `Video.convert_to_file_path()` resolves URL videos to a generated temporary path, and `_parse_to_discord` uses that path’s basename as the attachment filename. Discord therefore shows names such as `media_video_<id>.mp4` instead of the source video’s filename.
Choose the attachment filename from the source URL’s path when available, with a suitable fallback for URLs without a filename.
</issue_to_address>Sourcery assessment
Approval pending. 1 finding to address first.
Blocking findings: astrbot/core/platform/sources/discord/discord_platform_event.py:393
|
@sourcery-ai review |
Discord silently drops
Videocomponents fromsend_message_to_userwhile the tool reports success. This change sends them as attachments, including when combined with text.Modifications / 改动点
Resolve videos through the existing
Video.convert_to_file_path()method and stream them as Discord attachments, preserving URL filenames when available.Cover local/URL videos and file uploads with and without text, plus URL filename decoding and fallback behavior.
This is NOT a breaking change. / 这不是一个破坏性变更。
Screenshots or Test Results / 运行截图或测试结果
Verification: run
pytest tests/test_discord_adapter.py tests/unit/test_message_tools.py -q(102 passed).ruff format .,ruff check ., andgit diff --checkpassed.Manual verification: send the same MP4 to the current Discord session using
video, then plain text +video; confirm the attachment arrives in both cases. Usefileas a control. Post-fix Discord verification is pending.Before
After
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 checked the affected WebUI instructions and screenshots in
docs/zhanddocs/enagainst the changed navigation, page structure, and labels, and updated them in this PR (or explained why no documentation update is needed). For renamed, moved, or merged entry points, I included an old entry → new entry mapping in the documentation and changelog./ 我已对照变化后的 WebUI 入口、页面结构和术语,核对并在本 PR 中更新
docs/zh和docs/en的相关操作说明与截图(或说明无需更新文档的原因)。入口改名、移动或合并时,已在文档和 changelog 中补充 旧入口 → 新入口 对照。🤓 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
Ensure Discord video content is delivered as attachments instead of silently dropped components.
Bug Fixes:
Enhancements:
Tests: