Add support for Json, Xml, and other components#5205
Closed
NanoRocky wants to merge 6 commits intoAstrBotDevs:masterfrom
Closed
Add support for Json, Xml, and other components#5205NanoRocky wants to merge 6 commits intoAstrBotDevs:masterfrom
NanoRocky wants to merge 6 commits intoAstrBotDevs:masterfrom
Conversation
Contributor
There was a problem hiding this comment.
Hey - 我发现了 1 个问题,并留下了一些整体性反馈:
- 对于
Comp.Location,使用bool(comp.lat and comp.lon)会把0当作空值处理,但(0, 0)是一个合法坐标;建议改为显式检查is not None,以避免在赤道/本初子午线上的位置被错误丢弃。 - 对于
id和type这类字段(例如Comp.Music、Comp.Forward、Comp.Contact),简单使用真值判断会把0或空枚举错误地视为缺失;如果0/假值是合法标识符,建议改用显式的is not None检查。
给 AI Agent 的提示
Please address the comments from this code review:
## Overall Comments
- For `Comp.Location`, using `bool(comp.lat and comp.lon)` will treat `0` as empty even though `(0, 0)` is a valid coordinate; consider checking explicitly for `is not None` instead to avoid dropping locations at the equator/prime-meridian.
- For fields like `id` and `type` (e.g., `Comp.Music`, `Comp.Forward`, `Comp.Contact`), using simple truthiness checks can incorrectly treat `0` or empty enums as missing; prefer explicit `is not None` checks if `0`/falsy values are valid identifiers.
## Individual Comments
### Comment 1
<location> `astrbot/core/pipeline/respond/stage.py:41` </location>
<code_context>
+ Comp.Share: lambda comp: bool(comp.url) or bool(comp.title),
+ Comp.Music: lambda comp: (comp.id and comp.type and comp.type != 'custom') or (comp.type == 'custom' and comp.url and comp.audio and comp.title), # 音乐分享
+ Comp.Forward: lambda comp: bool(comp.id), # 合并转发
+ Comp.Location: lambda comp: bool(comp.lat and comp.lon), # 位置
+ Comp.Contact: lambda comp: bool(comp.type and comp.id), # 推荐好友 or 群
+ Comp.Shake: lambda _: True, # 窗口抖动(戳一戳)
</code_context>
<issue_to_address>
**issue (bug_risk):** 使用真值判断 lat/lon 会把 0 当成非法值,很可能导致合法坐标被判定为无效。
`bool(comp.lat and comp.lon)` 在任一值为 `0`/`0.0`(赤道、本初子午线)时,会对合法坐标返回 `False`,从而将其标记为无效。如果允许 `0`,请改用显式的 `None` 检查,例如 `comp.lat is not None and comp.lon is not None`,或使用其他基于哨兵值的方式。
</issue_to_address>帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进 Review 质量。
Original comment in English
Hey - I've found 1 issue, and left some high level feedback:
- For
Comp.Location, usingbool(comp.lat and comp.lon)will treat0as empty even though(0, 0)is a valid coordinate; consider checking explicitly foris not Noneinstead to avoid dropping locations at the equator/prime-meridian. - For fields like
idandtype(e.g.,Comp.Music,Comp.Forward,Comp.Contact), using simple truthiness checks can incorrectly treat0or empty enums as missing; prefer explicitis not Nonechecks if0/falsy values are valid identifiers.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- For `Comp.Location`, using `bool(comp.lat and comp.lon)` will treat `0` as empty even though `(0, 0)` is a valid coordinate; consider checking explicitly for `is not None` instead to avoid dropping locations at the equator/prime-meridian.
- For fields like `id` and `type` (e.g., `Comp.Music`, `Comp.Forward`, `Comp.Contact`), using simple truthiness checks can incorrectly treat `0` or empty enums as missing; prefer explicit `is not None` checks if `0`/falsy values are valid identifiers.
## Individual Comments
### Comment 1
<location> `astrbot/core/pipeline/respond/stage.py:41` </location>
<code_context>
+ Comp.Share: lambda comp: bool(comp.url) or bool(comp.title),
+ Comp.Music: lambda comp: (comp.id and comp.type and comp.type != 'custom') or (comp.type == 'custom' and comp.url and comp.audio and comp.title), # 音乐分享
+ Comp.Forward: lambda comp: bool(comp.id), # 合并转发
+ Comp.Location: lambda comp: bool(comp.lat and comp.lon), # 位置
+ Comp.Contact: lambda comp: bool(comp.type and comp.id), # 推荐好友 or 群
+ Comp.Shake: lambda _: True, # 窗口抖动(戳一戳)
</code_context>
<issue_to_address>
**issue (bug_risk):** Using truthiness for lat/lon will treat 0 as invalid, which likely breaks valid coordinates.
`bool(comp.lat and comp.lon)` will evaluate to `False` for valid coordinates where either value is `0`/`0.0` (equator, prime meridian), marking them invalid. If `0` is allowed, use explicit `None` checks instead, e.g. `comp.lat is not None and comp.lon is not None`, or another sentinel-based approach.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aims to fix issue #5198 where JSON messages were being skipped with a "消息为空,跳过发送阶段" error. The root cause was that the _component_validators dictionary in RespondStage was missing validators for several component types, causing those components to be treated as empty and skipped during the send stage.
Changes:
- Added 12 new component type validators to the
_component_validatorsdictionary inRespondStage - Validators added for: Json, Xml, Share, Music, Forward, Location, Contact, Shake, Anonymous, Dice, Rps, and Unknown component types
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
修复发送 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