Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions astrbot/core/pipeline/respond/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions tests/unit/test_respond_stage_empty_chain.py
Original file line number Diff line number Diff line change
@@ -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
)