nonebot2/tests/test_plugins/test_depends.py

29 lines
577 B
Python
Raw Normal View History

2021-11-14 18:51:23 +08:00
from nonebot.log import logger
from nonebot.dependencies import Depends
2021-11-21 15:46:48 +08:00
from nonebot import on_command, on_message
2021-11-14 18:51:23 +08:00
test = on_command("123")
def depend(state: dict):
2021-11-21 15:46:48 +08:00
print("==== depends running =====")
2021-11-14 18:51:23 +08:00
return state
@test.got("a", prompt="a")
@test.got("b", prompt="b")
@test.receive()
@test.got("c", prompt="c")
2021-11-21 15:46:48 +08:00
async def _(x: dict = Depends(depend)):
logger.info(f"=======, {x}")
test_cache1 = on_message()
test_cache2 = on_message()
@test_cache1.handle()
@test_cache2.handle()
async def _(x: dict = Depends(depend)):
logger.info(f"======= test, {x}")