Conversation
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
审查者指南通过安全的非空文本拼接、引用正文回退和消息入口异常隔离,修复引用合并转发、附件及空卡片触发的崩溃与 traceback 外发问题,并补充 @ 扫描兼容性及对应单元测试。 安全消息解析与异常隔离时序图sequenceDiagram
participant Event as AstrMessageEvent
participant Plugin as ParserPlugin
participant Utils as core.utils
participant Logger as Logger
Event->>Plugin: on_message(event)
Plugin->>Plugin: _handle_message(event)
Plugin->>Plugin: scan Plain and At segments
Plugin->>Utils: join_nonempty_texts(reply_texts)
Utils-->>Plugin: reply_text
alt reply_text exists
Plugin->>Plugin: use reply_text
else reply_text is empty
Plugin->>Plugin: keep current message text
end
alt parsing raises Exception
Plugin->>Logger: logger.exception(解析消息失败,已跳过)
Logger-->>Plugin: traceback stays in logs
else parsing succeeds
Plugin-->>Event: continue processing without traceback message
end
安全引用文本回退流程图flowchart TD
A[引用链包含消息段] --> B[收集 Plain.text 和 extract_json_url 结果]
B --> C["join_nonempty_texts(reply_texts)"]
C --> D{存在非空引用正文?}
D -->|是| E[使用引用正文]
D -->|否| F[保留当前消息正文]
E --> G[继续解析]
F --> G
G --> H{发生异常?}
H -->|是| I[记录日志并跳过消息]
H -->|否| J[正常完成]
文件级变更
提示与命令与 Sourcery 互动
自定义使用体验访问你的控制面板以:
获取帮助Original review guide in EnglishReviewer's Guide通过安全的非空文本拼接、引用正文回退和消息入口异常隔离,修复引用合并转发、附件及空卡片触发的崩溃与 traceback 外发问题,并补充 @ 扫描兼容性及对应单元测试。 Sequence diagram for safe message parsing and error isolationsequenceDiagram
participant Event as AstrMessageEvent
participant Plugin as ParserPlugin
participant Utils as core.utils
participant Logger as Logger
Event->>Plugin: on_message(event)
Plugin->>Plugin: _handle_message(event)
Plugin->>Plugin: scan Plain and At segments
Plugin->>Utils: join_nonempty_texts(reply_texts)
Utils-->>Plugin: reply_text
alt reply_text exists
Plugin->>Plugin: use reply_text
else reply_text is empty
Plugin->>Plugin: keep current message text
end
alt parsing raises Exception
Plugin->>Logger: logger.exception(解析消息失败,已跳过)
Logger-->>Plugin: traceback stays in logs
else parsing succeeds
Plugin-->>Event: continue processing without traceback message
end
Flow diagram for safe quoted-text fallbackflowchart TD
A[引用链包含消息段] --> B[收集 Plain.text 和 extract_json_url 结果]
B --> C["join_nonempty_texts(reply_texts)"]
C --> D{存在非空引用正文?}
D -->|是| E[使用引用正文]
D -->|否| F[保留当前消息正文]
E --> G[继续解析]
F --> G
G --> H{发生异常?}
H -->|是| I[记录日志并跳过消息]
H -->|否| J[正常完成]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
你好——我发现了 1 个问题
面向 AI 代理的提示
请处理本次代码审查中的评论:
## 单独评论
### 评论 1
<location path="core/utils.py" line_range="235-236" />
<code_context>
return unquote(value.strip().replace("\\/", "/"))
+def join_nonempty_texts(parts: list[object]) -> str:
+ """拼接文本,跳过 None 和空串,避免 str.join 遇到空值崩溃。"""
+ texts: list[str] = []
+ for part in parts:
+ if not part:
+ continue
+ texts.append(str(part))
+ return "".join(texts)
+
</code_context>
<issue_to_address>
**小问题(潜在错误):** join_nonempty_texts 会丢弃所有假值,而不仅仅是 None 和空字符串;parts 中有效的 0、False 或其他类似文本的假值会被静默省略。
**触发条件:** 调用方在 parts 中传入假值的非字符串值时。
**建议修复:** 在使用 str(part) 转换其余值之前,显式检查 `part is None or part == ""`。
```suggestion
if part is None or part == "":
continue
```
</issue_to_address>Original comment in English
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="core/utils.py" line_range="235-236" />
<code_context>
return unquote(value.strip().replace("\\/", "/"))
+def join_nonempty_texts(parts: list[object]) -> str:
+ """拼接文本,跳过 None 和空串,避免 str.join 遇到空值崩溃。"""
+ texts: list[str] = []
+ for part in parts:
+ if not part:
+ continue
+ texts.append(str(part))
+ return "".join(texts)
+
</code_context>
<issue_to_address>
**nitpick (bug_risk):** join_nonempty_texts drops every falsey value, not only None and the empty string; a valid 0, False, or other falsey text-like value in parts is silently omitted.
**Triggers:** When a caller passes a falsey non-string value in parts.
**Suggested fix:** Check explicitly for `part is None or part == ""` before converting the remaining values with `str(part)`.
```suggestion
if part is None or part == "":
continue
```
</issue_to_address>There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
Reviewed changes have no unresolved blocking issues.
Review effort: Lite
Findings: None
What changed in this PR
修复引用消息包含空内容时的解析崩溃,并避免异常堆栈发送到群聊。
Changes:
- 新增安全文本拼接,跳过空值。
- 引用无可解析文本时保留当前正文。
- 捕获消息处理异常并仅记录日志。
- 增加相关单元测试。
| File | Description |
|---|---|
tests/test_reply_text.py |
覆盖空值过滤与顺序保持 |
main.py |
调整消息处理、引用解析和 @ 扫描逻辑 |
core/utils.py |
新增非空文本拼接工具 |
CHANGELOG.md |
记录修复内容 |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
问题
开启
enable_reply_parse后,引用合并转发、附件或空文本卡片时,on_message会崩溃,堆栈被 AstrBot 发到群里。引用链里的 Json 段会走
extract_json_url(),抽不到 URL 时返回None。随后:触发:
异常从
on_message冒泡出去,群里就会看到完整 traceback。入站合并消息本身本来就不在解析范围内,但也不该因此把机器人打崩。修复
join_nonempty_texts(),拼接时跳过None和空串on_message捕获异常只写日志,不再把堆栈发到群里@时要求Plain.text存在,避免空文本段再踩一次复现
Fork
同一修复也在 fork 里:https://github.com/w1ndys/astrbot_plugin_parser(`v1.5.7-fix1`)。本 PR 不含 fork 的仓库地址 / 版本号改动。
Sourcery 总结
修复引用解析对空消息内容的处理,避免异常导致机器人崩溃或向群聊泄露堆栈。
错误修复:
改进:
@提及扫描对空文本消息片段的兼容性。测试:
Original summary in English
Sourcery 摘要
增强回复解析功能,使其能够处理引用内容为空的情况,并防止处理失败时在群聊中暴露 traceback。
Bug 修复:
改进:
测试:
Original summary in English
Summary by Sourcery
Harden reply parsing against empty referenced content and prevent processing failures from exposing tracebacks in group chats.
Bug Fixes:
Enhancements:
Tests: