feat: split oversized forwarded message nodes#8798
feat: split oversized forwarded message nodes#8798Sisyphbaous-DT-Project wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The default values for
forward_node_max_length/forward_node_hard_limitare hard-coded in bothdefault.pyandResultDecorateStage.initialize; consider centralizing these defaults (e.g., module-level constants or reading from config) to avoid future drift. - The logic for constructing
forward_split_patternlargely duplicates the segmented reply splitting setup; consider extracting a shared helper to build the regex pattern so the two code paths stay consistent when split-word rules evolve.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The default values for `forward_node_max_length`/`forward_node_hard_limit` are hard-coded in both `default.py` and `ResultDecorateStage.initialize`; consider centralizing these defaults (e.g., module-level constants or reading from config) to avoid future drift.
- The logic for constructing `forward_split_pattern` largely duplicates the segmented reply splitting setup; consider extracting a shared helper to build the regex pattern so the two code paths stay consistent when split-word rules evolve.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Code Review
This pull request introduces auto-forward node splitting for long replies, allowing messages to be split into multiple forward nodes based on target and hard length limits while preferring natural breakpoints (like punctuation and newlines). It updates the default configuration, localization files, and pipeline processing logic, and adds comprehensive unit tests. The reviewer identified a potential boundary bug in the _find_forward_split_pos method where a breakpoint crossing the target length boundary could be missed, and suggested a simplified, single-pass regex matching approach to resolve it.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
|
Thanks @sourcery-ai. I addressed the default-value drift risk in adea231 by centralizing the forward node defaults in For the split-pattern construction, I kept the regex construction inline for now because the repository contribution guide explicitly prefers avoiding extra helpers unless the reuse or complexity clearly warrants it. The forward splitter still reuses the configured |
修改了当前的合并转发的功能,加上了合并消息内按照设置分段的功能,用来防止单条消息字数过多导致的超过qq单消息字数上限的限制而报错,具体更改请看 PR 内容:
QQ/NapCat 在发送合并转发消息时,如果单个转发
Node里包含过长的纯文本,可能会在 aiocqhttp 调用send_private_forward_msg时失败,出现类似retcode=1200的错误。本 PR 保留现有
platform_settings.forward_threshold的含义,只在触发自动合并转发后,把长文本拆成多个较短的转发节点,避免单个节点过长。Modifications / 改动点
新增两个平台配置项:
platform_settings.forward_node_max_length:单个转发节点的目标文本长度。platform_settings.forward_node_hard_limit:单个转发节点的文本硬上限。兼容旧配置:旧配置缺少新字段时自动使用默认值,不要求用户手动迁移配置文件。
配置值非法时自动回退到默认值。
如果
forward_node_max_length大于forward_node_hard_limit,自动收敛到硬上限并记录 warning。合并转发节点分段时复用
segmented_reply.split_words,并额外支持换行作为自然断点。aiocqhttp 自动合并转发时,生成
Nodes([...]),内部包含多个Node,不再把整段长文本塞进一个Node。分段规则优先在目标长度之后、硬上限以内寻找自然断点;找不到再向目标长度之前回退;仍找不到则按硬上限强制切分。
保留非纯文本消息组件的原始顺序,避免图片、表情、At、Reply 等组件因分段而重复或丢失。
如果消息链里已经包含
Node或Nodes,跳过自动转换,避免二次包装。WebUI 配置元数据和中/英/俄三份 i18n 文案同步补充新配置项说明。
新增单元测试,覆盖切分点选择、节点构建、装饰阶段转换、配置规整和混合组件处理。
This is NOT a breaking change. / 这不是一个破坏性变更。
Screenshots or Test Results / 运行截图或测试结果
本地验证命令:
结果:
结果:
结果:通过。
结果:通过。
WebUI 构建验证:
结果:
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
Split long QQ/NapCat auto-forward messages into multiple shorter forward nodes to avoid single-node length limits while preserving existing behavior for other platforms and message types.
New Features:
Enhancements:
Tests: