mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-07-17 03:20:54 +00:00
🐛 fix cannot reject preset arg
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
from nonebot import on_message
|
||||
from nonebot.adapters import Event
|
||||
from nonebot.params import ArgStr, Received, LastReceived
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot.adapters import Event, Message
|
||||
from nonebot.params import ArgStr, Received, EventMessage, LastReceived
|
||||
|
||||
test_handle = on_message()
|
||||
|
||||
@ -54,3 +55,19 @@ async def combine(a: str = ArgStr(), b: str = ArgStr(), r: Event = Received()):
|
||||
assert a == "text_next"
|
||||
assert b == "text_next"
|
||||
assert str(r.get_message()) == "text_next"
|
||||
|
||||
|
||||
test_preset = on_message()
|
||||
|
||||
|
||||
@test_preset.handle()
|
||||
async def preset(matcher: Matcher, message: Message = EventMessage()):
|
||||
matcher.set_arg("a", message)
|
||||
|
||||
|
||||
@test_preset.got("a")
|
||||
async def reject_preset(a: str = ArgStr()):
|
||||
if a == "text":
|
||||
await test_preset.reject_arg("a")
|
||||
|
||||
assert a == "text_next"
|
||||
|
@ -9,6 +9,7 @@ async def test_matcher(app: App, load_plugin):
|
||||
from plugins.matcher import (
|
||||
test_got,
|
||||
test_handle,
|
||||
test_preset,
|
||||
test_combine,
|
||||
test_receive,
|
||||
)
|
||||
@ -58,3 +59,10 @@ async def test_matcher(app: App, load_plugin):
|
||||
ctx.receive_event(bot, event_next)
|
||||
ctx.should_rejected()
|
||||
ctx.receive_event(bot, event_next)
|
||||
|
||||
assert len(test_preset.handlers) == 2
|
||||
async with app.test_matcher(test_preset) as ctx:
|
||||
bot = ctx.create_bot()
|
||||
ctx.receive_event(bot, event)
|
||||
ctx.should_rejected()
|
||||
ctx.receive_event(bot, event_next)
|
||||
|
Reference in New Issue
Block a user