diff --git a/README.md b/README.md index d2afe009..d90c9731 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,7 @@ NoneBot2 的驱动框架 `Driver` 以及通信协议 `Adapter` 均可**自定义 目前 NoneBot2 内置的驱动框架: - [FastAPI](https://fastapi.tiangolo.com/) +- [Quart](https://pgjones.gitlab.io/quart/) (异步 flask ) 目前 NoneBot2 内置的协议适配: diff --git a/docs/.vuepress/public/plugins.json b/docs/.vuepress/public/plugins.json index df725b06..68fc621a 100644 --- a/docs/.vuepress/public/plugins.json +++ b/docs/.vuepress/public/plugins.json @@ -88,7 +88,7 @@ "repo": "abrahum/nonebot_plugin_simdraw" }, { - "id": "nonebot-plugin-wordbank", + "id": "nonebot_plugin_wordbank", "link": "nonebot-plugin-wordbank", "author": "Joenothing-lst", "desc": "无数据库的轻量问答插件,支持模糊问答", diff --git a/docs/advanced/export-and-require.md b/docs/advanced/export-and-require.md index cb24c428..eef88990 100644 --- a/docs/advanced/export-and-require.md +++ b/docs/advanced/export-and-require.md @@ -9,7 +9,7 @@ 下面将介绍第二种方法—— `export` 和 `require` 机制: -## 使用 export and require +## 使用 export 和 require 现在,假定有两个插件 `pluginA` 和 `pluginB`,需要在 `pluginB` 中调用 `pluginA` 中的一个变量 `varA` 和一个函数 `funcA`。 diff --git a/docs/advanced/permission.md b/docs/advanced/permission.md index 7190bcdd..de198e6e 100644 --- a/docs/advanced/permission.md +++ b/docs/advanced/permission.md @@ -1 +1,2 @@ # 权限控制 + diff --git a/docs/advanced/runtime-hook.md b/docs/advanced/runtime-hook.md index 935d3ce8..b5cc8b6d 100644 --- a/docs/advanced/runtime-hook.md +++ b/docs/advanced/runtime-hook.md @@ -1 +1,60 @@ # 钩子函数 + +[`钩子编程`](https://zh.wikipedia.org/wiki/%E9%92%A9%E5%AD%90%E7%BC%96%E7%A8%8B) + +> 钩子编程(hooking),也称作“挂钩”,是计算机程序设计术语,指通过拦截软件模块间的函数调用、消息传递、事件传递来修改或扩展操作系统、应用程序或其他软件组件的行为的各种技术。处理被拦截的函数调用、事件、消息的代码,被称为钩子(hook)。 + +在 `nonebot2` 中有一系列预定义的钩子函数,这些函数位于 [`nonebot.message`](https://v2.nonebot.dev/api/message.html) 模块下,我们可以以装饰器的形式利用这些函数,进行以下四种操作: + +:::warning 注意 +1.在钩子函数中,与 `matcher` 运行状态相关的函数将不可用,如 `matcher.finish()` + +2.如果需要在钩子函数中打断整个对话的执行,请参考以下范例: +```python +from nonebot.exception import IgnoredException + + +@event_preprocessor +async def do_something(matcher: Matcher, bot: Bot, event: Event, state: T_State): + raise IgnoredException("reason") +``` +::: + +## 事件预处理 + +```python +from nonebot.message import event_preprocessor + +@event_preprocessor +async def do_something(matcher: Matcher, bot: Bot, event: Event, state: T_State): + pass +``` + +## 事件后处理 + +```python +from nonebot.message import event_postprocessor + +@event_postprocessor +async def do_something(matcher: Matcher, bot: Bot, event: Event, state: T_State): + pass +``` + +## 运行预处理 + +```python +from nonebot.message import run_preprocessor + +@run_preprocessor +async def do_something(matcher: Matcher, bot: Bot, event: Event, state: T_State): + pass +``` + +## 运行后处理 +```python +from nonebot.message import run_postprocessor + +@run_postprocessor +async def do_something(matcher: Matcher, bot: Bot, event: Event, state: T_State): + pass +``` \ No newline at end of file diff --git a/docs/advanced/scheduler.md b/docs/advanced/scheduler.md index c58062f1..93d5be99 100644 --- a/docs/advanced/scheduler.md +++ b/docs/advanced/scheduler.md @@ -8,7 +8,7 @@ `APScheduler` 作为 `nonebot` v1 的可选依赖,为众多 bot 提供了方便的定时任务功能。`nonebot2` 已将 `APScheduler` 独立为 `nonebot_plugin_apscheduler` 插件,你可以在 [插件广场](https://v2.nonebot.dev/plugin-store.html) 中找到它。 -相比于 `nonebot` v1 ,只需要安装插件并修改 `scheduler` 的导入方式即可完成迁移。 +相比于 `nonebot` v1,`nonebot` v2只需要安装插件并修改 `scheduler` 的导入方式即可完成迁移。 ## 安装插件