2021-12-12 18:19:08 +08:00
|
|
|
from nonebot import on_message
|
|
|
|
from nonebot.adapters import Event
|
|
|
|
from nonebot.params import Depends
|
|
|
|
|
2021-12-16 23:22:25 +08:00
|
|
|
test_depends = on_message()
|
2021-12-12 18:19:08 +08:00
|
|
|
|
2021-12-16 23:22:25 +08:00
|
|
|
runned = []
|
2021-12-12 18:19:08 +08:00
|
|
|
|
|
|
|
|
|
|
|
def dependency(event: Event):
|
|
|
|
# test cache
|
2021-12-16 23:22:25 +08:00
|
|
|
runned.append(event)
|
2021-12-12 18:19:08 +08:00
|
|
|
return event
|
|
|
|
|
|
|
|
|
2021-12-16 23:22:25 +08:00
|
|
|
@test_depends.handle()
|
|
|
|
async def depends(x: Event = Depends(dependency)):
|
2021-12-12 18:19:08 +08:00
|
|
|
# test dependency
|
|
|
|
return x
|
2021-12-16 23:22:25 +08:00
|
|
|
|
|
|
|
|
|
|
|
@test_depends.handle()
|
|
|
|
async def depends_cache(y: Event = Depends(dependency, use_cache=True)):
|
|
|
|
return y
|