mirror of
https://github.com/nonebot/nonebot2.git
synced 2024-11-24 00:55:07 +08:00
✅ add test case
This commit is contained in:
parent
1b00fe7921
commit
e44cde0600
@ -159,17 +159,29 @@ class Matcher(metaclass=MatcherMeta):
|
||||
|
||||
NewMatcher = type(
|
||||
"Matcher", (Matcher,), {
|
||||
"module": module,
|
||||
"type": type_,
|
||||
"rule": rule or Rule(),
|
||||
"permission": permission or Permission(),
|
||||
"handlers": handlers or [],
|
||||
"temp": temp,
|
||||
"expire_time": expire_time,
|
||||
"priority": priority,
|
||||
"block": block,
|
||||
"_default_state": default_state or {},
|
||||
"_default_state_factory": default_state_factory
|
||||
"module":
|
||||
module,
|
||||
"type":
|
||||
type_,
|
||||
"rule":
|
||||
rule or Rule(),
|
||||
"permission":
|
||||
permission or Permission(),
|
||||
"handlers":
|
||||
handlers or [],
|
||||
"temp":
|
||||
temp,
|
||||
"expire_time":
|
||||
expire_time,
|
||||
"priority":
|
||||
priority,
|
||||
"block":
|
||||
block,
|
||||
"_default_state":
|
||||
default_state or {},
|
||||
"_default_state_factory":
|
||||
staticmethod(default_state_factory)
|
||||
if default_state_factory else None
|
||||
})
|
||||
|
||||
matchers[priority].append(NewMatcher)
|
||||
|
@ -8,9 +8,14 @@ async def heartbeat(bot: Bot, event: Event, state: T_State) -> bool:
|
||||
return isinstance(event, HeartbeatMetaEvent)
|
||||
|
||||
|
||||
test_matcher = on_metaevent(heartbeat)
|
||||
async def factory(bot: Bot, event: Event) -> T_State:
|
||||
return {"factory": True}
|
||||
|
||||
|
||||
test_matcher = on_metaevent(heartbeat, state_factory=factory)
|
||||
|
||||
|
||||
@test_matcher.receive()
|
||||
async def handle_heartbeat(bot: Bot, event: Event, state: T_State):
|
||||
print(state)
|
||||
print("[i] Heartbeat")
|
||||
|
Loading…
Reference in New Issue
Block a user