2020-12-17 21:09:30 +08:00
|
|
|
from nonebot.typing import T_State
|
2020-08-24 17:59:36 +08:00
|
|
|
from nonebot.plugin import on_metaevent
|
2020-12-17 21:09:30 +08:00
|
|
|
from nonebot.adapters import Bot, Event
|
|
|
|
from nonebot.adapters.cqhttp import HeartbeatMetaEvent
|
2020-07-25 12:28:30 +08:00
|
|
|
|
|
|
|
|
2020-12-17 21:09:30 +08:00
|
|
|
async def heartbeat(bot: Bot, event: Event, state: T_State) -> bool:
|
|
|
|
return isinstance(event, HeartbeatMetaEvent)
|
2020-07-25 12:28:30 +08:00
|
|
|
|
|
|
|
|
2020-12-20 12:09:30 +08:00
|
|
|
async def factory(bot: Bot, event: Event) -> T_State:
|
|
|
|
return {"factory": True}
|
|
|
|
|
|
|
|
|
|
|
|
test_matcher = on_metaevent(heartbeat, state_factory=factory)
|
2020-07-25 12:28:30 +08:00
|
|
|
|
|
|
|
|
2020-08-23 10:45:26 +08:00
|
|
|
@test_matcher.receive()
|
2020-12-17 21:09:30 +08:00
|
|
|
async def handle_heartbeat(bot: Bot, event: Event, state: T_State):
|
2020-12-20 12:09:30 +08:00
|
|
|
print(state)
|
2020-07-25 12:28:30 +08:00
|
|
|
print("[i] Heartbeat")
|