From db7e10cb4d8b1dcba9a18f700f0ff1dbf41c102f Mon Sep 17 00:00:00 2001 From: Lan <59906398+Lancercmd@users.noreply.github.com> Date: Fri, 1 Jan 2021 18:21:02 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E2=9C=8F=EF=B8=8F=20Fix=20typo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/guide/creating-a-matcher.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/guide/creating-a-matcher.md b/docs/guide/creating-a-matcher.md index 09603855..1e5a4299 100644 --- a/docs/guide/creating-a-matcher.md +++ b/docs/guide/creating-a-matcher.md @@ -21,7 +21,7 @@ async def handle_first_receive(bot: Bot, event: Event, state: T_State): @weather.got("city", prompt="你想查询哪个城市的天气呢?") -async def handle_city(bot: Bot, event: Event, state: State): +async def handle_city(bot: Bot, event: Event, state: T_State): city = state["city"] if city not in ["上海", "北京"]: await weather.reject("你想查询的城市暂不支持,请重新输入!") From 8f69b2449d17687f275ff44973202a2497b622eb Mon Sep 17 00:00:00 2001 From: Lan <59906398+Lancercmd@users.noreply.github.com> Date: Fri, 1 Jan 2021 19:21:46 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=93=9D=20Update=20creating-a-matcher.?= =?UTF-8?q?md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/guide/creating-a-matcher.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/guide/creating-a-matcher.md b/docs/guide/creating-a-matcher.md index 1e5a4299..182885fe 100644 --- a/docs/guide/creating-a-matcher.md +++ b/docs/guide/creating-a-matcher.md @@ -115,16 +115,17 @@ rule 的出现使得 nonebot 对事件的响应可以非常自由,nonebot 内 ```python from nonebot.rule import Rule +from nonebot.typing import T_State -async def async_checker(bot: Bot, event: Event, state: State) -> bool: +async def async_checker(bot: Bot, event: Event, state: T_State) -> bool: return True -def sync_checker(bot: Bot, event: Event, state: State) -> bool: +def sync_checker(bot: Bot, event: Event, state: T_State) -> bool: return True def check(arg1, args2): - async def _checker(bot: Bot, event: Event, state: State) -> bool: + async def _checker(bot: Bot, event: Event, state: T_State) -> bool: return bool(arg1 + arg2) return Rule(_check) From 996c57df6220a2ba66d681e425892c8d62c1157a Mon Sep 17 00:00:00 2001 From: Lan <59906398+Lancercmd@users.noreply.github.com> Date: Fri, 1 Jan 2021 19:23:51 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=93=9D=20Update=20creating-a-handler.?= =?UTF-8?q?md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/guide/creating-a-handler.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/guide/creating-a-handler.md b/docs/guide/creating-a-handler.md index 5b6b0591..723aeeff 100644 --- a/docs/guide/creating-a-handler.md +++ b/docs/guide/creating-a-handler.md @@ -69,7 +69,7 @@ async def handle2(bot: Bot, event: Event, state: T_State): ```python @matcher.got("key1") @matcher.got("key2") -async def handle(bot: Bot, event: Event, state: State): +async def handle(bot: Bot, event: Event, state: T_State): pass ``` @@ -169,12 +169,12 @@ matcher = on_command("test") # 修改默认参数处理 @matcher.args_parser -async def parse(bot: Bot, event: Event, state: State): +async def parse(bot: Bot, event: Event, state: T_State): print(state["_current_key"], ":", str(event.get_message())) state[state["_current_key"]] = str(event.get_message()) @matcher.handle() -async def first_receive(bot: Bot, event: Event, state: State): +async def first_receive(bot: Bot, event: Event, state: T_State): # 获取用户原始命令,如:/test print(state["_prefix"]["raw_command"]) # 处理用户输入参数,如:/test arg1 arg2 @@ -186,7 +186,7 @@ async def first_receive(bot: Bot, event: Event, state: State): @matcher.got("arg1", prompt="参数?") -async def arg_handle(bot: Bot, event: Event, state: State): +async def arg_handle(bot: Bot, event: Event, state: T_State): # 在这里对参数进行验证 if state["arg1"] not in ["allow", "list"]: await matcher.reject("参数不正确!请重新输入")