mirror of
https://github.com/nonebot/nonebot2.git
synced 2024-11-27 18:45:05 +08:00
🐛 Fix: 修复 echo
发送空消息 (#2525)
This commit is contained in:
parent
ccf9597102
commit
6b1e34da63
@ -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
33
tests/test_echo.py
Normal 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)
|
Loading…
Reference in New Issue
Block a user