Skip to content

feat: 缓存目录可配置与过期清理、reply 三层解析、接收方向转发自动合并 - #112

Merged
This-is-XiaoDeng merged 5 commits into
ITCraftDevelopmentTeam:masterfrom
This-is-XiaoDeng:feat/cache-config-and-reply-resolve
Aug 14, 2026
Merged

feat: 缓存目录可配置与过期清理、reply 三层解析、接收方向转发自动合并#112
This-is-XiaoDeng merged 5 commits into
ITCraftDevelopmentTeam:masterfrom
This-is-XiaoDeng:feat/cache-config-and-reply-resolve

Conversation

@This-is-XiaoDeng

@This-is-XiaoDeng This-is-XiaoDeng commented Aug 13, 2026

Copy link
Copy Markdown
Member

改动内容

  1. 缓存目录可配置:新增 system.cache_dir(默认 .cache),全部硬编码路径替换为 utils/cache.py 助手;database 未配置时自动使用缓存目录下的 onedisc.db(替换原 :memory: 默认,避免重启丢失)
  2. 缓存过期清理:新增 system.cache 配置(files_ttl / url_cache_ttl / db_ttl / cleanup_interval,默认不过期),启动后定时清理,清理逻辑避开索引 json
  3. reply 段三层解析:cached_messages → 本地 DB(Message 表构造 discord.MessageReference)→ 同频道 REST 预检,失败维持警告+忽略
  4. 接收方向转发自动合并:同一频道同一发送者在窗口内(merge_forward_interval,默认 500ms)的 Discord 转发消息自动合并为一条 OneBot V11 forward 上报;get_forward_msg 动作通过第一条消息(id 编码「频道id_消息id」)调 Discord API 拉取上下文重建(含翻页),无状态、重启不丢;system.merge_forward 可开关(默认开启)
  5. 测试规范:测试移入 tests/ 目录并 pytest 化(conftest.py 自动处理 CI 无配置文件环境),新增 test 依赖组与独立 test.yml workflow(PR + master 触发)

测试

  • tests/test_cache_and_reply.py:10 例
  • tests/test_forward_merge.py:18 例(含翻页拉取、序列中断、非法 id)
  • tests/test_native_forward.py:12 例(回归)
  • 共 40 例,本地与 CI(test workflow)全部通过

文档

  • docs/config.md:database / cache_dir / cache / merge_forward / merge_forward_interval 配置说明
  • docs/diff-v11.mdget_forward_msg 由「不支持」更正为「仅支持查询自动合并产生的消息」

- system.cache_dir 支持修改缓存目录(默认 .cache),database 未配置时自动使用缓存目录下的 onedisc.db
- system.cache 支持配置 files/url_cache/db 三类缓存过期时间(默认不过期)与清理间隔,启动后定时自动清理
- reply 段解析升级为三层:cached_messages → 本地 DB → 同频道 REST 预检
- 接收方向(Discord → OneBot)转发消息自动合并:同一频道同一发送者窗口内(默认 500ms)的转发合并为一条 forward 上报,get_forward_msg 通过第一条消息调 Discord API 拉取上下文无状态重建
- 测试:test_cache_and_reply(10 例)、test_forward_merge(33 例)、test_native_forward(13 例)全部通过
- docs/config.md 与 docs/diff-v11.md 同步更新
@github-actions
github-actions Bot requested a review from montmorill August 13, 2026 23:56
- 根目录 test_*.py 移入 tests/,改写为 pytest 风格(async def + assert),新增 conftest.py(CI 环境自动创建 dummy config.json、清理 .cache 副作用)
- pyproject.toml 新增 [tool.pytest.ini_options](testpaths/pythonpath/asyncio_mode)与 test 依赖组(pytest、pytest-asyncio)
- ci.yml 新增 test job:poetry install --only main,test + pytest(不装 nuitka 等构建依赖)
- 本地验证 40 例全部通过
@This-is-XiaoDeng
This-is-XiaoDeng merged commit 91a38f5 into ITCraftDevelopmentTeam:master Aug 14, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant