mirror of
				https://github.com/nonebot/nonebot2.git
				synced 2025-11-04 00:46:43 +00:00 
			
		
		
		
	fix some bug
This commit is contained in:
		@@ -10,13 +10,12 @@ test_message = on_message(state={"default": 1})
 | 
			
		||||
 | 
			
		||||
@test_message.handle()
 | 
			
		||||
async def test_handler(bot: Bot, event: Event, state: dict):
 | 
			
		||||
    print("Test Matcher Received:", event)
 | 
			
		||||
    print("Current State:", state)
 | 
			
		||||
    print("[*] Test Matcher Received:", event)
 | 
			
		||||
    state["event"] = event
 | 
			
		||||
    await bot.send_private_msg(message="Received", user_id=event.user_id)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@test_message.receive()
 | 
			
		||||
async def test_receive(bot: Bot, event: Event, state: dict):
 | 
			
		||||
    print("Test Matcher Received next time:", event)
 | 
			
		||||
    print("Current State:", state)
 | 
			
		||||
    print("[*] Test Matcher Received next time:", event)
 | 
			
		||||
    print("[*] Current State:", state)
 | 
			
		||||
 
 | 
			
		||||
@@ -12,6 +12,6 @@ async def heartbeat(bot: Bot, event: Event, state: dict) -> bool:
 | 
			
		||||
test_matcher = on_metaevent(heartbeat)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@test_matcher.handle()
 | 
			
		||||
@test_matcher.receive()
 | 
			
		||||
async def handle_heartbeat(bot: Bot, event: Event, state: dict):
 | 
			
		||||
    print("[i] Heartbeat")
 | 
			
		||||
 
 | 
			
		||||
@@ -1,14 +1,29 @@
 | 
			
		||||
#!/usr/bin/env python3
 | 
			
		||||
# -*- coding: utf-8 -*-
 | 
			
		||||
 | 
			
		||||
from nonebot.rule import Rule
 | 
			
		||||
from nonebot.rule import to_me
 | 
			
		||||
from nonebot.typing import Event
 | 
			
		||||
from nonebot.plugin import on_command
 | 
			
		||||
from nonebot.adapters.cqhttp import Bot
 | 
			
		||||
 | 
			
		||||
test_command = on_command(("帮助",))
 | 
			
		||||
test_command = on_command("帮助", to_me())
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@test_command.handle()
 | 
			
		||||
async def test_handler(bot: Bot, event: Event, state: dict):
 | 
			
		||||
    print(state["_prefix"])
 | 
			
		||||
    print("[!] Command:", state["_prefix"])
 | 
			
		||||
    args = str(event.message)[len(state["_prefix"]):].strip()
 | 
			
		||||
    if args:
 | 
			
		||||
        state["help"] = args
 | 
			
		||||
    else:
 | 
			
		||||
        await bot.send_private_msg(message="命令:\n1. test1\n2. test2",
 | 
			
		||||
                                   user_id=event.user_id)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@test_command.got("help", prompt="你要帮助的命令是?")
 | 
			
		||||
async def test_handler(bot: Bot, event: Event, state: dict):
 | 
			
		||||
    print("[!] Command 帮助:", state["help"])
 | 
			
		||||
    if state["help"] not in ["test1", "test2"]:
 | 
			
		||||
        await bot.send_private_msg(message=f"{state['help']} 不支持,请重新输入!")
 | 
			
		||||
        test_command.reject()
 | 
			
		||||
    await bot.send_private_msg(message=f"{state['help']} 帮助:\n...")
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user