nonebot2/tests/plugins/depends.py

25 lines
456 B
Python
Raw Normal View History

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-16 23:22:25 +08:00
runned = []
def dependency(event: Event):
# test cache
2021-12-16 23:22:25 +08:00
runned.append(event)
return event
2021-12-16 23:22:25 +08:00
@test_depends.handle()
async def depends(x: Event = Depends(dependency)):
# 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