From 6b1e34da63a0d1b61eedac318281ccc9d55b16aa Mon Sep 17 00:00:00 2001 From: Ju4tCode <42488585+yanyongyu@users.noreply.github.com> Date: Sun, 14 Jan 2024 14:49:05 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20Fix:=20=E4=BF=AE=E5=A4=8D=20`echo`=20?= =?UTF-8?q?=E5=8F=91=E9=80=81=E7=A9=BA=E6=B6=88=E6=81=AF=20(#2525)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nonebot/plugins/echo.py | 3 ++- tests/test_echo.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 tests/test_echo.py 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)