From c67d93157e71489b37141fe4a57a470edbad7338 Mon Sep 17 00:00:00 2001 From: Well404 Date: Sun, 16 Apr 2023 15:28:29 +0800 Subject: [PATCH 1/2] =?UTF-8?q?:memo:=20=E4=BF=AE=E6=AD=A3=E6=95=99?= =?UTF-8?q?=E7=A8=8B=E4=B8=AD=E9=83=A8=E5=88=86import=E7=BC=BA=E5=A4=B1?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- website/docs/tutorial/event-data.mdx | 3 ++- website/docs/tutorial/handler.mdx | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/website/docs/tutorial/event-data.mdx b/website/docs/tutorial/event-data.mdx index b4d134443ef..a2ed176b9bc 100644 --- a/website/docs/tutorial/event-data.mdx +++ b/website/docs/tutorial/event-data.mdx @@ -26,10 +26,11 @@ import Messenger from "@site/src/components/Messenger"; 例如,我们可以继续改进上一章节中的 `weather` 插件,使其可以获取到 `天气` 命令的地名参数,并根据地名返回天气信息。 -```python {8,10} title=weather/__init__.py +```python {9,11} title=weather/__init__.py from nonebot import on_command from nonebot.adapters import Message from nonebot.params import CommandArg +from nonebot.rule import to_me weather = on_command("天气", rule=to_me(), aliases={"weather", "查天气"}, priority=10, block=True) diff --git a/website/docs/tutorial/handler.mdx b/website/docs/tutorial/handler.mdx index ba63b96cea0..ee9509b9e35 100644 --- a/website/docs/tutorial/handler.mdx +++ b/website/docs/tutorial/handler.mdx @@ -26,8 +26,9 @@ import Messenger from "@site/src/components/Messenger"; 顾名思义,“事件处理函数装饰器”是一个[装饰器(decorator)](https://docs.python.org/zh-cn/3/glossary.html#term-decorator),那么它的使用方法也同[函数定义](https://docs.python.org/zh-cn/3/reference/compound_stmts.html#function-definitions)中所展示的包装用法相同。例如: -```python {5-7} title=weather/__init__.py +```python {6-8} title=weather/__init__.py from nonebot.plugin import on_command +from nonebot.rule import to_me weather = on_command("天气", rule=to_me(), aliases={"weather", "查天气"}, priority=10, block=True) @@ -44,8 +45,9 @@ async def handle_function(): 事件响应器操作与事件处理函数装饰器类似,通常作为事件响应器 `Matcher` 的[类方法](https://docs.python.org/zh-cn/3/library/functions.html#classmethod)存在,因此事件响应器操作的调用方法也是 `Matcher.func()` 的形式。不过不同的是,事件响应器操作并不是装饰器,因此并不需要@进行标注。 -```python {7,8} title=weather/__init__.py +```python {8,9} title=weather/__init__.py from nonebot.plugin import on_command +from nonebot.rule import to_me weather = on_command("天气", rule=to_me(), aliases={"weather", "查天气"}, priority=10, block=True) From f87d3a5c69d1bed6c51fc5ee4bec993a36f18c3c Mon Sep 17 00:00:00 2001 From: Ju4tCode <42488585+yanyongyu@users.noreply.github.com> Date: Sun, 16 Apr 2023 17:59:27 +0800 Subject: [PATCH 2/2] :art: sort import --- website/docs/tutorial/event-data.mdx | 2 +- website/docs/tutorial/handler.mdx | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/website/docs/tutorial/event-data.mdx b/website/docs/tutorial/event-data.mdx index a2ed176b9bc..59877577343 100644 --- a/website/docs/tutorial/event-data.mdx +++ b/website/docs/tutorial/event-data.mdx @@ -28,9 +28,9 @@ import Messenger from "@site/src/components/Messenger"; ```python {9,11} title=weather/__init__.py from nonebot import on_command +from nonebot.rule import to_me from nonebot.adapters import Message from nonebot.params import CommandArg -from nonebot.rule import to_me weather = on_command("天气", rule=to_me(), aliases={"weather", "查天气"}, priority=10, block=True) diff --git a/website/docs/tutorial/handler.mdx b/website/docs/tutorial/handler.mdx index ee9509b9e35..20e21d6d5b6 100644 --- a/website/docs/tutorial/handler.mdx +++ b/website/docs/tutorial/handler.mdx @@ -27,8 +27,8 @@ import Messenger from "@site/src/components/Messenger"; 顾名思义,“事件处理函数装饰器”是一个[装饰器(decorator)](https://docs.python.org/zh-cn/3/glossary.html#term-decorator),那么它的使用方法也同[函数定义](https://docs.python.org/zh-cn/3/reference/compound_stmts.html#function-definitions)中所展示的包装用法相同。例如: ```python {6-8} title=weather/__init__.py -from nonebot.plugin import on_command from nonebot.rule import to_me +from nonebot.plugin import on_command weather = on_command("天气", rule=to_me(), aliases={"weather", "查天气"}, priority=10, block=True) @@ -46,8 +46,8 @@ async def handle_function(): 事件响应器操作与事件处理函数装饰器类似,通常作为事件响应器 `Matcher` 的[类方法](https://docs.python.org/zh-cn/3/library/functions.html#classmethod)存在,因此事件响应器操作的调用方法也是 `Matcher.func()` 的形式。不过不同的是,事件响应器操作并不是装饰器,因此并不需要@进行标注。 ```python {8,9} title=weather/__init__.py -from nonebot.plugin import on_command from nonebot.rule import to_me +from nonebot.plugin import on_command weather = on_command("天气", rule=to_me(), aliases={"weather", "查天气"}, priority=10, block=True)