2020-08-23 17:03:59 +08:00
|
|
|
|
---
|
|
|
|
|
contentSidebar: true
|
|
|
|
|
sidebarDepth: 0
|
|
|
|
|
---
|
|
|
|
|
|
2020-08-19 20:29:37 +08:00
|
|
|
|
# NoneBot.typing 模块
|
|
|
|
|
|
|
|
|
|
## 类型
|
|
|
|
|
|
|
|
|
|
下面的文档中,「类型」部分使用 Python 的 Type Hint 语法,见 [PEP 484](https://www.python.org/dev/peps/pep-0484/)、[PEP 526](https://www.python.org/dev/peps/pep-0526/) 和 [typing](https://docs.python.org/3/library/typing.html)。
|
|
|
|
|
|
|
|
|
|
除了 Python 内置的类型,下面还出现了如下 NoneBot 自定类型,实际上它们是 Python 内置类型的别名。
|
|
|
|
|
|
|
|
|
|
以下类型均可从 nonebot.typing 模块导入。
|
|
|
|
|
|
|
|
|
|
|
2020-12-19 15:31:14 +08:00
|
|
|
|
## `T_State`
|
2020-08-19 20:29:37 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* **类型**
|
|
|
|
|
|
2020-12-07 00:52:26 +08:00
|
|
|
|
`Dict[Any, Any]`
|
2020-08-19 20:29:37 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* **说明**
|
|
|
|
|
|
2020-12-07 00:52:26 +08:00
|
|
|
|
事件处理状态 State 类型
|
2020-08-19 20:29:37 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-12-20 12:15:01 +08:00
|
|
|
|
## `T_StateFactory`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* **类型**
|
|
|
|
|
|
|
|
|
|
`Callable[[Bot, Event], Awaitable[T_State]]`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* **说明**
|
|
|
|
|
|
|
|
|
|
事件处理状态 State 类工厂函数
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-05-22 06:43:53 +08:00
|
|
|
|
## `T_BotConnectionHook`
|
2020-12-28 13:57:28 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* **类型**
|
|
|
|
|
|
|
|
|
|
`Callable[[Bot], Awaitable[None]]`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* **说明**
|
|
|
|
|
|
2021-05-22 06:43:53 +08:00
|
|
|
|
Bot 连接建立时执行的函数
|
2020-12-28 13:57:28 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-05-22 06:43:53 +08:00
|
|
|
|
## `T_BotDisconnectionHook`
|
2020-12-28 13:57:28 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* **类型**
|
|
|
|
|
|
|
|
|
|
`Callable[[Bot], Awaitable[None]]`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* **说明**
|
|
|
|
|
|
2021-05-22 06:43:53 +08:00
|
|
|
|
Bot 连接断开时执行的函数
|
2020-12-28 13:57:28 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-01 20:27:27 +08:00
|
|
|
|
## `T_CallingAPIHook`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* **类型**
|
|
|
|
|
|
|
|
|
|
`Callable[[Bot, str, Dict[str, Any]], Awaitable[None]]`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* **说明**
|
|
|
|
|
|
|
|
|
|
`bot.call_api` 时执行的函数
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## `T_CalledAPIHook`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* **类型**
|
|
|
|
|
|
|
|
|
|
`Callable[[Bot, Optional[Exception], str, Dict[str, Any], Any], Awaitable[None]]`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* **说明**
|
|
|
|
|
|
|
|
|
|
`bot.call_api` 后执行的函数,参数分别为 bot, exception, api, data, result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-12-19 15:31:14 +08:00
|
|
|
|
## `T_EventPreProcessor`
|
2020-08-19 20:29:37 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* **类型**
|
|
|
|
|
|
2021-11-21 12:37:46 +08:00
|
|
|
|
`Callable[..., Union[None, Awaitable[None]]]`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* **依赖参数**
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* `BotParam`: Bot 对象
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* `EventParam`: Event 对象
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* `StateParam`: State 对象
|
2020-08-19 20:29:37 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* **说明**
|
|
|
|
|
|
2020-11-07 17:52:23 +08:00
|
|
|
|
事件预处理函数 EventPreProcessor 类型
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-12-19 15:31:14 +08:00
|
|
|
|
## `T_EventPostProcessor`
|
2020-11-07 17:52:23 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* **类型**
|
|
|
|
|
|
2021-11-21 12:37:46 +08:00
|
|
|
|
`Callable[..., Union[None, Awaitable[None]]]`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* **依赖参数**
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* `BotParam`: Bot 对象
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* `EventParam`: Event 对象
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* `StateParam`: State 对象
|
2020-11-07 17:52:23 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* **说明**
|
|
|
|
|
|
|
|
|
|
事件预处理函数 EventPostProcessor 类型
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-12-19 15:31:14 +08:00
|
|
|
|
## `T_RunPreProcessor`
|
2020-11-07 17:52:23 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* **类型**
|
|
|
|
|
|
2021-11-21 12:37:46 +08:00
|
|
|
|
`Callable[..., Union[None, Awaitable[None]]]`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* **依赖参数**
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* `BotParam`: Bot 对象
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* `EventParam`: Event 对象
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* `StateParam`: State 对象
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* `MatcherParam`: Matcher 对象
|
2020-11-07 17:52:23 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* **说明**
|
|
|
|
|
|
|
|
|
|
事件响应器运行前预处理函数 RunPreProcessor 类型
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-12-19 15:31:14 +08:00
|
|
|
|
## `T_RunPostProcessor`
|
2020-11-07 17:52:23 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* **类型**
|
|
|
|
|
|
2021-11-21 12:37:46 +08:00
|
|
|
|
`Callable[..., Union[None, Awaitable[None]]]`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* **依赖参数**
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* `BotParam`: Bot 对象
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* `EventParam`: Event 对象
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* `StateParam`: State 对象
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* `MatcherParam`: Matcher 对象
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* `ExceptionParam`: 异常对象(可能为 None)
|
2020-11-07 17:52:23 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* **说明**
|
|
|
|
|
|
2020-11-16 19:42:47 +08:00
|
|
|
|
事件响应器运行前预处理函数 RunPostProcessor 类型,第二个参数为运行时产生的错误(如果存在)
|
2020-08-19 20:29:37 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-12-19 15:31:14 +08:00
|
|
|
|
## `T_RuleChecker`
|
2020-08-19 23:00:31 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* **类型**
|
|
|
|
|
|
2021-11-19 18:20:20 +08:00
|
|
|
|
`Callable[..., Union[bool, Awaitable[bool]]]`
|
2020-08-19 23:00:31 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-11-21 12:37:46 +08:00
|
|
|
|
* **依赖参数**
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* `BotParam`: Bot 对象
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* `EventParam`: Event 对象
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* `StateParam`: State 对象
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-08-19 23:00:31 +08:00
|
|
|
|
* **说明**
|
|
|
|
|
|
|
|
|
|
RuleChecker 即判断是否响应事件的处理函数。
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-12-19 15:31:14 +08:00
|
|
|
|
## `T_PermissionChecker`
|
2020-08-19 23:00:31 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* **类型**
|
|
|
|
|
|
2021-11-21 12:37:46 +08:00
|
|
|
|
`Callable[..., Union[bool, Awaitable[bool]]]`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* **依赖参数**
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* `BotParam`: Bot 对象
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* `EventParam`: Event 对象
|
2020-08-19 23:00:31 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* **说明**
|
|
|
|
|
|
|
|
|
|
RuleChecker 即判断是否响应消息的处理函数。
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-12-19 15:31:14 +08:00
|
|
|
|
## `T_Handler`
|
2020-08-19 23:00:31 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* **类型**
|
|
|
|
|
|
2021-11-21 12:37:46 +08:00
|
|
|
|
`Callable[..., Any]`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* **说明**
|
|
|
|
|
|
|
|
|
|
Handler 处理函数。
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## `T_DependencyCache`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* **类型**
|
|
|
|
|
|
|
|
|
|
`Dict[T_Handler, Any]`
|
2020-08-19 23:00:31 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* **说明**
|
|
|
|
|
|
2021-11-21 12:37:46 +08:00
|
|
|
|
依赖缓存, 用于存储依赖函数的返回值
|
2020-08-19 23:00:31 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-12-19 15:31:14 +08:00
|
|
|
|
## `T_ArgsParser`
|
2020-08-19 23:00:31 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* **类型**
|
|
|
|
|
|
2020-12-19 15:31:14 +08:00
|
|
|
|
`Callable[[Bot, Event, T_State], Union[Awaitable[None], Awaitable[NoReturn]]]`
|
2020-08-19 23:00:31 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* **说明**
|
|
|
|
|
|
|
|
|
|
ArgsParser 即消息参数解析函数,在 Matcher.got 获取参数时被运行。
|
2021-03-03 16:06:19 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## `T_TypeUpdater`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* **类型**
|
|
|
|
|
|
|
|
|
|
`Callable[[Bot, Event, T_State, str], Awaitable[str]]`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* **说明**
|
|
|
|
|
|
|
|
|
|
TypeUpdater 在 Matcher.pause, Matcher.reject 时被运行,用于更新响应的事件类型。默认会更新为 `message`。
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## `T_PermissionUpdater`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* **类型**
|
|
|
|
|
|
|
|
|
|
`Callable[[Bot, Event, T_State, Permission], Awaitable[Permission]]`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* **说明**
|
|
|
|
|
|
|
|
|
|
PermissionUpdater 在 Matcher.pause, Matcher.reject 时被运行,用于更新会话对象权限。默认会更新为当前事件的触发对象。
|