2020-08-23 10:45:26 +08:00
from nonebot . rule import to_me
2020-12-17 21:09:30 +08:00
from nonebot . typing import T_State
2020-08-17 16:09:41 +08:00
from nonebot . plugin import on_command
2020-12-17 21:09:30 +08:00
from nonebot . adapters import Bot , Event
2020-08-17 16:09:41 +08:00
2020-08-23 10:45:26 +08:00
test_command = on_command ( " 帮助 " , to_me ( ) )
2020-08-17 16:09:41 +08:00
@test_command.handle ( )
2021-06-16 00:58:47 +08:00
async def test_handler1 ( bot : Bot , event : Event , state : T_State ) :
2020-12-17 21:09:30 +08:00
args = str ( event . get_message ( ) ) . strip ( )
2020-08-24 17:59:36 +08:00
print ( " [!] Command: " , state [ " _prefix " ] , " Args: " , args )
2020-08-23 10:45:26 +08:00
if args :
state [ " help " ] = args
else :
2020-08-26 17:47:36 +08:00
await bot . send ( message = " 命令: \n 1. test1 \n 2. test2 " , event = event )
2020-08-23 10:45:26 +08:00
@test_command.got ( " help " , prompt = " 你要帮助的命令是? " )
2021-06-16 00:58:47 +08:00
async def test_handler2 ( bot : Bot , event : Event , state : T_State ) :
2020-08-23 10:45:26 +08:00
print ( " [!] Command 帮助: " , state [ " help " ] )
if state [ " help " ] not in [ " test1 " , " test2 " ] :
2020-08-25 15:23:10 +08:00
await test_command . reject ( f " { state [ ' help ' ] } 不支持,请重新输入! " )
2020-08-26 17:47:36 +08:00
await bot . send ( message = f " { state [ ' help ' ] } 帮助: \n ... " , event = event )