From edbf7c04760f51cba65e521d18fc451da85f49fd Mon Sep 17 00:00:00 2001 From: Rudy Celekli Date: Fri, 23 Oct 2026 19:14:52 -0400 Subject: [PATCH] fix(respond): keep platform-specific components when checking for empty chains Co-authored-by: Cursor --- astrbot/core/pipeline/respond/stage.py | 11 +++---- tests/unit/test_respond_stage_empty_chain.py | 34 ++++++++++++++++++++ 2 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 tests/unit/test_respond_stage_empty_chain.py diff --git a/astrbot/core/pipeline/respond/stage.py b/astrbot/core/pipeline/respond/stage.py index fa90ec70e41..115b33169bc 100644 --- a/astrbot/core/pipeline/respond/stage.py +++ b/astrbot/core/pipeline/respond/stage.py @@ -142,12 +142,11 @@ async def _is_empty_message_chain(self, chain: list[BaseMessageComponent]) -> bo return True for comp in chain: - comp_type = type(comp) - - # 检查组件类型是否在字典中 - if comp_type in self._component_validators: - if self._component_validators[comp_type](comp): - return False + validator = self._component_validators.get(type(comp)) + # Platform-specific components (e.g. Discord embeds) have no + # validator here; leave them for the platform adapter to handle. + if validator is None or validator(comp): + return False # 如果所有组件都为空 return True diff --git a/tests/unit/test_respond_stage_empty_chain.py b/tests/unit/test_respond_stage_empty_chain.py new file mode 100644 index 00000000000..b79aa75b071 --- /dev/null +++ b/tests/unit/test_respond_stage_empty_chain.py @@ -0,0 +1,34 @@ +import pytest + +import astrbot.core.message.components as Comp +from astrbot.core.message.components import BaseMessageComponent +from astrbot.core.pipeline.respond.stage import RespondStage + + +class _PlatformCard(BaseMessageComponent): + type: str = "platform_card" + title: str = "" + + +@pytest.mark.asyncio +async def test_platform_specific_component_is_not_empty(): + stage = RespondStage() + + assert await stage._is_empty_message_chain([_PlatformCard(title="t")]) is False + assert ( + await stage._is_empty_message_chain([Comp.Plain(text=" "), _PlatformCard()]) + is False + ) + + +@pytest.mark.asyncio +async def test_builtin_empty_components_are_still_empty(): + stage = RespondStage() + + assert await stage._is_empty_message_chain([]) is True + assert ( + await stage._is_empty_message_chain( + [Comp.Plain(text=" "), Comp.Image(file="")] + ) + is True + )