🐛 fix cannot reject preset arg

This commit is contained in:
yanyongyu
2021-12-24 14:09:43 +08:00
parent 17f3c8fd09
commit 6643f951ef
4 changed files with 49 additions and 10 deletions

View File

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

View File

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