Improve: 优化 QQ 下自动下载文件的问题
Motivation
现在 AstrBot 会下载每一个 QQ 协议端下发的文件并且没有定期消费机制,长期堆积可能导致用户磁盘被占满。
Modifications
‼️ BREAKING CHANGE: File 消息段的 file 字段将可能将下发 https 协议的链接。
Check
- [x] 😊 我的 Commit Message 符合良好的规范
- [ ] 👀 我的更改经过良好的测试
- [x] 🤓 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到了
requirements.txt和pyproject.toml文件相应位置。 - [x] 😮 我的更改没有引入恶意代码
好的,这是将拉取请求摘要翻译成中文的结果:
Sourcery 总结
优化 QQ 协议适配器的文件处理方式,更改文件处理和检索方式
新特性:
- 支持直接从 QQ 协议适配器检索文件 URL
Bug 修复:
- 避免不必要的本地文件下载
- 移除潜在的磁盘空间累积问题
增强功能:
- 修改 File 消息组件以支持基于 URL 的文件处理
- 改进不同消息类型(群消息和好友消息)的文件检索
日常维护:
- 更新文件处理逻辑,使其对不同的 QQ 协议客户端更具灵活性
Original summary in English
Summary by Sourcery
Optimize file handling for QQ protocol adapters by changing how files are processed and retrieved
New Features:
- Support for retrieving file URLs directly from QQ protocol adapters
Bug Fixes:
- Prevent unnecessary local file downloads
- Remove potential disk space accumulation issues
Enhancements:
- Modify File message component to support URL-based file handling
- Improve file retrieval for different message types (group and friend messages)
Chores:
- Update file handling logic to be more flexible with different QQ protocol clients
## 审查者指南
此拉取请求修改了 AIOCQHTTP 平台适配器,以防止自动下载通过 QQ 协议接收的文件。现在,它不再在收到文件时本地下载文件,而是使用 `get_group_file_url` 或 `get_private_file_url` 操作(对于 Napcat)检索文件 URL,或者直接使用提供的 HTTP URL(对于 Lagrange)。`File` 消息组件已更新以适应这些 URL。
### 文件级别更改
| 变更 | 详情 | 文件 |
| ------ | ------- | ----- |
| 将自动文件下载替换为 QQ 消息的 URL 检索。 | <ul><li>删除了自动从 HTTP URL 下载文件的代码。</li><li>将 `get_file` API 调用替换为 `get_group_file_url` 和 `get_private_file_url` 调用,以获取文件 URL 而不是下载。</li><li>更新了逻辑以直接使用检索到的 URL 创建 `File` 组件。</li><li>删除了本地文件路径处理和关联的已下载文件错误检查。</li></ul> | `astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py` |
| 更新了 File 组件以支持 URL。 | <ul><li>修改了 `File` 组件的 `file` 属性,以接受 URL 以及本地路径。</li><li>相应地更新了文档字符串和类型提示。</li></ul> | `astrbot/core/message/components.py` |
### 可能相关的 issue
- **#123**: PR 优化了 QQ 文件处理以使用 URL,从而解决了 dashscope image_urls 接收本地路径的问题。
---
<details>
<summary>提示和命令</summary>
#### 与 Sourcery 互动
- **触发新的审查:** 在拉取请求上评论 `@sourcery-ai review`。
- **继续讨论:** 直接回复 Sourcery 的审查评论。
- **从审查评论生成 GitHub issue:** 通过回复审查评论,要求 Sourcery 从审查评论创建一个 issue。您也可以回复审查评论并使用 `@sourcery-ai issue` 从中创建一个 issue。
- **生成拉取请求标题:** 在拉取请求标题中的任何位置写入 `@sourcery-ai` 以随时生成标题。您也可以在拉取请求上评论 `@sourcery-ai title` 以随时(重新)生成标题。
- **生成拉取请求摘要:** 在拉取请求正文中的任何位置写入 `@sourcery-ai summary` 以随时在您想要的位置生成 PR 摘要。您也可以在拉取请求上评论 `@sourcery-ai summary` 以随时(重新)生成摘要。
- **生成审查者指南:** 在拉取请求上评论 `@sourcery-ai guide` 以随时(重新)生成审查者指南。
- **解决所有 Sourcery 评论:** 在拉取请求上评论 `@sourcery-ai resolve` 以解决所有 Sourcery 评论。如果您已经解决了所有评论并且不想再看到它们,这将非常有用。
- **驳回所有 Sourcery 审查:** 在拉取请求上评论 `@sourcery-ai dismiss` 以驳回所有现有的 Sourcery 审查。如果您想重新开始新的审查,这将特别有用 - 不要忘记评论 `@sourcery-ai review` 以触发新的审查!
#### 自定义您的体验
访问您的 [仪表板](https://app.sourcery.ai) 以:
- 启用或禁用审查功能,例如 Sourcery 生成的拉取请求摘要、审查者指南等。
- 更改审查语言。
- 添加、删除或编辑自定义审查说明。
- 调整其他审查设置。
#### 获取帮助
- [联系我们的支持团队](mailto:[email protected]) 提出问题或反馈。
- 访问我们的 [文档](https://docs.sourcery.ai) 获取详细指南和信息。
- 通过在 [X/Twitter](https://x.com/SourceryAI)、[LinkedIn](https://www.linkedin.com/company/sourcery-ai/) 或 [GitHub](https://github.com/sourcery-ai) 上关注我们,与 Sourcery 团队保持联系。
</details>
Original review guide in English
Reviewer's Guide
The pull request modifies the AIOCQHTTP platform adapter to prevent automatic downloading of files received via the QQ protocol. Instead of downloading files locally upon receipt, it now retrieves file URLs using the get_group_file_url or get_private_file_url actions (for Napcat) or directly uses the provided HTTP URL (for Lagrange). The File message component has been updated to accommodate these URLs.
File-Level Changes
| Change | Details | Files |
|---|---|---|
| Replaced automatic file download with URL retrieval for QQ messages. |
|
astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py |
| Updated File component to support URLs. |
|
astrbot/core/message/components.py |
Possibly linked issues
- #123: PR optimizes QQ file handling to use URLs, which addresses the issue where dashscope image_urls receives local paths.
Tips and commands
Interacting with Sourcery
- Trigger a new review: Comment
@sourcery-ai reviewon the pull request. - Continue discussions: Reply directly to Sourcery's review comments.
- Generate a GitHub issue from a review comment: Ask Sourcery to create an
issue from a review comment by replying to it. You can also reply to a
review comment with
@sourcery-ai issueto create an issue from it. - Generate a pull request title: Write
@sourcery-aianywhere in the pull request title to generate a title at any time. You can also comment@sourcery-ai titleon the pull request to (re-)generate the title at any time. - Generate a pull request summary: Write
@sourcery-ai summaryanywhere in the pull request body to generate a PR summary at any time exactly where you want it. You can also comment@sourcery-ai summaryon the pull request to (re-)generate the summary at any time. - Generate reviewer's guide: Comment
@sourcery-ai guideon the pull request to (re-)generate the reviewer's guide at any time. - Resolve all Sourcery comments: Comment
@sourcery-ai resolveon the pull request to resolve all Sourcery comments. Useful if you've already addressed all the comments and don't want to see them anymore. - Dismiss all Sourcery reviews: Comment
@sourcery-ai dismisson the pull request to dismiss all existing Sourcery reviews. Especially useful if you want to start fresh with a new review - don't forget to comment@sourcery-ai reviewto trigger a new review!
Customizing Your Experience
Access your dashboard to:
- Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others.
- Change the review language.
- Add, remove or edit custom review instructions.
- Adjust other review settings.
Getting Help
- Contact our support team for questions or feedback.
- Visit our documentation for detailed guides and information.
- Keep in touch with the Sourcery team by following us on X/Twitter, LinkedIn or GitHub.
其实可以保持file属性为本地路径, 只不过默认为空, 加一个url属性, 然后提供一个方法, 从url下载文件, 并存储到astrbot的data/download里面, 并把这个路径返回(并存储到file属性里面), 这样的话原来的file属性仍然是本地路径, 要使用的时候才把文件下载并给file赋值, 这样怎么样?
其实可以保持file属性为本地路径, 只不过默认为空, 加一个url属性, 然后提供一个方法, 从url下载文件, 并存储到astrbot的data/download里面, 并把这个路径返回(并存储到file属性里面), 这样的话原来的file属性仍然是本地路径, 要使用的时候才把文件下载并给file赋值, 这样怎么样?
确实可行,加个property兼容一下
@anka-afk 实现下看看?
其实可以保持file属性为本地路径, 只不过默认为空, 加一个url属性, 然后提供一个方法, 从url下载文件, 并存储到astrbot的data/download里面, 并把这个路径返回(并存储到file属性里面), 这样的话原来的file属性仍然是本地路径, 要使用的时候才把文件下载并给file赋值, 这样怎么样?
确实可行,加个property兼容一下
@anka-afk 实现下看看?
收到