diff --git a/nonebot/plugins/echo.py b/nonebot/plugins/echo.py index 2b67c367..a9f38706 100644 --- a/nonebot/plugins/echo.py +++ b/nonebot/plugins/echo.py @@ -19,4 +19,5 @@ echo = on_command("echo", to_me()) @echo.handle() async def handle_echo(message: Message = CommandArg()): - await echo.send(message=message) + if any((not seg.is_text()) or str(seg) for seg in message): + await echo.send(message=message) diff --git a/tests/test_echo.py b/tests/test_echo.py new file mode 100644 index 00000000..f237f683 --- /dev/null +++ b/tests/test_echo.py @@ -0,0 +1,33 @@ +import pytest +from nonebug import App + +from utils import FakeMessage, FakeMessageSegment, make_fake_event + + +@pytest.mark.asyncio +async def test_echo(app: App): + from nonebot.plugins.echo import echo + + async with app.test_matcher(echo) as ctx: + bot = ctx.create_bot() + + message = FakeMessage("/echo 123") + event = make_fake_event(_message=message)() + ctx.receive_event(bot, event) + ctx.should_call_send(event, FakeMessage("123"), True, bot=bot) + + message = FakeMessageSegment.text("/echo 123") + FakeMessageSegment.image( + "test" + ) + event = make_fake_event(_message=message)() + ctx.receive_event(bot, event) + ctx.should_call_send( + event, + FakeMessageSegment.text("123") + FakeMessageSegment.image("test"), + True, + bot=bot, + ) + + message = FakeMessage("/echo") + event = make_fake_event(_message=message)() + ctx.receive_event(bot, event)