fix: 修复仅发送 JSON 消息段时的空消息回复报错#5208
Conversation
· 补全 JSON 消息判断,修复发送 JSON 消息时遇到 “消息为空,跳过发送阶段” 的问题。 · 顺带补全其它消息类型判断。 Co-authored-by: Pizero <zhaory200707@outlook.com>
There was a problem hiding this comment.
嗨,我在这里给出了一些总体反馈:
- 添加到
message_is_not_empty_checker的验证 lambda 现在变得相当复杂(尤其是Comp.Music);可以考虑把这些逻辑提取成具名的辅助函数,或者作为组件上的方法,以提升可读性,并保持 stage 映射本身是声明式的。 - 对于一些新的检查(例如
Comp.Share、Comp.Music、Comp.Contact、Comp.Location),建议在判断时显式地区分is not None和一般的 truthiness,这样更清晰也更不容易出错,特别是对 ID、坐标这类字段来说,0或空字符串本身可能是合法值。
给 AI Agents 的提示
请根据这次代码评审中的评论进行修改:
## 总体评论
- 添加到 `message_is_not_empty_checker` 的验证 lambda 现在变得相当复杂(尤其是 `Comp.Music`);可以考虑把这些逻辑提取成具名的辅助函数,或者作为组件上的方法,以提升可读性,并保持 stage 映射本身是声明式的。
- 对于一些新的检查(例如 `Comp.Share`、`Comp.Music`、`Comp.Contact`、`Comp.Location`),建议在判断时显式地区分 `is not None` 和一般的 truthiness,这样更清晰也更不容易出错,特别是对 ID、坐标这类字段来说,`0` 或空字符串本身可能是合法值。帮我变得更有用!请在每条评论上点击 👍 或 👎,我会根据你的反馈改进后续的评审。
Original comment in English
Hey - I've left some high level feedback:
- The validation lambdas added to
message_is_not_empty_checkerare getting fairly complex (especially forComp.Music); consider extracting these into named helper functions or methods on the component to improve readability and keep the stage mapping declarative. - For some of the new checks (e.g.,
Comp.Share,Comp.Music,Comp.Contact,Comp.Location), it may be clearer and less error-prone to be explicit aboutis not Nonevs. truthiness, especially for fields like IDs or coordinates where0or empty strings might be valid.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The validation lambdas added to `message_is_not_empty_checker` are getting fairly complex (especially for `Comp.Music`); consider extracting these into named helper functions or methods on the component to improve readability and keep the stage mapping declarative.
- For some of the new checks (e.g., `Comp.Share`, `Comp.Music`, `Comp.Contact`, `Comp.Location`), it may be clearer and less error-prone to be explicit about `is not None` vs. truthiness, especially for fields like IDs or coordinates where `0` or empty strings might be valid.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.
Pull request overview
This PR fixes a bug where JSON messages and other message types couldn't be sent due to missing entries in the _component_validators dictionary, which is used to determine if message components are empty before sending.
Changes:
- Added validation entries for 10 missing message component types (Json, Share, Music, Forward, Location, Contact, Shake, Dice, RPS, Unknown) to prevent "消息为空,跳过发送阶段" (message is empty, skip send stage) errors
|
@sourcery-ai review |
|
Hi @pizeroLOL! 👋 Only authors and team members can run @sourcery-ai commands on public repos. |
|
Hi @pizeroLOL! 👋 Only authors and team members can run @sourcery-ai commands on public repos. If you are a team member, install the @sourcery-ai bot to get access ✨ |
|
Generated docs update PR (pending manual review): AI change summary:
Experimental bot notice:
|
- Integrate active_event_registry register/unregister into new PipelineExecutor to restore AstrBotDevs#5225 (terminate active events on reset/new/del) - Add missing component validators (Json, Share, Music, Forward, Location, Contact, Shake, Dice, RPS, Unknown) to SendService to restore AstrBotDevs#5208 (JSON-only message empty reply error) - Invoke OnPluginErrorEvent hook in CommandDispatcher error path to restore AstrBotDevs#5192 (plugin error hook for custom error routing) - Pass text=comp.text when creating TTS Record to restore AstrBotDevs#5204 (voice_messages_forbidden fallback caption on Telegram)
修复发送 JSON 消息时遇到 “消息为空,跳过发送阶段” 的问题。
Modifications / 改动点
/astrbot/core/pipeline/respond/stage.py : 补全 JSON 消息判断,并顺带补全其它缺失的消息类型判断。
This is NOT a breaking change. / 这不是一个破坏性变更。
Screenshots or Test Results / 运行截图或测试结果
[2026-02-18 18:59:19.431] [Core] [INFO] [core.event_bus:59]: [default] [NapCat(aiocqhttp)] 皮皮喵酪灰/3525987739: 点歌1 [2026-02-18 18:59:19.432] [Core] [DBUG] [waking_check.stage:157]: enabled_plugins_name: ['*'] [2026-02-18 18:59:19.436] [Core] [DBUG] [method.star_request:44]: plugin -> session_controller - handle_session_control_agent [2026-02-18 18:59:19.436] [Core] [DBUG] [method.star_request:44]: plugin -> session_controller - handle_empty_mention [2026-02-18 18:59:19.436] [Core] [DBUG] [method.star_request:44]: plugin -> astrbot_plugin_meting - play_song_by_index [2026-02-18 18:59:19.718] [Plug] [INFO] [astrbot_plugin_meting.main:175]: 音乐卡片签名成功,发送卡片 [2026-02-18 18:59:19.719] [Plug] [INFO] [astrbot_plugin_meting.main:176]: 卡片数据: type=<ComponentType.Json: 'Json'> data={'app': 'com.tencent.music.lua', 'bizsrc': 'qqconnect.sdkshare_music', 'config': {'ctime': 1771411966, 'forward': 1, 'token': 'e79a964c581706afcbbfa0fb963e18eb', 'type': 'normal'}, 'extra': {'app_type': 1, 'appid': 100495085, 'uin': 3264925726}, 'meta': {'music': {'app_type': 1, 'appid': 100495085, 'ctime': 1771411966, 'desc': '小星星Aurora', 'jumpUrl': 'https://music.163.com/#/song?id=1351520305', 'musicUrl': 'https://metingapi.nanorocky.top/?server=netease&type=url&id=1351520305', 'preview': 'https://p3.music.126.net/-kDO5LiKki3bmeF21MaCuQ==/109951163917806959.jpg?param=320x320', 'tag': '网易云音乐', 'tagIcon': 'https://i.gtimg.cn/open/app_icon/00/49/50/85/100495085_100_m.png', 'title': '坠落星空', 'uin': 3264925726}}, 'prompt': '[分享]坠落星空', 'ver': '0.0.0.1', 'view': 'music'} [2026-02-18 18:59:19.719] [Core] [DBUG] [result_decorate.stage:165]: hook(on_decorating_result) -> meme_manager - on_decorating_result [2026-02-18 18:59:19.719] [Plug] [DBUG] [astrbot_plugin_meme_manager.main:766]: [meme_manager] on_decorating_result 开始处理 [2026-02-18 18:59:19.719] [Plug] [DBUG] [astrbot_plugin_meme_manager.main:914]: [meme_manager] on_decorating_result 处理完成 [2026-02-18 18:59:19.721] [Core] [INFO] [respond.stage:170]: Prepare to send - 皮皮喵酪灰/3525987739: [ComponentType.Json] [2026-02-18 18:59:19.844] [Core] [DBUG] [pipeline.context_utils:95]: hook(OnAfterMessageSentEvent) -> meme_manager - after_message_sent [2026-02-18 18:59:19.845] [Core] [DBUG] [pipeline.context_utils:95]: hook(OnAfterMessageSentEvent) -> astrbot - after_message_sent [2026-02-18 18:59:19.845] [Core] [DBUG] [method.star_request:44]: plugin -> meme_manager - handle_upload_image [2026-02-18 18:59:19.845] [Core] [DBUG] [method.star_request:44]: plugin -> astrbot - on_message [2026-02-18 18:59:19.845] [Core] [DBUG] [pipeline.scheduler:88]: pipeline 执行完毕。Checklist / 检查清单
requirements.txt和pyproject.toml文件相应位置。/ I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations inrequirements.txtandpyproject.toml.A short story
close #5198
Co-authored-by: Pizero zhaory200707@outlook.com
Summary by Sourcery
确保在响应阶段正确地将各种组件类型视为非空,从而在发送过程中不会跳过有效消息。
Bug Fixes(错误修复):
Enhancements(功能增强):
Original summary in English
Summary by Sourcery
Ensure respond stage correctly treats various component types as non-empty so valid messages are not skipped during sending.
Bug Fixes:
Enhancements: