Skip to content

Comments

fix: 修复仅发送 JSON 消息段时的空消息回复报错#5208

Merged
Soulter merged 3 commits intoAstrBotDevs:masterfrom
NanoRocky:master
Feb 19, 2026
Merged

fix: 修复仅发送 JSON 消息段时的空消息回复报错#5208
Soulter merged 3 commits intoAstrBotDevs:masterfrom
NanoRocky:master

Conversation

@NanoRocky
Copy link
Contributor

@NanoRocky NanoRocky commented Feb 18, 2026

修复发送 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 / 检查清单

  • 😊 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。/ If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
  • 👀 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。/ My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
  • 🤓 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到了 requirements.txtpyproject.toml 文件相应位置。/ 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.txt and pyproject.toml.
  • 😮 我的更改没有引入恶意代码。/ My changes do not introduce malicious code.

A short story

Image_1771415347973_644

close #5198

Co-authored-by: Pizero zhaory200707@outlook.com

Summary by Sourcery

确保在响应阶段正确地将各种组件类型视为非空,从而在发送过程中不会跳过有效消息。

Bug Fixes(错误修复):

  • 修复 JSON 卡片消息在响应阶段被错误地视为为空并被跳过的问题。

Enhancements(功能增强):

  • 为更多组件类型(share、music、forward、location、contact、shake、dice、RPS、unknown)添加完整性检查,以确保它们能够正确参与发送管线。
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:

  • Fix JSON card messages being incorrectly treated as empty and skipped during the respond stage.

Enhancements:

  • Add completeness checks for additional component types (share, music, forward, location, contact, shake, dice, RPS, unknown) so they participate correctly in the send pipeline.

· 补全 JSON 消息判断,修复发送 JSON 消息时遇到 “消息为空,跳过发送阶段” 的问题。
· 顺带补全其它消息类型判断。
Co-authored-by: Pizero <zhaory200707@outlook.com>
Copilot AI review requested due to automatic review settings February 18, 2026 12:52
@auto-assign auto-assign bot requested review from Fridemn and Soulter February 18, 2026 12:52
@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Feb 18, 2026
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗨,我在这里给出了一些总体反馈:

  • 添加到 message_is_not_empty_checker 的验证 lambda 现在变得相当复杂(尤其是 Comp.Music);可以考虑把这些逻辑提取成具名的辅助函数,或者作为组件上的方法,以提升可读性,并保持 stage 映射本身是声明式的。
  • 对于一些新的检查(例如 Comp.ShareComp.MusicComp.ContactComp.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` 或空字符串本身可能是合法值。

Sourcery 对开源项目是免费的——如果你觉得我们的评审有帮助,欢迎分享 ✨
帮我变得更有用!请在每条评论上点击 👍 或 👎,我会根据你的反馈改进后续的评审。
Original comment in English

Hey - I've left some high level feedback:

  • 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.
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.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@dosubot
Copy link

dosubot bot commented Feb 18, 2026

Related Documentation

Checked 1 published document(s) in 1 knowledge base(s). No updates required.

How did I do? Any feedback?  Join Discord

@dosubot dosubot bot added the area:core The bug / feature is about astrbot's core, backend label Feb 18, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@pizeroLOL
Copy link
Contributor

@sourcery-ai review

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Feb 18, 2026

Hi @pizeroLOL! 👋

Only authors and team members can run @sourcery-ai commands on public repos.

@SourceryAI
Copy link

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 ✨

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Feb 19, 2026
@Soulter Soulter merged commit 651a064 into AstrBotDevs:master Feb 19, 2026
6 checks passed
@Soulter Soulter changed the title Fix Register_Stage fix: 修复仅发送 JSON 消息段时的空消息回复报错 Feb 19, 2026
astrbot-doc-agent bot pushed a commit to AstrBotDevs/AstrBot-docs that referenced this pull request Feb 19, 2026
@astrbot-doc-agent
Copy link

Generated docs update PR (pending manual review):
AstrBotDevs/AstrBot-docs#130
Trigger: PR merged


AI change summary:

  • 更新 zh/dev/star/guides/send-message.md 与 en/dev/star/guides/send-message.md,补充关于发送 JSON 消息段的相关说明。
  • 更新 zh/dev/star/guides/listen-message-event.md,优化消息事件监听的开发指南。
  • 更新 zh/dev/star/plugin.md,同步插件开发基础文档。
  • i18n 状态:send-message.md 已同步更新中英文版本;listen-message-event.md 与 plugin.md 缺失英文对应更新(TODO)。

Experimental bot notice:

  • This output is generated by AstrBot-Doc-Agent for review only.
  • It does not represent the final documentation form.

Raven95676 added a commit to Raven95676/AstrBot_Rdev that referenced this pull request Feb 20, 2026
- 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core The bug / feature is about astrbot's core, backend lgtm This PR has been approved by a maintainer size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] 发不出 Json 消息

4 participants