🐛 Fix: 修复 echo 发送空消息 (#2525)

This commit is contained in:
Ju4tCode 2024-01-14 14:49:05 +08:00 committed by GitHub
parent ccf9597102
commit 6b1e34da63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 1 deletions

View File

@ -19,4 +19,5 @@ echo = on_command("echo", to_me())
@echo.handle() @echo.handle()
async def handle_echo(message: Message = CommandArg()): async def handle_echo(message: Message = CommandArg()):
if any((not seg.is_text()) or str(seg) for seg in message):
await echo.send(message=message) await echo.send(message=message)

33
tests/test_echo.py Normal file
View File

@ -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)