mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-07-27 16:21:28 +00:00
🔖 Release 2.0.0rc3
This commit is contained in:
@ -0,0 +1,3 @@
|
||||
{
|
||||
"position": 15
|
||||
}
|
619
website/versioned_docs/version-2.0.0rc3/api/adapters/index.md
Normal file
619
website/versioned_docs/version-2.0.0rc3/api/adapters/index.md
Normal file
@ -0,0 +1,619 @@
|
||||
---
|
||||
sidebar_position: 0
|
||||
description: nonebot.adapters 模块
|
||||
---
|
||||
|
||||
# nonebot.adapters
|
||||
|
||||
本模块定义了协议适配基类,各协议请继承以下基类。
|
||||
|
||||
使用 [Driver.register_adapter](../drivers/index.md#Driver-register_adapter) 注册适配器。
|
||||
|
||||
## _abstract class_ `Bot(adapter, self_id)` {#Bot}
|
||||
|
||||
- **说明**
|
||||
|
||||
Bot 基类。
|
||||
|
||||
用于处理上报消息,并提供 API 调用接口。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `adapter` (Adapter): 协议适配器实例
|
||||
|
||||
- `self_id` (str): 机器人 ID
|
||||
|
||||
### _property_ `config` {#Bot-config}
|
||||
|
||||
- **类型:** [Config](../config.md#Config)
|
||||
|
||||
- **说明:** 全局 NoneBot 配置
|
||||
|
||||
### _property_ `type` {#Bot-type}
|
||||
|
||||
- **类型:** str
|
||||
|
||||
- **说明:** 协议适配器名称
|
||||
|
||||
### _async method_ `call_api(self, api, **data)` {#Bot-call_api}
|
||||
|
||||
- **说明**
|
||||
|
||||
调用机器人 API 接口,可以通过该函数或直接通过 bot 属性进行调用
|
||||
|
||||
- **参数**
|
||||
|
||||
- `api` (str): API 名称
|
||||
|
||||
- `**data` (Any): API 数据
|
||||
|
||||
- **返回**
|
||||
|
||||
- Any
|
||||
|
||||
- **用法**
|
||||
|
||||
```python
|
||||
await bot.call_api("send_msg", message="hello world")
|
||||
await bot.send_msg(message="hello world")
|
||||
```
|
||||
|
||||
### _classmethod_ `on_called_api(cls, func)` {#Bot-on_called_api}
|
||||
|
||||
- **说明**
|
||||
|
||||
调用 api 后处理。
|
||||
|
||||
钩子函数参数:
|
||||
|
||||
- bot: 当前 bot 对象
|
||||
- exception: 调用 api 时发生的错误
|
||||
- api: 调用的 api 名称
|
||||
- data: api 调用的参数字典
|
||||
- result: api 调用的返回
|
||||
|
||||
- **参数**
|
||||
|
||||
- `func` ((Bot, Exception | None, str, dict[str, Any], Any) -> Awaitable[Any])
|
||||
|
||||
- **返回**
|
||||
|
||||
- (Bot, Exception | None, str, dict[str, Any], Any) -> Awaitable[Any]
|
||||
|
||||
### _classmethod_ `on_calling_api(cls, func)` {#Bot-on_calling_api}
|
||||
|
||||
- **说明**
|
||||
|
||||
调用 api 预处理。
|
||||
|
||||
钩子函数参数:
|
||||
|
||||
- bot: 当前 bot 对象
|
||||
- api: 调用的 api 名称
|
||||
- data: api 调用的参数字典
|
||||
|
||||
- **参数**
|
||||
|
||||
- `func` ((Bot, str, dict[str, Any]) -> Awaitable[Any])
|
||||
|
||||
- **返回**
|
||||
|
||||
- (Bot, str, dict[str, Any]) -> Awaitable[Any]
|
||||
|
||||
### _abstract async method_ `send(self, event, message, **kwargs)` {#Bot-send}
|
||||
|
||||
- **说明**
|
||||
|
||||
调用机器人基础发送消息接口
|
||||
|
||||
- **参数**
|
||||
|
||||
- `event` (Event): 上报事件
|
||||
|
||||
- `message` (str | Message | MessageSegment): 要发送的消息
|
||||
|
||||
- `**kwargs` (Any): 任意额外参数
|
||||
|
||||
- **返回**
|
||||
|
||||
- Any
|
||||
|
||||
## _abstract class_ `Event(**extra_data)` {#Event}
|
||||
|
||||
- **说明**
|
||||
|
||||
Event 基类。提供获取关键信息的方法,其余信息可直接获取。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `**extra_data` (Any)
|
||||
|
||||
### _abstract method_ `get_event_description(self)` {#Event-get_event_description}
|
||||
|
||||
- **说明**
|
||||
|
||||
获取事件描述的方法,通常为事件具体内容。
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
### _abstract method_ `get_event_name(self)` {#Event-get_event_name}
|
||||
|
||||
- **说明**
|
||||
|
||||
获取事件名称的方法。
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
### _method_ `get_log_string(self)` {#Event-get_log_string}
|
||||
|
||||
- **说明**
|
||||
|
||||
获取事件日志信息的方法。
|
||||
|
||||
通常你不需要修改这个方法,只有当希望 NoneBot 隐藏该事件日志时,可以抛出 `NoLogException` 异常。
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
- **异常**
|
||||
|
||||
NoLogException
|
||||
|
||||
### _abstract method_ `get_message(self)` {#Event-get_message}
|
||||
|
||||
- **说明**
|
||||
|
||||
获取事件消息内容的方法。
|
||||
|
||||
- **返回**
|
||||
|
||||
- Message
|
||||
|
||||
### _method_ `get_plaintext(self)` {#Event-get_plaintext}
|
||||
|
||||
- **说明**
|
||||
|
||||
获取消息纯文本的方法。
|
||||
|
||||
通常不需要修改,默认通过 `get_message().extract_plain_text` 获取。
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
### _abstract method_ `get_session_id(self)` {#Event-get_session_id}
|
||||
|
||||
- **说明**
|
||||
|
||||
获取会话 id 的方法,用于判断当前事件属于哪一个会话,通常是用户 id、群组 id 组合。
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
### _abstract method_ `get_type(self)` {#Event-get_type}
|
||||
|
||||
- **说明**
|
||||
|
||||
获取事件类型的方法,类型通常为 NoneBot 内置的四种类型。
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
### _abstract method_ `get_user_id(self)` {#Event-get_user_id}
|
||||
|
||||
- **说明**
|
||||
|
||||
获取事件主体 id 的方法,通常是用户 id 。
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
### _abstract method_ `is_tome(self)` {#Event-is_tome}
|
||||
|
||||
- **说明**
|
||||
|
||||
获取事件是否与机器人有关的方法。
|
||||
|
||||
- **返回**
|
||||
|
||||
- bool
|
||||
|
||||
### _classmethod_ `validate(cls, value)` {#Event-validate}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `value` (Any)
|
||||
|
||||
- **返回**
|
||||
|
||||
- E
|
||||
|
||||
## _abstract class_ `Adapter(driver, **kwargs)` {#Adapter}
|
||||
|
||||
- **说明**
|
||||
|
||||
协议适配器基类。
|
||||
|
||||
通常,在 Adapter 中编写协议通信相关代码,如: 建立通信连接、处理接收与发送 data 等。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `driver` (nonebot.internal.driver.driver.Driver): [Driver](../drivers/index.md#Driver) 实例
|
||||
|
||||
- `**kwargs` (Any): 其他由 [Driver.register_adapter](../drivers/index.md#Driver-register_adapter) 传入的额外参数
|
||||
|
||||
### _property_ `config` {#Adapter-config}
|
||||
|
||||
- **类型:** [Config](../config.md#Config)
|
||||
|
||||
- **说明:** 全局 NoneBot 配置
|
||||
|
||||
### _method_ `bot_connect(self, bot)` {#Adapter-bot_connect}
|
||||
|
||||
- **说明**
|
||||
|
||||
告知 NoneBot 建立了一个新的 [Bot](#Bot) 连接。
|
||||
|
||||
当有新的 [Bot](#Bot) 实例连接建立成功时调用。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `bot` (nonebot.internal.adapter.bot.Bot): [Bot](#Bot) 实例
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _method_ `bot_disconnect(self, bot)` {#Adapter-bot_disconnect}
|
||||
|
||||
- **说明**
|
||||
|
||||
告知 NoneBot [Bot](#Bot) 连接已断开。
|
||||
|
||||
当有 [Bot](#Bot) 实例连接断开时调用。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `bot` (nonebot.internal.adapter.bot.Bot): [Bot](#Bot) 实例
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _abstract classmethod_ `get_name(cls)` {#Adapter-get_name}
|
||||
|
||||
- **说明**
|
||||
|
||||
当前协议适配器的名称
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
### _async method_ `request(self, setup)` {#Adapter-request}
|
||||
|
||||
- **说明**
|
||||
|
||||
进行一个 HTTP 客户端请求
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` (nonebot.internal.driver.model.Request)
|
||||
|
||||
- **返回**
|
||||
|
||||
- nonebot.internal.driver.model.Response
|
||||
|
||||
### _method_ `setup_http_server(self, setup)` {#Adapter-setup_http_server}
|
||||
|
||||
- **说明**
|
||||
|
||||
设置一个 HTTP 服务器路由配置
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` (nonebot.internal.driver.model.HTTPServerSetup)
|
||||
|
||||
- **返回**
|
||||
|
||||
- Unknown
|
||||
|
||||
### _method_ `setup_websocket_server(self, setup)` {#Adapter-setup_websocket_server}
|
||||
|
||||
- **说明**
|
||||
|
||||
设置一个 WebSocket 服务器路由配置
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` (nonebot.internal.driver.model.WebSocketServerSetup)
|
||||
|
||||
- **返回**
|
||||
|
||||
- Unknown
|
||||
|
||||
### _method_ `websocket(self, setup)` {#Adapter-websocket}
|
||||
|
||||
- **说明**
|
||||
|
||||
建立一个 WebSocket 客户端连接请求
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` (nonebot.internal.driver.model.Request)
|
||||
|
||||
- **返回**
|
||||
|
||||
- AsyncGenerator[nonebot.internal.driver.model.WebSocket, NoneType]
|
||||
|
||||
## _abstract class_ `Message(message=None)` {#Message}
|
||||
|
||||
- **说明**
|
||||
|
||||
消息数组
|
||||
|
||||
- **参数**
|
||||
|
||||
- `message` (str | NoneType | Iterable[(~ TMS)] | (~ TMS)): 消息内容
|
||||
|
||||
### _method_ `append(self, obj)` {#Message-append}
|
||||
|
||||
- **说明**
|
||||
|
||||
添加一个消息段到消息数组末尾。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `obj` (str | (~ TMS)): 要添加的消息段
|
||||
|
||||
- **返回**
|
||||
|
||||
- (~ TM)
|
||||
|
||||
### _method_ `copy(self)` {#Message-copy}
|
||||
|
||||
- **返回**
|
||||
|
||||
- (~ TM)
|
||||
|
||||
### _method_ `count(self, value)` {#Message-count}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `value` ((~ TMS) | str)
|
||||
|
||||
- **返回**
|
||||
|
||||
- int
|
||||
|
||||
### _method_ `extend(self, obj)` {#Message-extend}
|
||||
|
||||
- **说明**
|
||||
|
||||
拼接一个消息数组或多个消息段到消息数组末尾。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `obj` ((~ TM) | Iterable[(~ TMS)]): 要添加的消息数组
|
||||
|
||||
- **返回**
|
||||
|
||||
- (~ TM)
|
||||
|
||||
### _method_ `extract_plain_text(self)` {#Message-extract_plain_text}
|
||||
|
||||
- **说明**
|
||||
|
||||
提取消息内纯文本消息
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
### _method_ `get(self, type_, count=None)` {#Message-get}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `type_` (str)
|
||||
|
||||
- `count` (int | None)
|
||||
|
||||
- **返回**
|
||||
|
||||
- (~ TM)
|
||||
|
||||
### _abstract classmethod_ `get_segment_class(cls)` {#Message-get_segment_class}
|
||||
|
||||
- **说明**
|
||||
|
||||
获取消息段类型
|
||||
|
||||
- **返回**
|
||||
|
||||
- Type[(~ TMS)]
|
||||
|
||||
### _method_ `index(self, value, *args)` {#Message-index}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `value` ((~ TMS) | str)
|
||||
|
||||
- `*args`
|
||||
|
||||
- **返回**
|
||||
|
||||
- int
|
||||
|
||||
### _classmethod_ `template(cls, format_string)` {#Message-template}
|
||||
|
||||
- **说明**
|
||||
|
||||
创建消息模板。
|
||||
|
||||
用法和 `str.format` 大致相同, 但是可以输出消息对象, 并且支持以 `Message` 对象作为消息模板
|
||||
|
||||
并且提供了拓展的格式化控制符, 可以用适用于该消息类型的 `MessageSegment` 的工厂方法创建消息
|
||||
|
||||
- **参数**
|
||||
|
||||
- `format_string` (str | (~ TM)): 格式化模板
|
||||
|
||||
- **返回**
|
||||
|
||||
- nonebot.internal.adapter.template.MessageTemplate[(~ TM)]: 消息格式化器
|
||||
|
||||
## _abstract class_ `MessageSegment(type, data=<factory>)` {#MessageSegment}
|
||||
|
||||
- **说明**
|
||||
|
||||
消息段基类
|
||||
|
||||
- **参数**
|
||||
|
||||
- `type` (str)
|
||||
|
||||
- `data` (dict[str, Any])
|
||||
|
||||
### _method_ `copy(self)` {#MessageSegment-copy}
|
||||
|
||||
- **返回**
|
||||
|
||||
- (~ T)
|
||||
|
||||
### _method_ `get(self, key, default=None)` {#MessageSegment-get}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `key` (str)
|
||||
|
||||
- `default` (Any)
|
||||
|
||||
- **返回**
|
||||
|
||||
- Unknown
|
||||
|
||||
### _abstract classmethod_ `get_message_class(cls)` {#MessageSegment-get_message_class}
|
||||
|
||||
- **说明**
|
||||
|
||||
获取消息数组类型
|
||||
|
||||
- **返回**
|
||||
|
||||
- Type[(~ TM)]
|
||||
|
||||
### _abstract method_ `is_text(self)` {#MessageSegment-is_text}
|
||||
|
||||
- **说明**
|
||||
|
||||
当前消息段是否为纯文本
|
||||
|
||||
- **返回**
|
||||
|
||||
- bool
|
||||
|
||||
### _method_ `items(self)` {#MessageSegment-items}
|
||||
|
||||
- **返回**
|
||||
|
||||
- Unknown
|
||||
|
||||
### _method_ `keys(self)` {#MessageSegment-keys}
|
||||
|
||||
- **返回**
|
||||
|
||||
- Unknown
|
||||
|
||||
### _method_ `values(self)` {#MessageSegment-values}
|
||||
|
||||
- **返回**
|
||||
|
||||
- Unknown
|
||||
|
||||
## _class_ `MessageTemplate(template, factory=str)` {#MessageTemplate}
|
||||
|
||||
- **说明**
|
||||
|
||||
消息模板格式化实现类。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `template` (str | (~ TM)): 模板
|
||||
|
||||
- `factory` (Type[str] | Type[(~ TM)]): 消息类型工厂,默认为 `str`
|
||||
|
||||
### _method_ `add_format_spec(self, spec, name=None)` {#MessageTemplate-add_format_spec}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `spec` ((~ FormatSpecFunc_T))
|
||||
|
||||
- `name` (str | None)
|
||||
|
||||
- **返回**
|
||||
|
||||
- (~ FormatSpecFunc_T)
|
||||
|
||||
### _method_ `format(self, *args, **kwargs)` {#MessageTemplate-format}
|
||||
|
||||
- **说明**
|
||||
|
||||
根据传入参数和模板生成消息对象
|
||||
|
||||
- **参数**
|
||||
|
||||
- `*args`
|
||||
|
||||
- `**kwargs`
|
||||
|
||||
- **返回**
|
||||
|
||||
- Unknown
|
||||
|
||||
### _method_ `format_field(self, value, format_spec)` {#MessageTemplate-format_field}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `value` (Any)
|
||||
|
||||
- `format_spec` (str)
|
||||
|
||||
- **返回**
|
||||
|
||||
- Any
|
||||
|
||||
### _method_ `format_map(self, mapping)` {#MessageTemplate-format_map}
|
||||
|
||||
- **说明**
|
||||
|
||||
根据传入字典和模板生成消息对象, 在传入字段名不是有效标识符时有用
|
||||
|
||||
- **参数**
|
||||
|
||||
- `mapping` (Mapping[str, Any])
|
||||
|
||||
- **返回**
|
||||
|
||||
- (~ TF)
|
||||
|
||||
### _method_ `vformat(self, format_string, args, kwargs)` {#MessageTemplate-vformat}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `format_string` (str)
|
||||
|
||||
- `args` (Sequence[Any])
|
||||
|
||||
- `kwargs` (Mapping[str, Any])
|
||||
|
||||
- **返回**
|
||||
|
||||
- (~ TF)
|
194
website/versioned_docs/version-2.0.0rc3/api/config.md
Normal file
194
website/versioned_docs/version-2.0.0rc3/api/config.md
Normal file
@ -0,0 +1,194 @@
|
||||
---
|
||||
sidebar_position: 1
|
||||
description: nonebot.config 模块
|
||||
---
|
||||
|
||||
# nonebot.config
|
||||
|
||||
本模块定义了 NoneBot 本身运行所需的配置项。
|
||||
|
||||
NoneBot 使用 [`pydantic`](https://pydantic-docs.helpmanual.io/) 以及 [`python-dotenv`](https://saurabh-kumar.com/python-dotenv/) 来读取配置。
|
||||
|
||||
配置项需符合特殊格式或 json 序列化格式。详情见 [`pydantic Field Type`](https://pydantic-docs.helpmanual.io/usage/types/) 文档。
|
||||
|
||||
## _class_ `Env(_env_file='<object object>', _env_file_encoding=None, _env_nested_delimiter=None, _secrets_dir=None, *, environment='prod', **values)` {#Env}
|
||||
|
||||
- **说明**
|
||||
|
||||
运行环境配置。大小写不敏感。
|
||||
|
||||
将会从 `环境变量` > `.env 环境配置文件` 的优先级读取环境信息。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `_env_file` (str | os.PathLike | list[str | os.PathLike] | tuple[str | os.PathLike, ...] | NoneType)
|
||||
|
||||
- `_env_file_encoding` (str | None)
|
||||
|
||||
- `_env_nested_delimiter` (str | None)
|
||||
|
||||
- `_secrets_dir` (str | os.PathLike | NoneType)
|
||||
|
||||
- `environment` (str)
|
||||
|
||||
- `**values` (Any)
|
||||
|
||||
### _class-var_ `environment` {#Env-environment}
|
||||
|
||||
- **类型:** str
|
||||
|
||||
- **说明**
|
||||
|
||||
当前环境名。
|
||||
|
||||
NoneBot 将从 `.env.{environment}` 文件中加载配置。
|
||||
|
||||
## _class_ `Config(_env_file='<object object>', _env_file_encoding=None, _env_nested_delimiter=None, _secrets_dir=None, *, driver='~fastapi', host=IPv4Address('127.0.0.1'), port=8080, log_level='INFO', api_timeout=30.0, superusers=set(), nickname=set(), command_start={'/'}, command_sep={'.'}, session_expire_timeout=datetime.timedelta(seconds=120), **values)` {#Config}
|
||||
|
||||
- **说明**
|
||||
|
||||
NoneBot 主要配置。大小写不敏感。
|
||||
|
||||
除了 NoneBot 的配置项外,还可以自行添加配置项到 `.env.{environment}` 文件中。
|
||||
这些配置将会在 json 反序列化后一起带入 `Config` 类中。
|
||||
|
||||
配置方法参考: [配置](https://v2.nonebot.dev/docs/tutorial/configuration)
|
||||
|
||||
- **参数**
|
||||
|
||||
- `_env_file` (str | os.PathLike | list[str | os.PathLike] | tuple[str | os.PathLike, ...] | NoneType)
|
||||
|
||||
- `_env_file_encoding` (str | None)
|
||||
|
||||
- `_env_nested_delimiter` (str | None)
|
||||
|
||||
- `_secrets_dir` (str | os.PathLike | NoneType)
|
||||
|
||||
- `driver` (str)
|
||||
|
||||
- `host` (pydantic.networks.IPvAnyAddress)
|
||||
|
||||
- `port` (int)
|
||||
|
||||
- `log_level` (int | str)
|
||||
|
||||
- `api_timeout` (float | None)
|
||||
|
||||
- `superusers` (set[str])
|
||||
|
||||
- `nickname` (set[str])
|
||||
|
||||
- `command_start` (set[str])
|
||||
|
||||
- `command_sep` (set[str])
|
||||
|
||||
- `session_expire_timeout` (datetime.timedelta)
|
||||
|
||||
- `**values` (Any)
|
||||
|
||||
### _class-var_ `driver` {#Config-driver}
|
||||
|
||||
- **类型:** str
|
||||
|
||||
- **说明**
|
||||
|
||||
NoneBot 运行所使用的 `Driver` 。继承自 [Driver](./drivers/index.md#Driver) 。
|
||||
|
||||
配置格式为 `<module>[:<Driver>][+<module>[:<Mixin>]]*`。
|
||||
|
||||
`~` 为 `nonebot.drivers.` 的缩写。
|
||||
|
||||
### _class-var_ `host` {#Config-host}
|
||||
|
||||
- **类型:** pydantic.networks.IPvAnyAddress
|
||||
|
||||
- **说明:** NoneBot [ReverseDriver](./drivers/index.md#ReverseDriver) 服务端监听的 IP/主机名。
|
||||
|
||||
### _class-var_ `port` {#Config-port}
|
||||
|
||||
- **类型:** int
|
||||
|
||||
- **说明:** NoneBot [ReverseDriver](./drivers/index.md#ReverseDriver) 服务端监听的端口。
|
||||
|
||||
### _class-var_ `log_level` {#Config-log_level}
|
||||
|
||||
- **类型:** int | str
|
||||
|
||||
- **说明**
|
||||
|
||||
NoneBot 日志输出等级,可以为 `int` 类型等级或等级名称
|
||||
|
||||
参考 [`loguru 日志等级`](https://loguru.readthedocs.io/en/stable/api/logger.html#levels)。
|
||||
|
||||
:::tip 提示
|
||||
日志等级名称应为大写,如 `INFO`。
|
||||
:::
|
||||
|
||||
- **用法**
|
||||
|
||||
```conf
|
||||
LOG_LEVEL=25
|
||||
LOG_LEVEL=INFO
|
||||
```
|
||||
|
||||
### _class-var_ `api_timeout` {#Config-api_timeout}
|
||||
|
||||
- **类型:** float | None
|
||||
|
||||
- **说明:** API 请求超时时间,单位: 秒。
|
||||
|
||||
### _class-var_ `superusers` {#Config-superusers}
|
||||
|
||||
- **类型:** set[str]
|
||||
|
||||
- **说明:** 机器人超级用户。
|
||||
|
||||
- **用法**
|
||||
|
||||
```conf
|
||||
SUPERUSERS=["12345789"]
|
||||
```
|
||||
|
||||
### _class-var_ `nickname` {#Config-nickname}
|
||||
|
||||
- **类型:** set[str]
|
||||
|
||||
- **说明:** 机器人昵称。
|
||||
|
||||
### _class-var_ `command_start` {#Config-command_start}
|
||||
|
||||
- **类型:** set[str]
|
||||
|
||||
- **说明:** 命令的起始标记,用于判断一条消息是不是命令。
|
||||
|
||||
- **用法**
|
||||
|
||||
```conf
|
||||
COMMAND_START=["/", ""]
|
||||
```
|
||||
|
||||
### _class-var_ `command_sep` {#Config-command_sep}
|
||||
|
||||
- **类型:** set[str]
|
||||
|
||||
- **说明:** 命令的分隔标记,用于将文本形式的命令切分为元组(实际的命令名)。
|
||||
|
||||
- **用法**
|
||||
|
||||
```conf
|
||||
COMMAND_SEP=["."]
|
||||
```
|
||||
|
||||
### _class-var_ `session_expire_timeout` {#Config-session_expire_timeout}
|
||||
|
||||
- **类型:** datetime.timedelta
|
||||
|
||||
- **说明:** 等待用户回复的超时时间。
|
||||
|
||||
- **用法**
|
||||
|
||||
```conf
|
||||
SESSION_EXPIRE_TIMEOUT=120 # 单位: 秒
|
||||
SESSION_EXPIRE_TIMEOUT=[DD ][HH:MM]SS[.ffffff]
|
||||
SESSION_EXPIRE_TIMEOUT=P[DD]DT[HH]H[MM]M[SS]S # ISO 8601
|
||||
```
|
128
website/versioned_docs/version-2.0.0rc3/api/consts.md
Normal file
128
website/versioned_docs/version-2.0.0rc3/api/consts.md
Normal file
@ -0,0 +1,128 @@
|
||||
---
|
||||
sidebar_position: 9
|
||||
description: nonebot.consts 模块
|
||||
---
|
||||
|
||||
# nonebot.consts
|
||||
|
||||
本模块包含了 NoneBot 事件处理过程中使用到的常量。
|
||||
|
||||
## _var_ `RECEIVE_KEY` {#RECEIVE_KEY}
|
||||
|
||||
- **类型:** Literal['_receive_{id}']
|
||||
|
||||
- **说明:** `receive` 存储 key
|
||||
|
||||
## _var_ `LAST_RECEIVE_KEY` {#LAST_RECEIVE_KEY}
|
||||
|
||||
- **类型:** Literal['_last_receive']
|
||||
|
||||
- **说明:** `last_receive` 存储 key
|
||||
|
||||
## _var_ `ARG_KEY` {#ARG_KEY}
|
||||
|
||||
- **类型:** Literal['{key}']
|
||||
|
||||
- **说明:** `arg` 存储 key
|
||||
|
||||
## _var_ `REJECT_TARGET` {#REJECT_TARGET}
|
||||
|
||||
- **类型:** Literal['_current_target']
|
||||
|
||||
- **说明:** 当前 `reject` 目标存储 key
|
||||
|
||||
## _var_ `REJECT_CACHE_TARGET` {#REJECT_CACHE_TARGET}
|
||||
|
||||
- **类型:** Literal['_next_target']
|
||||
|
||||
- **说明:** 下一个 `reject` 目标存储 key
|
||||
|
||||
## _var_ `PREFIX_KEY` {#PREFIX_KEY}
|
||||
|
||||
- **类型:** Literal['_prefix']
|
||||
|
||||
- **说明:** 命令前缀存储 key
|
||||
|
||||
## _var_ `CMD_KEY` {#CMD_KEY}
|
||||
|
||||
- **类型:** Literal['command']
|
||||
|
||||
- **说明:** 命令元组存储 key
|
||||
|
||||
## _var_ `RAW_CMD_KEY` {#RAW_CMD_KEY}
|
||||
|
||||
- **类型:** Literal['raw_command']
|
||||
|
||||
- **说明:** 命令文本存储 key
|
||||
|
||||
## _var_ `CMD_ARG_KEY` {#CMD_ARG_KEY}
|
||||
|
||||
- **类型:** Literal['command_arg']
|
||||
|
||||
- **说明:** 命令参数存储 key
|
||||
|
||||
## _var_ `CMD_START_KEY` {#CMD_START_KEY}
|
||||
|
||||
- **类型:** Literal['command_start']
|
||||
|
||||
- **说明:** 命令开头存储 key
|
||||
|
||||
## _var_ `SHELL_ARGS` {#SHELL_ARGS}
|
||||
|
||||
- **类型:** Literal['_args']
|
||||
|
||||
- **说明:** shell 命令 parse 后参数字典存储 key
|
||||
|
||||
## _var_ `SHELL_ARGV` {#SHELL_ARGV}
|
||||
|
||||
- **类型:** Literal['_argv']
|
||||
|
||||
- **说明:** shell 命令原始参数列表存储 key
|
||||
|
||||
## _var_ `REGEX_MATCHED` {#REGEX_MATCHED}
|
||||
|
||||
- **类型:** Literal['_matched']
|
||||
|
||||
- **说明:** 正则匹配结果存储 key
|
||||
|
||||
## _var_ `REGEX_STR` {#REGEX_STR}
|
||||
|
||||
- **类型:** Literal['_matched_str']
|
||||
|
||||
- **说明:** 正则匹配文本存储 key
|
||||
|
||||
## _var_ `REGEX_GROUP` {#REGEX_GROUP}
|
||||
|
||||
- **类型:** Literal['_matched_groups']
|
||||
|
||||
- **说明:** 正则匹配 group 元组存储 key
|
||||
|
||||
## _var_ `REGEX_DICT` {#REGEX_DICT}
|
||||
|
||||
- **类型:** Literal['_matched_dict']
|
||||
|
||||
- **说明:** 正则匹配 group 字典存储 key
|
||||
|
||||
## _var_ `STARTSWITH_KEY` {#STARTSWITH_KEY}
|
||||
|
||||
- **类型:** Literal['_startswith']
|
||||
|
||||
- **说明:** 响应触发前缀 key
|
||||
|
||||
## _var_ `ENDSWITH_KEY` {#ENDSWITH_KEY}
|
||||
|
||||
- **类型:** Literal['_endswith']
|
||||
|
||||
- **说明:** 响应触发后缀 key
|
||||
|
||||
## _var_ `FULLMATCH_KEY` {#FULLMATCH_KEY}
|
||||
|
||||
- **类型:** Literal['_fullmatch']
|
||||
|
||||
- **说明:** 响应触发完整消息 key
|
||||
|
||||
## _var_ `KEYWORD_KEY` {#KEYWORD_KEY}
|
||||
|
||||
- **类型:** Literal['_keyword']
|
||||
|
||||
- **说明:** 响应触发关键字 key
|
@ -0,0 +1,3 @@
|
||||
{
|
||||
"position": 13
|
||||
}
|
@ -0,0 +1,98 @@
|
||||
---
|
||||
sidebar_position: 0
|
||||
description: nonebot.dependencies 模块
|
||||
---
|
||||
|
||||
# nonebot.dependencies
|
||||
|
||||
本模块模块实现了依赖注入的定义与处理。
|
||||
|
||||
## _abstract class_ `Param(default=PydanticUndefined, **kwargs)` {#Param}
|
||||
|
||||
- **说明**
|
||||
|
||||
依赖注入的基本单元 —— 参数。
|
||||
|
||||
继承自 `pydantic.fields.FieldInfo`,用于描述参数信息(不包括参数名)。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `default` (Any)
|
||||
|
||||
- `**kwargs` (Any)
|
||||
|
||||
## _class_ `Dependent(call, params=<factory>, parameterless=<factory>)` {#Dependent}
|
||||
|
||||
- **说明**
|
||||
|
||||
依赖注入容器
|
||||
|
||||
- **参数**
|
||||
|
||||
- `call` ((*Any, \*\*Any) -> (~ R) | (*Any, \*\*Any) -> Awaitable[(~ R)]): 依赖注入的可调用对象,可以是任何 Callable 对象
|
||||
|
||||
- `params` (tuple[pydantic.fields.ModelField]): 具名参数列表
|
||||
|
||||
- `parameterless` (tuple[[Param](#Param)]): 匿名参数列表
|
||||
|
||||
- `pre_checkers`: 依赖注入解析前的参数检查
|
||||
|
||||
- `allow_types`: 允许的参数类型
|
||||
|
||||
### _async method_ `check(self, **params)` {#Dependent-check}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `**params` (Any)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _classmethod_ `parse(cls, *, call, parameterless=None, allow_types)` {#Dependent-parse}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `call` ((*Any, \*\*Any) -> (~ R) | (*Any, \*\*Any) -> Awaitable[(~ R)])
|
||||
|
||||
- `parameterless` (Iterable[Any] | None)
|
||||
|
||||
- `allow_types` (Iterable[Type[[Param](#Param)]])
|
||||
|
||||
- **返回**
|
||||
|
||||
- Dependent[R]
|
||||
|
||||
### _staticmethod_ `parse_parameterless(parameterless, allow_types)` {#Dependent-parse_parameterless}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `parameterless` (tuple[Any, ...])
|
||||
|
||||
- `allow_types` (tuple[Type[[Param](#Param)], ...])
|
||||
|
||||
- **返回**
|
||||
|
||||
- tuple[[Param](#Param), ...]
|
||||
|
||||
### _staticmethod_ `parse_params(call, allow_types)` {#Dependent-parse_params}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `call` ((*Any, \*\*Any) -> (~ R) | (*Any, \*\*Any) -> Awaitable[(~ R)])
|
||||
|
||||
- `allow_types` (tuple[Type[[Param](#Param)], ...])
|
||||
|
||||
- **返回**
|
||||
|
||||
- tuple[pydantic.fields.ModelField]
|
||||
|
||||
### _async method_ `solve(self, **params)` {#Dependent-solve}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `**params` (Any)
|
||||
|
||||
- **返回**
|
||||
|
||||
- dict[str, Any]
|
@ -0,0 +1,48 @@
|
||||
---
|
||||
sidebar_position: 1
|
||||
description: nonebot.dependencies.utils 模块
|
||||
---
|
||||
|
||||
# nonebot.dependencies.utils
|
||||
|
||||
## _def_ `get_typed_signature(call)` {#get_typed_signature}
|
||||
|
||||
- **说明**
|
||||
|
||||
获取可调用对象签名
|
||||
|
||||
- **参数**
|
||||
|
||||
- `call` ((\*Any, \*\*Any) -> Any)
|
||||
|
||||
- **返回**
|
||||
|
||||
- inspect.Signature
|
||||
|
||||
## _def_ `get_typed_annotation(param, globalns)` {#get_typed_annotation}
|
||||
|
||||
- **说明**
|
||||
|
||||
获取参数的类型注解
|
||||
|
||||
- **参数**
|
||||
|
||||
- `param` (inspect.Parameter)
|
||||
|
||||
- `globalns` (dict[str, Any])
|
||||
|
||||
- **返回**
|
||||
|
||||
- Any
|
||||
|
||||
## _def_ `check_field_type(field, value)` {#check_field_type}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `field` (pydantic.fields.ModelField)
|
||||
|
||||
- `value` ((~ V))
|
||||
|
||||
- **返回**
|
||||
|
||||
- (~ V)
|
@ -0,0 +1,3 @@
|
||||
{
|
||||
"position": 14
|
||||
}
|
120
website/versioned_docs/version-2.0.0rc3/api/drivers/aiohttp.md
Normal file
120
website/versioned_docs/version-2.0.0rc3/api/drivers/aiohttp.md
Normal file
@ -0,0 +1,120 @@
|
||||
---
|
||||
sidebar_position: 2
|
||||
description: nonebot.drivers.aiohttp 模块
|
||||
---
|
||||
|
||||
# nonebot.drivers.aiohttp
|
||||
|
||||
[AIOHTTP](https://aiohttp.readthedocs.io/en/stable/) 驱动适配器。
|
||||
|
||||
```bash
|
||||
nb driver install aiohttp
|
||||
# 或者
|
||||
pip install nonebot2[aiohttp]
|
||||
```
|
||||
|
||||
:::tip 提示
|
||||
本驱动仅支持客户端连接
|
||||
:::
|
||||
|
||||
## _class_ `Mixin()` {#Mixin}
|
||||
|
||||
- **说明**
|
||||
|
||||
AIOHTTP Mixin
|
||||
|
||||
### _property_ `type` {#Mixin-type}
|
||||
|
||||
- **类型:** str
|
||||
|
||||
### _async method_ `request(self, setup)` {#Mixin-request}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` (nonebot.internal.driver.model.Request)
|
||||
|
||||
- **返回**
|
||||
|
||||
- nonebot.internal.driver.model.Response
|
||||
|
||||
### _method_ `websocket(self, setup)` {#Mixin-websocket}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` (nonebot.internal.driver.model.Request)
|
||||
|
||||
- **返回**
|
||||
|
||||
- AsyncGenerator[WebSocket, NoneType]
|
||||
|
||||
## _class_ `WebSocket(*, request, session, websocket)` {#WebSocket}
|
||||
|
||||
- **说明**
|
||||
|
||||
AIOHTTP Websocket Wrapper
|
||||
|
||||
- **参数**
|
||||
|
||||
- `request` (nonebot.internal.driver.model.Request)
|
||||
|
||||
- `session` (aiohttp.client.ClientSession)
|
||||
|
||||
- `websocket` (aiohttp.client_ws.ClientWebSocketResponse)
|
||||
|
||||
### _async method_ `accept(self)` {#WebSocket-accept}
|
||||
|
||||
- **返回**
|
||||
|
||||
- Unknown
|
||||
|
||||
### _async method_ `close(self, code=1000)` {#WebSocket-close}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `code` (int)
|
||||
|
||||
- **返回**
|
||||
|
||||
- Unknown
|
||||
|
||||
### _async method_ `receive(self)` {#WebSocket-receive}
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
### _async method_ `receive_bytes(self)` {#WebSocket-receive_bytes}
|
||||
|
||||
- **返回**
|
||||
|
||||
- bytes
|
||||
|
||||
### _async method_ `receive_text(self)` {#WebSocket-receive_text}
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
### _async method_ `send_bytes(self, data)` {#WebSocket-send_bytes}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `data` (bytes)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _async method_ `send_text(self, data)` {#WebSocket-send_text}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `data` (str)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
## _library-attr_ `Driver`
|
||||
|
||||
三方库 API
|
290
website/versioned_docs/version-2.0.0rc3/api/drivers/fastapi.md
Normal file
290
website/versioned_docs/version-2.0.0rc3/api/drivers/fastapi.md
Normal file
@ -0,0 +1,290 @@
|
||||
---
|
||||
sidebar_position: 1
|
||||
description: nonebot.drivers.fastapi 模块
|
||||
---
|
||||
|
||||
# nonebot.drivers.fastapi
|
||||
|
||||
[FastAPI](https://fastapi.tiangolo.com/) 驱动适配
|
||||
|
||||
```bash
|
||||
nb driver install fastapi
|
||||
# 或者
|
||||
pip install nonebot2[fastapi]
|
||||
```
|
||||
|
||||
:::tip 提示
|
||||
本驱动仅支持服务端连接
|
||||
:::
|
||||
|
||||
## _class_ `Config(_env_file='<object object>', _env_file_encoding=None, _env_nested_delimiter=None, _secrets_dir=None, *, fastapi_openapi_url=None, fastapi_docs_url=None, fastapi_redoc_url=None, fastapi_include_adapter_schema=True, fastapi_reload=False, fastapi_reload_dirs=None, fastapi_reload_delay=0.25, fastapi_reload_includes=None, fastapi_reload_excludes=None, fastapi_extra={})` {#Config}
|
||||
|
||||
- **说明**
|
||||
|
||||
FastAPI 驱动框架设置,详情参考 FastAPI 文档
|
||||
|
||||
- **参数**
|
||||
|
||||
- `_env_file` (str | os.PathLike | list[str | os.PathLike] | tuple[str | os.PathLike, ...] | NoneType)
|
||||
|
||||
- `_env_file_encoding` (str | None)
|
||||
|
||||
- `_env_nested_delimiter` (str | None)
|
||||
|
||||
- `_secrets_dir` (str | os.PathLike | NoneType)
|
||||
|
||||
- `fastapi_openapi_url` (str | None)
|
||||
|
||||
- `fastapi_docs_url` (str | None)
|
||||
|
||||
- `fastapi_redoc_url` (str | None)
|
||||
|
||||
- `fastapi_include_adapter_schema` (bool)
|
||||
|
||||
- `fastapi_reload` (bool)
|
||||
|
||||
- `fastapi_reload_dirs` (list[str] | None)
|
||||
|
||||
- `fastapi_reload_delay` (float)
|
||||
|
||||
- `fastapi_reload_includes` (list[str] | None)
|
||||
|
||||
- `fastapi_reload_excludes` (list[str] | None)
|
||||
|
||||
- `fastapi_extra` (dict[str, Any])
|
||||
|
||||
### _class-var_ `fastapi_openapi_url` {#Config-fastapi_openapi_url}
|
||||
|
||||
- **类型:** str | None
|
||||
|
||||
- **说明:** `openapi.json` 地址,默认为 `None` 即关闭
|
||||
|
||||
### _class-var_ `fastapi_docs_url` {#Config-fastapi_docs_url}
|
||||
|
||||
- **类型:** str | None
|
||||
|
||||
- **说明:** `swagger` 地址,默认为 `None` 即关闭
|
||||
|
||||
### _class-var_ `fastapi_redoc_url` {#Config-fastapi_redoc_url}
|
||||
|
||||
- **类型:** str | None
|
||||
|
||||
- **说明:** `redoc` 地址,默认为 `None` 即关闭
|
||||
|
||||
### _class-var_ `fastapi_include_adapter_schema` {#Config-fastapi_include_adapter_schema}
|
||||
|
||||
- **类型:** bool
|
||||
|
||||
- **说明:** 是否包含适配器路由的 schema,默认为 `True`
|
||||
|
||||
### _class-var_ `fastapi_reload` {#Config-fastapi_reload}
|
||||
|
||||
- **类型:** bool
|
||||
|
||||
- **说明:** 开启/关闭冷重载
|
||||
|
||||
### _class-var_ `fastapi_reload_dirs` {#Config-fastapi_reload_dirs}
|
||||
|
||||
- **类型:** list[str] | None
|
||||
|
||||
- **说明:** 重载监控文件夹列表,默认为 uvicorn 默认值
|
||||
|
||||
### _class-var_ `fastapi_reload_delay` {#Config-fastapi_reload_delay}
|
||||
|
||||
- **类型:** float
|
||||
|
||||
- **说明:** 重载延迟,默认为 uvicorn 默认值
|
||||
|
||||
### _class-var_ `fastapi_reload_includes` {#Config-fastapi_reload_includes}
|
||||
|
||||
- **类型:** list[str] | None
|
||||
|
||||
- **说明:** 要监听的文件列表,支持 glob pattern,默认为 uvicorn 默认值
|
||||
|
||||
### _class-var_ `fastapi_reload_excludes` {#Config-fastapi_reload_excludes}
|
||||
|
||||
- **类型:** list[str] | None
|
||||
|
||||
- **说明:** 不要监听的文件列表,支持 glob pattern,默认为 uvicorn 默认值
|
||||
|
||||
### _class-var_ `fastapi_extra` {#Config-fastapi_extra}
|
||||
|
||||
- **类型:** dict[str, Any]
|
||||
|
||||
- **说明:** 传递给 `FastAPI` 的其他参数。
|
||||
|
||||
## _class_ `Driver(env, config)` {#Driver}
|
||||
|
||||
- **说明**
|
||||
|
||||
FastAPI 驱动框架。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `env` ([Env](../config.md#Env))
|
||||
|
||||
- `config` ([Config](../config.md#Config))
|
||||
|
||||
### _property_ `asgi` {#Driver-asgi}
|
||||
|
||||
- **类型:** fastapi.applications.FastAPI
|
||||
|
||||
- **说明:** `FastAPI APP` 对象
|
||||
|
||||
### _property_ `logger` {#Driver-logger}
|
||||
|
||||
- **类型:** logging.Logger
|
||||
|
||||
- **说明:** fastapi 使用的 logger
|
||||
|
||||
### _property_ `server_app` {#Driver-server_app}
|
||||
|
||||
- **类型:** fastapi.applications.FastAPI
|
||||
|
||||
- **说明:** `FastAPI APP` 对象
|
||||
|
||||
### _property_ `type` {#Driver-type}
|
||||
|
||||
- **类型:** str
|
||||
|
||||
- **说明:** 驱动名称: `fastapi`
|
||||
|
||||
### _method_ `on_shutdown(self, func)` {#Driver-on_shutdown}
|
||||
|
||||
- **说明**
|
||||
|
||||
参考文档: `Events <https://fastapi.tiangolo.com/advanced/events/#shutdown-event>`\_
|
||||
|
||||
- **参数**
|
||||
|
||||
- `func` (Callable)
|
||||
|
||||
- **返回**
|
||||
|
||||
- Callable
|
||||
|
||||
### _method_ `on_startup(self, func)` {#Driver-on_startup}
|
||||
|
||||
- **说明**
|
||||
|
||||
参考文档: `Events <https://fastapi.tiangolo.com/advanced/events/#startup-event>`\_
|
||||
|
||||
- **参数**
|
||||
|
||||
- `func` (Callable)
|
||||
|
||||
- **返回**
|
||||
|
||||
- Callable
|
||||
|
||||
### _method_ `run(self, host=None, port=None, *, app=None, **kwargs)` {#Driver-run}
|
||||
|
||||
- **说明**
|
||||
|
||||
使用 `uvicorn` 启动 FastAPI
|
||||
|
||||
- **参数**
|
||||
|
||||
- `host` (str | None)
|
||||
|
||||
- `port` (int | None)
|
||||
|
||||
- `app` (str | None)
|
||||
|
||||
- `**kwargs`
|
||||
|
||||
- **返回**
|
||||
|
||||
- Unknown
|
||||
|
||||
### _method_ `setup_http_server(self, setup)` {#Driver-setup_http_server}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` (nonebot.internal.driver.model.HTTPServerSetup)
|
||||
|
||||
- **返回**
|
||||
|
||||
- Unknown
|
||||
|
||||
### _method_ `setup_websocket_server(self, setup)` {#Driver-setup_websocket_server}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` (nonebot.internal.driver.model.WebSocketServerSetup)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
## _class_ `FastAPIWebSocket(*, request, websocket)` {#FastAPIWebSocket}
|
||||
|
||||
- **说明**
|
||||
|
||||
FastAPI WebSocket Wrapper
|
||||
|
||||
- **参数**
|
||||
|
||||
- `request` (nonebot.internal.driver.model.Request)
|
||||
|
||||
- `websocket` (starlette.websockets.WebSocket)
|
||||
|
||||
### _property_ `closed` {#FastAPIWebSocket-closed}
|
||||
|
||||
- **类型:** bool
|
||||
|
||||
### _async method_ `accept(self)` {#FastAPIWebSocket-accept}
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _async method_ `close(self, code=1000, reason='')` {#FastAPIWebSocket-close}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `code` (int)
|
||||
|
||||
- `reason` (str)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _async method_ `receive(self)` {#FastAPIWebSocket-receive}
|
||||
|
||||
- **返回**
|
||||
|
||||
- str | bytes
|
||||
|
||||
### _async method_ `receive_bytes(self)` {#FastAPIWebSocket-receive_bytes}
|
||||
|
||||
- **返回**
|
||||
|
||||
- bytes
|
||||
|
||||
### _async method_ `receive_text(self)` {#FastAPIWebSocket-receive_text}
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
### _async method_ `send_bytes(self, data)` {#FastAPIWebSocket-send_bytes}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `data` (bytes)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _async method_ `send_text(self, data)` {#FastAPIWebSocket-send_text}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `data` (str)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
52
website/versioned_docs/version-2.0.0rc3/api/drivers/httpx.md
Normal file
52
website/versioned_docs/version-2.0.0rc3/api/drivers/httpx.md
Normal file
@ -0,0 +1,52 @@
|
||||
---
|
||||
sidebar_position: 3
|
||||
description: nonebot.drivers.httpx 模块
|
||||
---
|
||||
|
||||
# nonebot.drivers.httpx
|
||||
|
||||
[HTTPX](https://www.python-httpx.org/) 驱动适配
|
||||
|
||||
```bash
|
||||
nb driver install httpx
|
||||
# 或者
|
||||
pip install nonebot2[httpx]
|
||||
```
|
||||
|
||||
:::tip 提示
|
||||
本驱动仅支持客户端 HTTP 连接
|
||||
:::
|
||||
|
||||
## _class_ `Mixin()` {#Mixin}
|
||||
|
||||
- **说明**
|
||||
|
||||
HTTPX Mixin
|
||||
|
||||
### _property_ `type` {#Mixin-type}
|
||||
|
||||
- **类型:** str
|
||||
|
||||
### _async method_ `request(self, setup)` {#Mixin-request}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` (nonebot.internal.driver.model.Request)
|
||||
|
||||
- **返回**
|
||||
|
||||
- nonebot.internal.driver.model.Response
|
||||
|
||||
### _method_ `websocket(self, setup)` {#Mixin-websocket}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` (nonebot.internal.driver.model.Request)
|
||||
|
||||
- **返回**
|
||||
|
||||
- AsyncGenerator[nonebot.internal.driver.model.WebSocket, NoneType]
|
||||
|
||||
## _library-attr_ `Driver`
|
||||
|
||||
三方库 API
|
538
website/versioned_docs/version-2.0.0rc3/api/drivers/index.md
Normal file
538
website/versioned_docs/version-2.0.0rc3/api/drivers/index.md
Normal file
@ -0,0 +1,538 @@
|
||||
---
|
||||
sidebar_position: 0
|
||||
description: nonebot.drivers 模块
|
||||
---
|
||||
|
||||
# nonebot.drivers
|
||||
|
||||
本模块定义了驱动适配器基类。
|
||||
|
||||
各驱动请继承以下基类。
|
||||
|
||||
## _abstract class_ `Driver(env, config)` {#Driver}
|
||||
|
||||
- **说明**
|
||||
|
||||
Driver 基类。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `env` ([Env](../config.md#Env)): 包含环境信息的 Env 对象
|
||||
|
||||
- `config` ([Config](../config.md#Config)): 包含配置信息的 Config 对象
|
||||
|
||||
### _property_ `bots` {#Driver-bots}
|
||||
|
||||
- **类型:** dict[str, Bot]
|
||||
|
||||
- **说明:** 获取当前所有已连接的 Bot
|
||||
|
||||
### _abstract property_ `logger` {#Driver-logger}
|
||||
|
||||
- **类型:**
|
||||
|
||||
- **说明:** 驱动专属 logger 日志记录器
|
||||
|
||||
### _abstract property_ `type` {#Driver-type}
|
||||
|
||||
- **类型:** str
|
||||
|
||||
- **说明:** 驱动类型名称
|
||||
|
||||
### _classmethod_ `on_bot_connect(cls, func)` {#Driver-on_bot_connect}
|
||||
|
||||
- **说明**
|
||||
|
||||
装饰一个函数使他在 bot 连接成功时执行。
|
||||
|
||||
钩子函数参数:
|
||||
|
||||
- bot: 当前连接上的 Bot 对象
|
||||
|
||||
- **参数**
|
||||
|
||||
- `func` ((*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any])
|
||||
|
||||
- **返回**
|
||||
|
||||
- (\*Any, \*\*Any) -> Any | (\*Any, \*\*Any) -> Awaitable[Any]
|
||||
|
||||
### _classmethod_ `on_bot_disconnect(cls, func)` {#Driver-on_bot_disconnect}
|
||||
|
||||
- **说明**
|
||||
|
||||
装饰一个函数使他在 bot 连接断开时执行。
|
||||
|
||||
钩子函数参数:
|
||||
|
||||
- bot: 当前连接上的 Bot 对象
|
||||
|
||||
- **参数**
|
||||
|
||||
- `func` ((*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any])
|
||||
|
||||
- **返回**
|
||||
|
||||
- (\*Any, \*\*Any) -> Any | (\*Any, \*\*Any) -> Awaitable[Any]
|
||||
|
||||
### _abstract method_ `on_shutdown(self, func)` {#Driver-on_shutdown}
|
||||
|
||||
- **说明**
|
||||
|
||||
注册一个在驱动器停止时执行的函数
|
||||
|
||||
- **参数**
|
||||
|
||||
- `func` (Callable)
|
||||
|
||||
- **返回**
|
||||
|
||||
- Callable
|
||||
|
||||
### _abstract method_ `on_startup(self, func)` {#Driver-on_startup}
|
||||
|
||||
- **说明**
|
||||
|
||||
注册一个在驱动器启动时执行的函数
|
||||
|
||||
- **参数**
|
||||
|
||||
- `func` (Callable)
|
||||
|
||||
- **返回**
|
||||
|
||||
- Callable
|
||||
|
||||
### _method_ `register_adapter(self, adapter, **kwargs)` {#Driver-register_adapter}
|
||||
|
||||
- **说明**
|
||||
|
||||
注册一个协议适配器
|
||||
|
||||
- **参数**
|
||||
|
||||
- `adapter` (Type[Adapter]): 适配器类
|
||||
|
||||
- `**kwargs`: 其他传递给适配器的参数
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _abstract method_ `run(self, *args, **kwargs)` {#Driver-run}
|
||||
|
||||
- **说明**
|
||||
|
||||
启动驱动框架
|
||||
|
||||
- **参数**
|
||||
|
||||
- `*args`
|
||||
|
||||
- `**kwargs`
|
||||
|
||||
- **返回**
|
||||
|
||||
- Unknown
|
||||
|
||||
## _class_ `Cookies(cookies=None)` {#Cookies}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `cookies` (NoneType | Cookies | http.cookiejar.CookieJar | dict[str, str] | list[tuple[str, str]])
|
||||
|
||||
### _method_ `as_header(self, request)` {#Cookies-as_header}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `request` (nonebot.internal.driver.model.Request)
|
||||
|
||||
- **返回**
|
||||
|
||||
- dict[str, str]
|
||||
|
||||
### _method_ `clear(self, domain=None, path=None)` {#Cookies-clear}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `domain` (str | None)
|
||||
|
||||
- `path` (str | None)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _method_ `delete(self, name, domain=None, path=None)` {#Cookies-delete}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `name` (str)
|
||||
|
||||
- `domain` (str | None)
|
||||
|
||||
- `path` (str | None)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _method_ `get(self, name, default=None, domain=None, path=None)` {#Cookies-get}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `name` (str)
|
||||
|
||||
- `default` (str | None)
|
||||
|
||||
- `domain` (str | None)
|
||||
|
||||
- `path` (str | None)
|
||||
|
||||
- **返回**
|
||||
|
||||
- str | None
|
||||
|
||||
### _method_ `set(self, name, value, domain='', path='/')` {#Cookies-set}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `name` (str)
|
||||
|
||||
- `value` (str)
|
||||
|
||||
- `domain` (str)
|
||||
|
||||
- `path` (str)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _method_ `update(self, cookies=None)` {#Cookies-update}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `cookies` (NoneType | Cookies | http.cookiejar.CookieJar | dict[str, str] | list[tuple[str, str]])
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
## _class_ `Request(method, url, *, params=None, headers=None, cookies=None, content=None, data=None, json=None, files=None, version=HTTPVersion.H11, timeout=None, proxy=None)` {#Request}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `method` (str | bytes)
|
||||
|
||||
- `url` (URL | str | tuple[bytes, bytes, int | None, bytes])
|
||||
|
||||
- `params` (NoneType | str | Mapping[str, str | int | float | list[str | int | float]] | list[tuple[str, str | int | float | list[str | int | float]]])
|
||||
|
||||
- `headers` (NoneType | multidict.\_multidict.CIMultiDict[str] | dict[str, str] | list[tuple[str, str]])
|
||||
|
||||
- `cookies` (NoneType | Cookies | http.cookiejar.CookieJar | dict[str, str] | list[tuple[str, str]])
|
||||
|
||||
- `content` (str | bytes | NoneType)
|
||||
|
||||
- `data` (dict | None)
|
||||
|
||||
- `json` (Any)
|
||||
|
||||
- `files` (dict[str, IO[bytes] | bytes | tuple[str | None, IO[bytes] | bytes] | tuple[str | None, IO[bytes] | bytes, str | None]] | list[tuple[str, IO[bytes] | bytes | tuple[str | None, IO[bytes] | bytes] | tuple[str | None, IO[bytes] | bytes, str | None]]] | NoneType)
|
||||
|
||||
- `version` (str | nonebot.internal.driver.model.HTTPVersion)
|
||||
|
||||
- `timeout` (float | None)
|
||||
|
||||
- `proxy` (str | None)
|
||||
|
||||
## _class_ `Response(status_code, *, headers=None, content=None, request=None)` {#Response}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `status_code` (int)
|
||||
|
||||
- `headers` (NoneType | multidict.\_multidict.CIMultiDict[str] | dict[str, str] | list[tuple[str, str]])
|
||||
|
||||
- `content` (str | bytes | NoneType)
|
||||
|
||||
- `request` (nonebot.internal.driver.model.Request | None)
|
||||
|
||||
## _abstract class_ `WebSocket(*, request)` {#WebSocket}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `request` (nonebot.internal.driver.model.Request)
|
||||
|
||||
### _abstract property_ `closed` {#WebSocket-closed}
|
||||
|
||||
- **类型:** bool
|
||||
|
||||
- **说明:** 连接是否已经关闭
|
||||
|
||||
### _abstract async method_ `accept(self)` {#WebSocket-accept}
|
||||
|
||||
- **说明**
|
||||
|
||||
接受 WebSocket 连接请求
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _abstract async method_ `close(self, code=1000, reason='')` {#WebSocket-close}
|
||||
|
||||
- **说明**
|
||||
|
||||
关闭 WebSocket 连接请求
|
||||
|
||||
- **参数**
|
||||
|
||||
- `code` (int)
|
||||
|
||||
- `reason` (str)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _abstract async method_ `receive(self)` {#WebSocket-receive}
|
||||
|
||||
- **说明**
|
||||
|
||||
接收一条 WebSocket text/bytes 信息
|
||||
|
||||
- **返回**
|
||||
|
||||
- str | bytes
|
||||
|
||||
### _abstract async method_ `receive_bytes(self)` {#WebSocket-receive_bytes}
|
||||
|
||||
- **说明**
|
||||
|
||||
接收一条 WebSocket binary 信息
|
||||
|
||||
- **返回**
|
||||
|
||||
- bytes
|
||||
|
||||
### _abstract async method_ `receive_text(self)` {#WebSocket-receive_text}
|
||||
|
||||
- **说明**
|
||||
|
||||
接收一条 WebSocket text 信息
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
### _async method_ `send(self, data)` {#WebSocket-send}
|
||||
|
||||
- **说明**
|
||||
|
||||
发送一条 WebSocket text/bytes 信息
|
||||
|
||||
- **参数**
|
||||
|
||||
- `data` (str | bytes)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _abstract async method_ `send_bytes(self, data)` {#WebSocket-send_bytes}
|
||||
|
||||
- **说明**
|
||||
|
||||
发送一条 WebSocket binary 信息
|
||||
|
||||
- **参数**
|
||||
|
||||
- `data` (bytes)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _abstract async method_ `send_text(self, data)` {#WebSocket-send_text}
|
||||
|
||||
- **说明**
|
||||
|
||||
发送一条 WebSocket text 信息
|
||||
|
||||
- **参数**
|
||||
|
||||
- `data` (str)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
## _enum_ `HTTPVersion` {#HTTPVersion}
|
||||
|
||||
- **说明**
|
||||
|
||||
An enumeration.
|
||||
|
||||
- **枚举成员**
|
||||
|
||||
- `H10`
|
||||
|
||||
- `H11`
|
||||
|
||||
- `H2`
|
||||
|
||||
## _abstract class_ `ForwardMixin()` {#ForwardMixin}
|
||||
|
||||
- **说明**
|
||||
|
||||
客户端混入基类。
|
||||
|
||||
### _abstract property_ `type` {#ForwardMixin-type}
|
||||
|
||||
- **类型:** str
|
||||
|
||||
- **说明:** 客户端驱动类型名称
|
||||
|
||||
### _abstract async method_ `request(self, setup)` {#ForwardMixin-request}
|
||||
|
||||
- **说明**
|
||||
|
||||
发送一个 HTTP 请求
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` (nonebot.internal.driver.model.Request)
|
||||
|
||||
- **返回**
|
||||
|
||||
- nonebot.internal.driver.model.Response
|
||||
|
||||
### _abstract method_ `websocket(self, setup)` {#ForwardMixin-websocket}
|
||||
|
||||
- **说明**
|
||||
|
||||
发起一个 WebSocket 连接
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` (nonebot.internal.driver.model.Request)
|
||||
|
||||
- **返回**
|
||||
|
||||
- AsyncGenerator[nonebot.internal.driver.model.WebSocket, NoneType]
|
||||
|
||||
## _abstract class_ `ForwardDriver(env, config)` {#ForwardDriver}
|
||||
|
||||
- **说明**
|
||||
|
||||
客户端基类。将客户端框架封装,以满足适配器使用。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `env` ([Env](../config.md#Env))
|
||||
|
||||
- `config` ([Config](../config.md#Config))
|
||||
|
||||
## _abstract class_ `ReverseDriver(env, config)` {#ReverseDriver}
|
||||
|
||||
- **说明**
|
||||
|
||||
服务端基类。将后端框架封装,以满足适配器使用。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `env` ([Env](../config.md#Env))
|
||||
|
||||
- `config` ([Config](../config.md#Config))
|
||||
|
||||
### _abstract property_ `asgi` {#ReverseDriver-asgi}
|
||||
|
||||
- **类型:** Any
|
||||
|
||||
- **说明:** 驱动 ASGI 对象
|
||||
|
||||
### _abstract property_ `server_app` {#ReverseDriver-server_app}
|
||||
|
||||
- **类型:** Any
|
||||
|
||||
- **说明:** 驱动 APP 对象
|
||||
|
||||
### _abstract method_ `setup_http_server(self, setup)` {#ReverseDriver-setup_http_server}
|
||||
|
||||
- **说明**
|
||||
|
||||
设置一个 HTTP 服务器路由配置
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` (HTTPServerSetup)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _abstract method_ `setup_websocket_server(self, setup)` {#ReverseDriver-setup_websocket_server}
|
||||
|
||||
- **说明**
|
||||
|
||||
设置一个 WebSocket 服务器路由配置
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` (WebSocketServerSetup)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
## _def_ `combine_driver(driver, *mixins)` {#combine_driver}
|
||||
|
||||
- **说明**
|
||||
|
||||
将一个驱动器和多个混入类合并。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `driver` (Type[nonebot.internal.driver.driver.Driver])
|
||||
|
||||
- `*mixins` (Type[nonebot.internal.driver.driver.ForwardMixin])
|
||||
|
||||
- **返回**
|
||||
|
||||
- Type[nonebot.internal.driver.driver.Driver]
|
||||
|
||||
## _class_ `HTTPServerSetup(path, method, name, handle_func)` {#HTTPServerSetup}
|
||||
|
||||
- **说明**
|
||||
|
||||
HTTP 服务器路由配置。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `path` (yarl.URL)
|
||||
|
||||
- `method` (str)
|
||||
|
||||
- `name` (str)
|
||||
|
||||
- `handle_func` ((nonebot.internal.driver.model.Request) -> Awaitable[nonebot.internal.driver.model.Response])
|
||||
|
||||
## _class_ `WebSocketServerSetup(path, name, handle_func)` {#WebSocketServerSetup}
|
||||
|
||||
- **说明**
|
||||
|
||||
WebSocket 服务器路由配置。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `path` (yarl.URL)
|
||||
|
||||
- `name` (str)
|
||||
|
||||
- `handle_func` ((nonebot.internal.driver.model.WebSocket) -> Awaitable[Any])
|
||||
|
||||
## _library-attr_ `URL`
|
||||
|
||||
三方库 API
|
80
website/versioned_docs/version-2.0.0rc3/api/drivers/none.md
Normal file
80
website/versioned_docs/version-2.0.0rc3/api/drivers/none.md
Normal file
@ -0,0 +1,80 @@
|
||||
---
|
||||
sidebar_position: 6
|
||||
description: nonebot.drivers.none 模块
|
||||
---
|
||||
|
||||
# nonebot.drivers.none
|
||||
|
||||
None 驱动适配
|
||||
|
||||
:::tip 提示
|
||||
本驱动不支持任何服务器或客户端连接
|
||||
:::
|
||||
|
||||
## _class_ `Driver(env, config)` {#Driver}
|
||||
|
||||
- **说明**
|
||||
|
||||
None 驱动框架
|
||||
|
||||
- **参数**
|
||||
|
||||
- `env` ([Env](../config.md#Env))
|
||||
|
||||
- `config` ([Config](../config.md#Config))
|
||||
|
||||
### _property_ `logger` {#Driver-logger}
|
||||
|
||||
- **类型:**
|
||||
|
||||
- **说明:** none driver 使用的 logger
|
||||
|
||||
### _property_ `type` {#Driver-type}
|
||||
|
||||
- **类型:** str
|
||||
|
||||
- **说明:** 驱动名称: `none`
|
||||
|
||||
### _method_ `on_shutdown(self, func)` {#Driver-on_shutdown}
|
||||
|
||||
- **说明**
|
||||
|
||||
注册一个停止时执行的函数
|
||||
|
||||
- **参数**
|
||||
|
||||
- `func` (() -> NoneType | () -> Awaitable[NoneType])
|
||||
|
||||
- **返回**
|
||||
|
||||
- () -> NoneType | () -> Awaitable[NoneType]
|
||||
|
||||
### _method_ `on_startup(self, func)` {#Driver-on_startup}
|
||||
|
||||
- **说明**
|
||||
|
||||
注册一个启动时执行的函数
|
||||
|
||||
- **参数**
|
||||
|
||||
- `func` (() -> NoneType | () -> Awaitable[NoneType])
|
||||
|
||||
- **返回**
|
||||
|
||||
- () -> NoneType | () -> Awaitable[NoneType]
|
||||
|
||||
### _method_ `run(self, *args, **kwargs)` {#Driver-run}
|
||||
|
||||
- **说明**
|
||||
|
||||
启动 none driver
|
||||
|
||||
- **参数**
|
||||
|
||||
- `*args`
|
||||
|
||||
- `**kwargs`
|
||||
|
||||
- **返回**
|
||||
|
||||
- Unknown
|
254
website/versioned_docs/version-2.0.0rc3/api/drivers/quart.md
Normal file
254
website/versioned_docs/version-2.0.0rc3/api/drivers/quart.md
Normal file
@ -0,0 +1,254 @@
|
||||
---
|
||||
sidebar_position: 5
|
||||
description: nonebot.drivers.quart 模块
|
||||
---
|
||||
|
||||
# nonebot.drivers.quart
|
||||
|
||||
[Quart](https://pgjones.gitlab.io/quart/index.html) 驱动适配
|
||||
|
||||
```bash
|
||||
nb driver install quart
|
||||
# 或者
|
||||
pip install nonebot2[quart]
|
||||
```
|
||||
|
||||
:::tip 提示
|
||||
本驱动仅支持服务端连接
|
||||
:::
|
||||
|
||||
## _class_ `Config(_env_file='<object object>', _env_file_encoding=None, _env_nested_delimiter=None, _secrets_dir=None, *, quart_reload=False, quart_reload_dirs=None, quart_reload_delay=0.25, quart_reload_includes=None, quart_reload_excludes=None, quart_extra={})` {#Config}
|
||||
|
||||
- **说明**
|
||||
|
||||
Quart 驱动框架设置
|
||||
|
||||
- **参数**
|
||||
|
||||
- `_env_file` (str | os.PathLike | list[str | os.PathLike] | tuple[str | os.PathLike, ...] | NoneType)
|
||||
|
||||
- `_env_file_encoding` (str | None)
|
||||
|
||||
- `_env_nested_delimiter` (str | None)
|
||||
|
||||
- `_secrets_dir` (str | os.PathLike | NoneType)
|
||||
|
||||
- `quart_reload` (bool)
|
||||
|
||||
- `quart_reload_dirs` (list[str] | None)
|
||||
|
||||
- `quart_reload_delay` (float)
|
||||
|
||||
- `quart_reload_includes` (list[str] | None)
|
||||
|
||||
- `quart_reload_excludes` (list[str] | None)
|
||||
|
||||
- `quart_extra` (dict[str, Any])
|
||||
|
||||
### _class-var_ `quart_reload` {#Config-quart_reload}
|
||||
|
||||
- **类型:** bool
|
||||
|
||||
- **说明:** 开启/关闭冷重载
|
||||
|
||||
### _class-var_ `quart_reload_dirs` {#Config-quart_reload_dirs}
|
||||
|
||||
- **类型:** list[str] | None
|
||||
|
||||
- **说明:** 重载监控文件夹列表,默认为 uvicorn 默认值
|
||||
|
||||
### _class-var_ `quart_reload_delay` {#Config-quart_reload_delay}
|
||||
|
||||
- **类型:** float
|
||||
|
||||
- **说明:** 重载延迟,默认为 uvicorn 默认值
|
||||
|
||||
### _class-var_ `quart_reload_includes` {#Config-quart_reload_includes}
|
||||
|
||||
- **类型:** list[str] | None
|
||||
|
||||
- **说明:** 要监听的文件列表,支持 glob pattern,默认为 uvicorn 默认值
|
||||
|
||||
### _class-var_ `quart_reload_excludes` {#Config-quart_reload_excludes}
|
||||
|
||||
- **类型:** list[str] | None
|
||||
|
||||
- **说明:** 不要监听的文件列表,支持 glob pattern,默认为 uvicorn 默认值
|
||||
|
||||
### _class-var_ `quart_extra` {#Config-quart_extra}
|
||||
|
||||
- **类型:** dict[str, Any]
|
||||
|
||||
- **说明:** 传递给 `Quart` 的其他参数。
|
||||
|
||||
## _class_ `Driver(env, config)` {#Driver}
|
||||
|
||||
- **说明**
|
||||
|
||||
Quart 驱动框架
|
||||
|
||||
- **参数**
|
||||
|
||||
- `env` ([Env](../config.md#Env))
|
||||
|
||||
- `config` ([Config](../config.md#Config))
|
||||
|
||||
### _property_ `asgi` {#Driver-asgi}
|
||||
|
||||
- **类型:**
|
||||
|
||||
- **说明:** `Quart` 对象
|
||||
|
||||
### _property_ `logger` {#Driver-logger}
|
||||
|
||||
- **类型:**
|
||||
|
||||
- **说明:** Quart 使用的 logger
|
||||
|
||||
### _property_ `server_app` {#Driver-server_app}
|
||||
|
||||
- **类型:** quart.app.Quart
|
||||
|
||||
- **说明:** `Quart` 对象
|
||||
|
||||
### _property_ `type` {#Driver-type}
|
||||
|
||||
- **类型:** str
|
||||
|
||||
- **说明:** 驱动名称: `quart`
|
||||
|
||||
### _method_ `on_shutdown(self, func)` {#Driver-on_shutdown}
|
||||
|
||||
- **说明**
|
||||
|
||||
参考文档: [`Startup and Shutdown`](https://pgjones.gitlab.io/quart/how_to_guides/startup_shutdown.html)
|
||||
|
||||
- **参数**
|
||||
|
||||
- `func` ((~ \_AsyncCallable))
|
||||
|
||||
- **返回**
|
||||
|
||||
- (~ \_AsyncCallable)
|
||||
|
||||
### _method_ `on_startup(self, func)` {#Driver-on_startup}
|
||||
|
||||
- **说明**
|
||||
|
||||
参考文档: [`Startup and Shutdown`](https://pgjones.gitlab.io/quart/how_to_guides/startup_shutdown.html)
|
||||
|
||||
- **参数**
|
||||
|
||||
- `func` ((~ \_AsyncCallable))
|
||||
|
||||
- **返回**
|
||||
|
||||
- (~ \_AsyncCallable)
|
||||
|
||||
### _method_ `run(self, host=None, port=None, *, app=None, **kwargs)` {#Driver-run}
|
||||
|
||||
- **说明**
|
||||
|
||||
使用 `uvicorn` 启动 Quart
|
||||
|
||||
- **参数**
|
||||
|
||||
- `host` (str | None)
|
||||
|
||||
- `port` (int | None)
|
||||
|
||||
- `app` (str | None)
|
||||
|
||||
- `**kwargs`
|
||||
|
||||
- **返回**
|
||||
|
||||
- Unknown
|
||||
|
||||
### _method_ `setup_http_server(self, setup)` {#Driver-setup_http_server}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` (nonebot.internal.driver.model.HTTPServerSetup)
|
||||
|
||||
- **返回**
|
||||
|
||||
- Unknown
|
||||
|
||||
### _method_ `setup_websocket_server(self, setup)` {#Driver-setup_websocket_server}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` (nonebot.internal.driver.model.WebSocketServerSetup)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
## _class_ `WebSocket(*, request, websocket)` {#WebSocket}
|
||||
|
||||
- **说明**
|
||||
|
||||
Quart WebSocket Wrapper
|
||||
|
||||
- **参数**
|
||||
|
||||
- `request` (nonebot.internal.driver.model.Request)
|
||||
|
||||
- `websocket` (quart.wrappers.websocket.Websocket)
|
||||
|
||||
### _async method_ `accept(self)` {#WebSocket-accept}
|
||||
|
||||
- **返回**
|
||||
|
||||
- Unknown
|
||||
|
||||
### _async method_ `close(self, code=1000, reason='')` {#WebSocket-close}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `code` (int)
|
||||
|
||||
- `reason` (str)
|
||||
|
||||
- **返回**
|
||||
|
||||
- Unknown
|
||||
|
||||
### _async method_ `receive(self)` {#WebSocket-receive}
|
||||
|
||||
- **返回**
|
||||
|
||||
- str | bytes
|
||||
|
||||
### _async method_ `receive_bytes(self)` {#WebSocket-receive_bytes}
|
||||
|
||||
- **返回**
|
||||
|
||||
- bytes
|
||||
|
||||
### _async method_ `receive_text(self)` {#WebSocket-receive_text}
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
### _async method_ `send_bytes(self, data)` {#WebSocket-send_bytes}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `data` (bytes)
|
||||
|
||||
- **返回**
|
||||
|
||||
- Unknown
|
||||
|
||||
### _async method_ `send_text(self, data)` {#WebSocket-send_text}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `data` (str)
|
||||
|
||||
- **返回**
|
||||
|
||||
- Unknown
|
@ -0,0 +1,134 @@
|
||||
---
|
||||
sidebar_position: 4
|
||||
description: nonebot.drivers.websockets 模块
|
||||
---
|
||||
|
||||
# nonebot.drivers.websockets
|
||||
|
||||
[websockets](https://websockets.readthedocs.io/) 驱动适配
|
||||
|
||||
```bash
|
||||
nb driver install websockets
|
||||
# 或者
|
||||
pip install nonebot2[websockets]
|
||||
```
|
||||
|
||||
:::tip 提示
|
||||
本驱动仅支持客户端 WebSocket 连接
|
||||
:::
|
||||
|
||||
## _def_ `catch_closed(func)` {#catch_closed}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `func`
|
||||
|
||||
- **返回**
|
||||
|
||||
- Unknown
|
||||
|
||||
## _class_ `Mixin()` {#Mixin}
|
||||
|
||||
- **说明**
|
||||
|
||||
Websockets Mixin
|
||||
|
||||
### _property_ `type` {#Mixin-type}
|
||||
|
||||
- **类型:** str
|
||||
|
||||
### _async method_ `request(self, setup)` {#Mixin-request}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` (nonebot.internal.driver.model.Request)
|
||||
|
||||
- **返回**
|
||||
|
||||
- nonebot.internal.driver.model.Response
|
||||
|
||||
### _method_ `websocket(self, setup)` {#Mixin-websocket}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` (nonebot.internal.driver.model.Request)
|
||||
|
||||
- **返回**
|
||||
|
||||
- AsyncGenerator[WebSocket, NoneType]
|
||||
|
||||
## _class_ `WebSocket(*, request, websocket)` {#WebSocket}
|
||||
|
||||
- **说明**
|
||||
|
||||
Websockets WebSocket Wrapper
|
||||
|
||||
- **参数**
|
||||
|
||||
- `request` (nonebot.internal.driver.model.Request)
|
||||
|
||||
- `websocket` (websockets.legacy.client.WebSocketClientProtocol)
|
||||
|
||||
### _property_ `closed` {#WebSocket-closed}
|
||||
|
||||
- **类型:** bool
|
||||
|
||||
### _async method_ `accept(self)` {#WebSocket-accept}
|
||||
|
||||
- **返回**
|
||||
|
||||
- Unknown
|
||||
|
||||
### _async method_ `close(self, code=1000, reason='')` {#WebSocket-close}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `code` (int)
|
||||
|
||||
- `reason` (str)
|
||||
|
||||
- **返回**
|
||||
|
||||
- Unknown
|
||||
|
||||
### _async method_ `receive(self)` {#WebSocket-receive}
|
||||
|
||||
- **返回**
|
||||
|
||||
- str | bytes
|
||||
|
||||
### _async method_ `receive_bytes(self)` {#WebSocket-receive_bytes}
|
||||
|
||||
- **返回**
|
||||
|
||||
- bytes
|
||||
|
||||
### _async method_ `receive_text(self)` {#WebSocket-receive_text}
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
### _async method_ `send_bytes(self, data)` {#WebSocket-send_bytes}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `data` (bytes)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _async method_ `send_text(self, data)` {#WebSocket-send_text}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `data` (str)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
## _library-attr_ `Driver`
|
||||
|
||||
三方库 API
|
260
website/versioned_docs/version-2.0.0rc3/api/exception.md
Normal file
260
website/versioned_docs/version-2.0.0rc3/api/exception.md
Normal file
@ -0,0 +1,260 @@
|
||||
---
|
||||
sidebar_position: 10
|
||||
description: nonebot.exception 模块
|
||||
---
|
||||
|
||||
# nonebot.exception
|
||||
|
||||
本模块包含了所有 NoneBot 运行时可能会抛出的异常。
|
||||
|
||||
这些异常并非所有需要用户处理,在 NoneBot 内部运行时被捕获,并进行对应操作。
|
||||
|
||||
```bash
|
||||
NoneBotException
|
||||
├── ParserExit
|
||||
├── ProcessException
|
||||
| ├── IgnoredException
|
||||
| ├── SkippedException
|
||||
| | └── TypeMisMatch
|
||||
| ├── MockApiException
|
||||
| └── StopPropagation
|
||||
├── MatcherException
|
||||
| ├── PausedException
|
||||
| ├── RejectedException
|
||||
| └── FinishedException
|
||||
├── AdapterException
|
||||
| ├── NoLogException
|
||||
| ├── ApiNotAvailable
|
||||
| ├── NetworkError
|
||||
| └── ActionFailed
|
||||
└── DriverException
|
||||
└── WebSocketClosed
|
||||
```
|
||||
|
||||
## _class_ `NoneBotException()` {#NoneBotException}
|
||||
|
||||
- **说明**
|
||||
|
||||
所有 NoneBot 发生的异常基类。
|
||||
|
||||
## _class_ `ParserExit(status=0, message=None)` {#ParserExit}
|
||||
|
||||
- **说明**
|
||||
|
||||
[shell_command](./rule.md#shell_command) 处理消息失败时返回的异常
|
||||
|
||||
- **参数**
|
||||
|
||||
- `status` (int)
|
||||
|
||||
- `message` (str | None)
|
||||
|
||||
## _class_ `ProcessException()` {#ProcessException}
|
||||
|
||||
- **说明**
|
||||
|
||||
事件处理过程中发生的异常基类。
|
||||
|
||||
## _class_ `IgnoredException(reason)` {#IgnoredException}
|
||||
|
||||
- **说明**
|
||||
|
||||
指示 NoneBot 应该忽略该事件。可由 PreProcessor 抛出。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `reason` (Any): 忽略事件的原因
|
||||
|
||||
## _class_ `SkippedException()` {#SkippedException}
|
||||
|
||||
- **说明**
|
||||
|
||||
指示 NoneBot 立即结束当前 `Dependent` 的运行。
|
||||
|
||||
例如,可以在 `Handler` 中通过 [Matcher.skip](./matcher.md#Matcher-skip) 抛出。
|
||||
|
||||
- **用法**
|
||||
|
||||
```python
|
||||
def always_skip():
|
||||
Matcher.skip()
|
||||
|
||||
@matcher.handle()
|
||||
async def handler(dependency = Depends(always_skip)):
|
||||
# never run
|
||||
```
|
||||
|
||||
## _class_ `TypeMisMatch(param, value)` {#TypeMisMatch}
|
||||
|
||||
- **说明**
|
||||
|
||||
当前 `Handler` 的参数类型不匹配。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `param` (pydantic.fields.ModelField)
|
||||
|
||||
- `value` (Any)
|
||||
|
||||
## _class_ `MockApiException(result)` {#MockApiException}
|
||||
|
||||
- **说明**
|
||||
|
||||
指示 NoneBot 阻止本次 API 调用或修改本次调用返回值,并返回自定义内容。可由 api hook 抛出。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `result` (Any): 返回的内容
|
||||
|
||||
## _class_ `StopPropagation()` {#StopPropagation}
|
||||
|
||||
- **说明**
|
||||
|
||||
指示 NoneBot 终止事件向下层传播。
|
||||
|
||||
在 {ref}`nonebot.matcher.Matcher.block` 为 `True`
|
||||
或使用 [Matcher.stop_propagation](./matcher.md#Matcher-stop_propagation) 方法时抛出。
|
||||
|
||||
- **用法**
|
||||
|
||||
```python
|
||||
matcher = on_notice(block=True)
|
||||
# 或者
|
||||
@matcher.handle()
|
||||
async def handler(matcher: Matcher):
|
||||
matcher.stop_propagation()
|
||||
```
|
||||
|
||||
## _class_ `MatcherException()` {#MatcherException}
|
||||
|
||||
- **说明**
|
||||
|
||||
所有 Matcher 发生的异常基类。
|
||||
|
||||
## _class_ `PausedException()` {#PausedException}
|
||||
|
||||
- **说明**
|
||||
|
||||
指示 NoneBot 结束当前 `Handler` 并等待下一条消息后继续下一个 `Handler`。可用于用户输入新信息。
|
||||
|
||||
可以在 `Handler` 中通过 [Matcher.pause](./matcher.md#Matcher-pause) 抛出。
|
||||
|
||||
- **用法**
|
||||
|
||||
```python
|
||||
@matcher.handle()
|
||||
async def handler():
|
||||
await matcher.pause("some message")
|
||||
```
|
||||
|
||||
## _class_ `RejectedException()` {#RejectedException}
|
||||
|
||||
- **说明**
|
||||
|
||||
指示 NoneBot 结束当前 `Handler` 并等待下一条消息后重新运行当前 `Handler`。可用于用户重新输入。
|
||||
|
||||
可以在 `Handler` 中通过 [Matcher.reject](./matcher.md#Matcher-reject) 抛出。
|
||||
|
||||
- **用法**
|
||||
|
||||
```python
|
||||
@matcher.handle()
|
||||
async def handler():
|
||||
await matcher.reject("some message")
|
||||
```
|
||||
|
||||
## _class_ `FinishedException()` {#FinishedException}
|
||||
|
||||
- **说明**
|
||||
|
||||
指示 NoneBot 结束当前 `Handler` 且后续 `Handler` 不再被运行。可用于结束用户会话。
|
||||
|
||||
可以在 `Handler` 中通过 [Matcher.finish](./matcher.md#Matcher-finish) 抛出。
|
||||
|
||||
- **用法**
|
||||
|
||||
```python
|
||||
@matcher.handle()
|
||||
async def handler():
|
||||
await matcher.finish("some message")
|
||||
```
|
||||
|
||||
## _class_ `AdapterException(adapter_name, *args)` {#AdapterException}
|
||||
|
||||
- **说明**
|
||||
|
||||
代表 `Adapter` 抛出的异常,所有的 `Adapter` 都要在内部继承自这个 `Exception`
|
||||
|
||||
- **参数**
|
||||
|
||||
- `adapter_name` (str): 标识 adapter
|
||||
|
||||
- `*args` (object)
|
||||
|
||||
## _class_ `NoLogException(adapter_name, *args)` {#NoLogException}
|
||||
|
||||
- **说明**
|
||||
|
||||
指示 NoneBot 对当前 `Event` 进行处理但不显示 Log 信息。
|
||||
|
||||
可在 [Event.get_log_string](./adapters/index.md#Event-get_log_string) 时抛出
|
||||
|
||||
- **参数**
|
||||
|
||||
- `adapter_name` (str)
|
||||
|
||||
- `*args` (object)
|
||||
|
||||
## _class_ `ApiNotAvailable(adapter_name, *args)` {#ApiNotAvailable}
|
||||
|
||||
- **说明**
|
||||
|
||||
在 API 连接不可用时抛出。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `adapter_name` (str)
|
||||
|
||||
- `*args` (object)
|
||||
|
||||
## _class_ `NetworkError(adapter_name, *args)` {#NetworkError}
|
||||
|
||||
- **说明**
|
||||
|
||||
在网络出现问题时抛出,如: API 请求地址不正确, API 请求无返回或返回状态非正常等。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `adapter_name` (str)
|
||||
|
||||
- `*args` (object)
|
||||
|
||||
## _class_ `ActionFailed(adapter_name, *args)` {#ActionFailed}
|
||||
|
||||
- **说明**
|
||||
|
||||
API 请求成功返回数据,但 API 操作失败。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `adapter_name` (str)
|
||||
|
||||
- `*args` (object)
|
||||
|
||||
## _class_ `DriverException()` {#DriverException}
|
||||
|
||||
- **说明**
|
||||
|
||||
`Driver` 抛出的异常基类
|
||||
|
||||
## _class_ `WebSocketClosed(code, reason=None)` {#WebSocketClosed}
|
||||
|
||||
- **说明**
|
||||
|
||||
WebSocket 连接已关闭
|
||||
|
||||
- **参数**
|
||||
|
||||
- `code` (int)
|
||||
|
||||
- `reason` (str | None)
|
207
website/versioned_docs/version-2.0.0rc3/api/index.md
Normal file
207
website/versioned_docs/version-2.0.0rc3/api/index.md
Normal file
@ -0,0 +1,207 @@
|
||||
---
|
||||
sidebar_position: 0
|
||||
description: nonebot 模块
|
||||
---
|
||||
|
||||
# nonebot
|
||||
|
||||
本模块主要定义了 NoneBot 启动所需函数,供 bot 入口文件调用。
|
||||
|
||||
## 快捷导入
|
||||
|
||||
为方便使用,本模块从子模块导入了部分内容,以下内容可以直接通过本模块导入:
|
||||
|
||||
- `on` => [`on`](./plugin/on.md#on)
|
||||
- `on_metaevent` => [`on_metaevent`](./plugin/on.md#on_metaevent)
|
||||
- `on_message` => [`on_message`](./plugin/on.md#on_message)
|
||||
- `on_notice` => [`on_notice`](./plugin/on.md#on_notice)
|
||||
- `on_request` => [`on_request`](./plugin/on.md#on_request)
|
||||
- `on_startswith` => [`on_startswith`](./plugin/on.md#on_startswith)
|
||||
- `on_endswith` => [`on_endswith`](./plugin/on.md#on_endswith)
|
||||
- `on_fullmatch` => [`on_fullmatch`](./plugin/on.md#on_fullmatch)
|
||||
- `on_keyword` => [`on_keyword`](./plugin/on.md#on_keyword)
|
||||
- `on_command` => [`on_command`](./plugin/on.md#on_command)
|
||||
- `on_shell_command` => [`on_shell_command`](./plugin/on.md#on_shell_command)
|
||||
- `on_regex` => [`on_regex`](./plugin/on.md#on_regex)
|
||||
- `on_type` => [`on_type`](./plugin/on.md#on_type)
|
||||
- `CommandGroup` => [`CommandGroup`](./plugin/on.md#CommandGroup)
|
||||
- `Matchergroup` => [`MatcherGroup`](./plugin/on.md#MatcherGroup)
|
||||
- `load_plugin` => [`load_plugin`](./plugin/load.md#load_plugin)
|
||||
- `load_plugins` => [`load_plugins`](./plugin/load.md#load_plugins)
|
||||
- `load_all_plugins` => [`load_all_plugins`](./plugin/load.md#load_all_plugins)
|
||||
- `load_from_json` => [`load_from_json`](./plugin/load.md#load_from_json)
|
||||
- `load_from_toml` => [`load_from_toml`](./plugin/load.md#load_from_toml)
|
||||
- `load_builtin_plugin` => [`load_builtin_plugin`](./plugin/load.md#load_builtin_plugin)
|
||||
- `load_builtin_plugins` => [`load_builtin_plugins`](./plugin/load.md#load_builtin_plugins)
|
||||
- `get_plugin` => [`get_plugin`](./plugin/index.md#get_plugin)
|
||||
- `get_plugin_by_module_name` => [`get_plugin_by_module_name`](./plugin/index.md#get_plugin_by_module_name)
|
||||
- `get_loaded_plugins` => [`get_loaded_plugins`](./plugin/index.md#get_loaded_plugins)
|
||||
- `get_available_plugin_names` => [`get_available_plugin_names`](./plugin/index.md#get_available_plugin_names)
|
||||
- `require` => [`require`](./plugin/load.md#require)
|
||||
|
||||
## _def_ `get_driver()` {#get_driver}
|
||||
|
||||
- **说明**
|
||||
|
||||
获取全局 [Driver](./drivers/index.md#Driver) 实例。
|
||||
|
||||
可用于在计划任务的回调等情形中获取当前 [Driver](./drivers/index.md#Driver) 实例。
|
||||
|
||||
- **返回**
|
||||
|
||||
- nonebot.internal.driver.driver.Driver: 全局 [Driver](./drivers/index.md#Driver) 对象
|
||||
|
||||
- **异常**
|
||||
|
||||
- `ValueError`: 全局 [Driver](./drivers/index.md#Driver) 对象尚未初始化 ([nonebot.init](#init) 尚未调用)
|
||||
|
||||
- **用法**
|
||||
|
||||
```python
|
||||
driver = nonebot.get_driver()
|
||||
```
|
||||
|
||||
## _def_ `get_app()` {#get_app}
|
||||
|
||||
- **说明**
|
||||
|
||||
获取全局 [ReverseDriver](./drivers/index.md#ReverseDriver) 对应的 Server App 对象。
|
||||
|
||||
- **返回**
|
||||
|
||||
- Any: Server App 对象
|
||||
|
||||
- **异常**
|
||||
|
||||
- `AssertionError`: 全局 Driver 对象不是 [ReverseDriver](./drivers/index.md#ReverseDriver) 类型
|
||||
|
||||
- `ValueError`: 全局 [Driver](./drivers/index.md#Driver) 对象尚未初始化 ([nonebot.init](#init) 尚未调用)
|
||||
|
||||
- **用法**
|
||||
|
||||
```python
|
||||
app = nonebot.get_app()
|
||||
```
|
||||
|
||||
## _def_ `get_asgi()` {#get_asgi}
|
||||
|
||||
- **说明**
|
||||
|
||||
获取全局 [ReverseDriver](./drivers/index.md#ReverseDriver) 对应 [ASGI](https://asgi.readthedocs.io/) 对象。
|
||||
|
||||
- **返回**
|
||||
|
||||
- Any: ASGI 对象
|
||||
|
||||
- **异常**
|
||||
|
||||
- `AssertionError`: 全局 Driver 对象不是 [ReverseDriver](./drivers/index.md#ReverseDriver) 类型
|
||||
|
||||
- `ValueError`: 全局 [Driver](./drivers/index.md#Driver) 对象尚未初始化 ([nonebot.init](#init) 尚未调用)
|
||||
|
||||
- **用法**
|
||||
|
||||
```python
|
||||
asgi = nonebot.get_asgi()
|
||||
```
|
||||
|
||||
## _def_ `get_bot(self_id=None)` {#get_bot}
|
||||
|
||||
- **说明**
|
||||
|
||||
获取一个连接到 NoneBot 的 [Bot](./adapters/index.md#Bot) 对象。
|
||||
|
||||
当提供 `self_id` 时,此函数是 `get_bots()[self_id]` 的简写;
|
||||
当不提供时,返回一个 [Bot](./adapters/index.md#Bot)。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `self_id` (str | None): 用来识别 [Bot](./adapters/index.md#Bot) 的 {ref}`nonebot.adapters.Bot.self_id` 属性
|
||||
|
||||
- **返回**
|
||||
|
||||
- nonebot.internal.adapter.bot.Bot: [Bot](./adapters/index.md#Bot) 对象
|
||||
|
||||
- **异常**
|
||||
|
||||
- `KeyError`: 对应 self_id 的 Bot 不存在
|
||||
|
||||
- `ValueError`: 没有传入 self_id 且没有 Bot 可用
|
||||
|
||||
- `ValueError`: 全局 [Driver](./drivers/index.md#Driver) 对象尚未初始化 ([nonebot.init](#init) 尚未调用)
|
||||
|
||||
- **用法**
|
||||
|
||||
```python
|
||||
assert nonebot.get_bot("12345") == nonebot.get_bots()["12345"]
|
||||
|
||||
another_unspecified_bot = nonebot.get_bot()
|
||||
```
|
||||
|
||||
## _def_ `get_bots()` {#get_bots}
|
||||
|
||||
- **说明**
|
||||
|
||||
获取所有连接到 NoneBot 的 [Bot](./adapters/index.md#Bot) 对象。
|
||||
|
||||
- **返回**
|
||||
|
||||
- dict[str, nonebot.internal.adapter.bot.Bot]: 一个以 {ref}`nonebot.adapters.Bot.self_id` 为键,[Bot](./adapters/index.md#Bot) 对象为值的字典
|
||||
|
||||
- **异常**
|
||||
|
||||
- `ValueError`: 全局 [Driver](./drivers/index.md#Driver) 对象尚未初始化 ([nonebot.init](#init) 尚未调用)
|
||||
|
||||
- **用法**
|
||||
|
||||
```python
|
||||
bots = nonebot.get_bots()
|
||||
```
|
||||
|
||||
## _def_ `init(*, _env_file=None, **kwargs)` {#init}
|
||||
|
||||
- **说明**
|
||||
|
||||
初始化 NoneBot 以及 全局 [Driver](./drivers/index.md#Driver) 对象。
|
||||
|
||||
NoneBot 将会从 .env 文件中读取环境信息,并使用相应的 env 文件配置。
|
||||
|
||||
也可以传入自定义的 `_env_file` 来指定 NoneBot 从该文件读取配置。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `_env_file` (str | os.PathLike | list[str | os.PathLike] | tuple[str | os.PathLike, ...] | NoneType): 配置文件名,默认从 `.env.{env_name}` 中读取配置
|
||||
|
||||
- `**kwargs` (Any): 任意变量,将会存储到 {ref}`nonebot.drivers.Driver.config` 对象里
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
- **用法**
|
||||
|
||||
```python
|
||||
nonebot.init(database=Database(...))
|
||||
```
|
||||
|
||||
## _def_ `run(*args, **kwargs)` {#run}
|
||||
|
||||
- **说明**
|
||||
|
||||
启动 NoneBot,即运行全局 [Driver](./drivers/index.md#Driver) 对象。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `*args` (Any): 传入 [Driver.run](./drivers/index.md#Driver-run) 的位置参数
|
||||
|
||||
- `**kwargs` (Any): 传入 [Driver.run](./drivers/index.md#Driver-run) 的命名参数
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
- **用法**
|
||||
|
||||
```python
|
||||
nonebot.run(host="127.0.0.1", port=8080)
|
||||
```
|
75
website/versioned_docs/version-2.0.0rc3/api/log.md
Normal file
75
website/versioned_docs/version-2.0.0rc3/api/log.md
Normal file
@ -0,0 +1,75 @@
|
||||
---
|
||||
sidebar_position: 7
|
||||
description: nonebot.log 模块
|
||||
---
|
||||
|
||||
# nonebot.log
|
||||
|
||||
本模块定义了 NoneBot 的日志记录 Logger。
|
||||
|
||||
NoneBot 使用 [`loguru`][loguru] 来记录日志信息。
|
||||
|
||||
自定义 logger 请参考 [自定义日志](https://v2.nonebot.dev/docs/tutorial/custom-logger)
|
||||
以及 [`loguru`][loguru] 文档。
|
||||
|
||||
[loguru]: https://github.com/Delgan/loguru
|
||||
|
||||
## _var_ `logger` {#logger}
|
||||
|
||||
- **类型:** Logger
|
||||
|
||||
- **说明**
|
||||
|
||||
NoneBot 日志记录器对象。
|
||||
|
||||
默认信息:
|
||||
|
||||
- 格式: `[%(asctime)s %(name)s] %(levelname)s: %(message)s`
|
||||
- 等级: `INFO` ,根据 `config.log_level` 配置改变
|
||||
- 输出: 输出至 stdout
|
||||
|
||||
- **用法**
|
||||
|
||||
```python
|
||||
from nonebot.log import logger
|
||||
```
|
||||
|
||||
## _var_ `default_format` {#default_format}
|
||||
|
||||
- **类型:** str
|
||||
|
||||
- **说明:** 默认日志格式
|
||||
|
||||
## _class_ `LoguruHandler(level=0)` {#LoguruHandler}
|
||||
|
||||
- **说明**
|
||||
|
||||
logging 与 loguru 之间的桥梁,将 logging 的日志转发到 loguru。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `level`
|
||||
|
||||
### _method_ `emit(self, record)` {#LoguruHandler-emit}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `record` (logging.LogRecord)
|
||||
|
||||
- **返回**
|
||||
|
||||
- Unknown
|
||||
|
||||
## _def_ `default_filter(record)` {#default_filter}
|
||||
|
||||
- **说明**
|
||||
|
||||
默认的日志过滤器,根据 `config.log_level` 配置改变日志等级。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `record` (Record)
|
||||
|
||||
- **返回**
|
||||
|
||||
- Unknown
|
615
website/versioned_docs/version-2.0.0rc3/api/matcher.md
Normal file
615
website/versioned_docs/version-2.0.0rc3/api/matcher.md
Normal file
@ -0,0 +1,615 @@
|
||||
---
|
||||
sidebar_position: 3
|
||||
description: nonebot.matcher 模块
|
||||
---
|
||||
|
||||
# nonebot.matcher
|
||||
|
||||
本模块实现事件响应器的创建与运行,并提供一些快捷方法来帮助用户更好的与机器人进行对话。
|
||||
|
||||
## _class_ `Matcher()` {#Matcher}
|
||||
|
||||
- **说明**
|
||||
|
||||
事件响应器类
|
||||
|
||||
### _classmethod_ `append_handler(cls, handler, parameterless=None)` {#Matcher-append_handler}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `handler` ((*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any])
|
||||
|
||||
- `parameterless` (Iterable[Any] | None)
|
||||
|
||||
- **返回**
|
||||
|
||||
- [Dependent](./dependencies/index.md#Dependent)[typing.Any]
|
||||
|
||||
### _async classmethod_ `check_perm(cls, bot, event, stack=None, dependency_cache=None)` {#Matcher-check_perm}
|
||||
|
||||
- **说明**
|
||||
|
||||
检查是否满足触发权限
|
||||
|
||||
- **参数**
|
||||
|
||||
- `bot` (nonebot.internal.adapter.bot.Bot): Bot 对象
|
||||
|
||||
- `event` (nonebot.internal.adapter.event.Event): 上报事件
|
||||
|
||||
- `stack` (contextlib.AsyncExitStack | None): 异步上下文栈
|
||||
|
||||
- `dependency_cache` (dict[(*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any], Task[Any]] | None): 依赖缓存
|
||||
|
||||
- **返回**
|
||||
|
||||
- bool: 是否满足权限
|
||||
|
||||
### _async classmethod_ `check_rule(cls, bot, event, state, stack=None, dependency_cache=None)` {#Matcher-check_rule}
|
||||
|
||||
- **说明**
|
||||
|
||||
检查是否满足匹配规则
|
||||
|
||||
- **参数**
|
||||
|
||||
- `bot` (nonebot.internal.adapter.bot.Bot): Bot 对象
|
||||
|
||||
- `event` (nonebot.internal.adapter.event.Event): 上报事件
|
||||
|
||||
- `state` (dict[Any, Any]): 当前状态
|
||||
|
||||
- `stack` (contextlib.AsyncExitStack | None): 异步上下文栈
|
||||
|
||||
- `dependency_cache` (dict[(*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any], Task[Any]] | None): 依赖缓存
|
||||
|
||||
- **返回**
|
||||
|
||||
- bool: 是否满足匹配规则
|
||||
|
||||
### _classmethod_ `destroy(cls)` {#Matcher-destroy}
|
||||
|
||||
- **说明**
|
||||
|
||||
销毁当前的事件响应器
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _method_ `ensure_context(self, bot, event)` {#Matcher-ensure_context}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `bot` (nonebot.internal.adapter.bot.Bot)
|
||||
|
||||
- `event` (nonebot.internal.adapter.event.Event)
|
||||
|
||||
- **返回**
|
||||
|
||||
- Unknown
|
||||
|
||||
### _async classmethod_ `finish(cls, message=None, **kwargs)` {#Matcher-finish}
|
||||
|
||||
- **说明**
|
||||
|
||||
发送一条消息给当前交互用户并结束当前事件响应器
|
||||
|
||||
- **参数**
|
||||
|
||||
- `message` (str | nonebot.internal.adapter.message.Message | nonebot.internal.adapter.message.MessageSegment | nonebot.internal.adapter.template.MessageTemplate | NoneType): 消息内容
|
||||
|
||||
- `**kwargs`: [Bot.send](./adapters/index.md#Bot-send) 的参数,请参考对应 adapter 的 bot 对象 api
|
||||
|
||||
- **返回**
|
||||
|
||||
- NoReturn
|
||||
|
||||
### _method_ `get_arg(self, key, default=None)` {#Matcher-get_arg}
|
||||
|
||||
- **说明**
|
||||
|
||||
获取一个 `got` 消息
|
||||
|
||||
如果没有找到对应的消息,返回 `default` 值
|
||||
|
||||
- **参数**
|
||||
|
||||
- `key` (str)
|
||||
|
||||
- `default` ((~ T) | None)
|
||||
|
||||
- **返回**
|
||||
|
||||
- nonebot.internal.adapter.message.Message | (~ T) | NoneType
|
||||
|
||||
### _method_ `get_last_receive(self, default=None)` {#Matcher-get_last_receive}
|
||||
|
||||
- **说明**
|
||||
|
||||
获取最近一次 `receive` 事件
|
||||
|
||||
如果没有事件,返回 `default` 值
|
||||
|
||||
- **参数**
|
||||
|
||||
- `default` ((~ T) | None)
|
||||
|
||||
- **返回**
|
||||
|
||||
- nonebot.internal.adapter.event.Event | (~ T) | NoneType
|
||||
|
||||
### _method_ `get_receive(self, id, default=None)` {#Matcher-get_receive}
|
||||
|
||||
- **说明**
|
||||
|
||||
获取一个 `receive` 事件
|
||||
|
||||
如果没有找到对应的事件,返回 `default` 值
|
||||
|
||||
- **参数**
|
||||
|
||||
- `id` (str)
|
||||
|
||||
- `default` ((~ T) | None)
|
||||
|
||||
- **返回**
|
||||
|
||||
- nonebot.internal.adapter.event.Event | (~ T) | NoneType
|
||||
|
||||
### _method_ `get_target(self, default=None)` {#Matcher-get_target}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `default` ((~ T) | None)
|
||||
|
||||
- **返回**
|
||||
|
||||
- str | (~ T) | NoneType
|
||||
|
||||
### _classmethod_ `got(cls, key, prompt=None, parameterless=None)` {#Matcher-got}
|
||||
|
||||
- **说明**
|
||||
|
||||
装饰一个函数来指示 NoneBot 获取一个参数 `key`
|
||||
|
||||
当要获取的 `key` 不存在时接收用户新的一条消息再运行该函数,如果 `key` 已存在则直接继续运行
|
||||
|
||||
- **参数**
|
||||
|
||||
- `key` (str): 参数名
|
||||
|
||||
- `prompt` (str | nonebot.internal.adapter.message.Message | nonebot.internal.adapter.message.MessageSegment | nonebot.internal.adapter.template.MessageTemplate | NoneType): 在参数不存在时向用户发送的消息
|
||||
|
||||
- `parameterless` (Iterable[Any] | None): 非参数类型依赖列表
|
||||
|
||||
- **返回**
|
||||
|
||||
- ((\*Any, \*\*Any) -> Any | (\*Any, \*\*Any) -> Awaitable[Any]) -> (\*Any, \*\*Any) -> Any | (\*Any, \*\*Any) -> Awaitable[Any]
|
||||
|
||||
### _classmethod_ `handle(cls, parameterless=None)` {#Matcher-handle}
|
||||
|
||||
- **说明**
|
||||
|
||||
装饰一个函数来向事件响应器直接添加一个处理函数
|
||||
|
||||
- **参数**
|
||||
|
||||
- `parameterless` (Iterable[Any] | None): 非参数类型依赖列表
|
||||
|
||||
- **返回**
|
||||
|
||||
- ((\*Any, \*\*Any) -> Any | (\*Any, \*\*Any) -> Awaitable[Any]) -> (\*Any, \*\*Any) -> Any | (\*Any, \*\*Any) -> Awaitable[Any]
|
||||
|
||||
### _classmethod_ `new(cls, type_='', rule=None, permission=None, handlers=None, temp=False, priority=1, block=False, *, plugin=None, module=None, expire_time=None, default_state=None, default_type_updater=None, default_permission_updater=None)` {#Matcher-new}
|
||||
|
||||
- **说明**
|
||||
|
||||
创建一个新的事件响应器,并存储至 `matchers <#matchers>`\_
|
||||
|
||||
- **参数**
|
||||
|
||||
- `type_` (str): 事件响应器类型,与 `event.get_type()` 一致时触发,空字符串表示任意
|
||||
|
||||
- `rule` (nonebot.internal.rule.Rule | None): 匹配规则
|
||||
|
||||
- `permission` (nonebot.internal.permission.Permission | None): 权限
|
||||
|
||||
- `handlers` (list[(*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any] | [Dependent](./dependencies/index.md#Dependent)[Any]] | None): 事件处理函数列表
|
||||
|
||||
- `temp` (bool): 是否为临时事件响应器,即触发一次后删除
|
||||
|
||||
- `priority` (int): 响应优先级
|
||||
|
||||
- `block` (bool): 是否阻止事件向更低优先级的响应器传播
|
||||
|
||||
- `plugin` (Plugin | None): 事件响应器所在插件
|
||||
|
||||
- `module` (module | None): 事件响应器所在模块
|
||||
|
||||
- `expire_time` (datetime.datetime | datetime.timedelta | NoneType): 事件响应器最终有效时间点,过时即被删除
|
||||
|
||||
- `default_state` (dict[Any, Any] | None): 默认状态 `state`
|
||||
|
||||
- `default_type_updater` ((*Any, \*\*Any) -> str | (*Any, \*\*Any) -> Awaitable[str] | [Dependent](./dependencies/index.md#Dependent)[str] | NoneType)
|
||||
|
||||
- `default_permission_updater` ((*Any, \*\*Any) -> Permission | (*Any, \*\*Any) -> Awaitable[Permission] | [Dependent](./dependencies/index.md#Dependent)[nonebot.internal.permission.Permission] | NoneType)
|
||||
|
||||
- **返回**
|
||||
|
||||
- Type[Matcher]: 新的事件响应器类
|
||||
|
||||
### _async classmethod_ `pause(cls, prompt=None, **kwargs)` {#Matcher-pause}
|
||||
|
||||
- **说明**
|
||||
|
||||
发送一条消息给当前交互用户并暂停事件响应器,在接收用户新的一条消息后继续下一个处理函数
|
||||
|
||||
- **参数**
|
||||
|
||||
- `prompt` (str | nonebot.internal.adapter.message.Message | nonebot.internal.adapter.message.MessageSegment | nonebot.internal.adapter.template.MessageTemplate | NoneType): 消息内容
|
||||
|
||||
- `**kwargs`: [Bot.send](./adapters/index.md#Bot-send) 的参数,请参考对应 adapter 的 bot 对象 api
|
||||
|
||||
- **返回**
|
||||
|
||||
- NoReturn
|
||||
|
||||
### _classmethod_ `permission_updater(cls, func)` {#Matcher-permission_updater}
|
||||
|
||||
- **说明**
|
||||
|
||||
装饰一个函数来更改当前事件响应器的默认会话权限更新函数
|
||||
|
||||
- **参数**
|
||||
|
||||
- `func` ((*Any, \*\*Any) -> Permission | (*Any, \*\*Any) -> Awaitable[Permission]): 会话权限更新函数
|
||||
|
||||
- **返回**
|
||||
|
||||
- (\*Any, \*\*Any) -> Permission | (\*Any, \*\*Any) -> Awaitable[Permission]
|
||||
|
||||
### _classmethod_ `receive(cls, id='', parameterless=None)` {#Matcher-receive}
|
||||
|
||||
- **说明**
|
||||
|
||||
装饰一个函数来指示 NoneBot 在接收用户新的一条消息后继续运行该函数
|
||||
|
||||
- **参数**
|
||||
|
||||
- `id` (str): 消息 ID
|
||||
|
||||
- `parameterless` (Iterable[Any] | None): 非参数类型依赖列表
|
||||
|
||||
- **返回**
|
||||
|
||||
- ((\*Any, \*\*Any) -> Any | (\*Any, \*\*Any) -> Awaitable[Any]) -> (\*Any, \*\*Any) -> Any | (\*Any, \*\*Any) -> Awaitable[Any]
|
||||
|
||||
### _async classmethod_ `reject(cls, prompt=None, **kwargs)` {#Matcher-reject}
|
||||
|
||||
- **说明**
|
||||
|
||||
最近使用 `got` / `receive` 接收的消息不符合预期,
|
||||
发送一条消息给当前交互用户并将当前事件处理流程中断在当前位置,在接收用户新的一个事件后从头开始执行当前处理函数
|
||||
|
||||
- **参数**
|
||||
|
||||
- `prompt` (str | nonebot.internal.adapter.message.Message | nonebot.internal.adapter.message.MessageSegment | nonebot.internal.adapter.template.MessageTemplate | NoneType): 消息内容
|
||||
|
||||
- `**kwargs`: [Bot.send](./adapters/index.md#Bot-send) 的参数,请参考对应 adapter 的 bot 对象 api
|
||||
|
||||
- **返回**
|
||||
|
||||
- NoReturn
|
||||
|
||||
### _async classmethod_ `reject_arg(cls, key, prompt=None, **kwargs)` {#Matcher-reject_arg}
|
||||
|
||||
- **说明**
|
||||
|
||||
最近使用 `got` 接收的消息不符合预期,
|
||||
发送一条消息给当前交互用户并将当前事件处理流程中断在当前位置,在接收用户新的一条消息后从头开始执行当前处理函数
|
||||
|
||||
- **参数**
|
||||
|
||||
- `key` (str): 参数名
|
||||
|
||||
- `prompt` (str | nonebot.internal.adapter.message.Message | nonebot.internal.adapter.message.MessageSegment | nonebot.internal.adapter.template.MessageTemplate | NoneType): 消息内容
|
||||
|
||||
- `**kwargs`: [Bot.send](./adapters/index.md#Bot-send) 的参数,请参考对应 adapter 的 bot 对象 api
|
||||
|
||||
- **返回**
|
||||
|
||||
- NoReturn
|
||||
|
||||
### _async classmethod_ `reject_receive(cls, id='', prompt=None, **kwargs)` {#Matcher-reject_receive}
|
||||
|
||||
- **说明**
|
||||
|
||||
最近使用 `receive` 接收的消息不符合预期,
|
||||
发送一条消息给当前交互用户并将当前事件处理流程中断在当前位置,在接收用户新的一个事件后从头开始执行当前处理函数
|
||||
|
||||
- **参数**
|
||||
|
||||
- `id` (str): 消息 id
|
||||
|
||||
- `prompt` (str | nonebot.internal.adapter.message.Message | nonebot.internal.adapter.message.MessageSegment | nonebot.internal.adapter.template.MessageTemplate | NoneType): 消息内容
|
||||
|
||||
- `**kwargs`: [Bot.send](./adapters/index.md#Bot-send) 的参数,请参考对应 adapter 的 bot 对象 api
|
||||
|
||||
- **返回**
|
||||
|
||||
- NoReturn
|
||||
|
||||
### _async method_ `resolve_reject(self)` {#Matcher-resolve_reject}
|
||||
|
||||
- **返回**
|
||||
|
||||
- Unknown
|
||||
|
||||
### _async method_ `run(self, bot, event, state, stack=None, dependency_cache=None)` {#Matcher-run}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `bot` (nonebot.internal.adapter.bot.Bot)
|
||||
|
||||
- `event` (nonebot.internal.adapter.event.Event)
|
||||
|
||||
- `state` (dict[Any, Any])
|
||||
|
||||
- `stack` (contextlib.AsyncExitStack | None)
|
||||
|
||||
- `dependency_cache` (dict[(*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any], Task[Any]] | None)
|
||||
|
||||
- **返回**
|
||||
|
||||
- Unknown
|
||||
|
||||
### _async classmethod_ `send(cls, message, **kwargs)` {#Matcher-send}
|
||||
|
||||
- **说明**
|
||||
|
||||
发送一条消息给当前交互用户
|
||||
|
||||
- **参数**
|
||||
|
||||
- `message` (str | nonebot.internal.adapter.message.Message | nonebot.internal.adapter.message.MessageSegment | nonebot.internal.adapter.template.MessageTemplate): 消息内容
|
||||
|
||||
- `**kwargs` (Any): [Bot.send](./adapters/index.md#Bot-send) 的参数,请参考对应 adapter 的 bot 对象 api
|
||||
|
||||
- **返回**
|
||||
|
||||
- Any
|
||||
|
||||
### _method_ `set_arg(self, key, message)` {#Matcher-set_arg}
|
||||
|
||||
- **说明**
|
||||
|
||||
设置一个 `got` 消息
|
||||
|
||||
- **参数**
|
||||
|
||||
- `key` (str)
|
||||
|
||||
- `message` (nonebot.internal.adapter.message.Message)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _method_ `set_receive(self, id, event)` {#Matcher-set_receive}
|
||||
|
||||
- **说明**
|
||||
|
||||
设置一个 `receive` 事件
|
||||
|
||||
- **参数**
|
||||
|
||||
- `id` (str)
|
||||
|
||||
- `event` (nonebot.internal.adapter.event.Event)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _method_ `set_target(self, target, cache=True)` {#Matcher-set_target}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `target` (str)
|
||||
|
||||
- `cache` (bool)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _async method_ `simple_run(self, bot, event, state, stack=None, dependency_cache=None)` {#Matcher-simple_run}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `bot` (nonebot.internal.adapter.bot.Bot)
|
||||
|
||||
- `event` (nonebot.internal.adapter.event.Event)
|
||||
|
||||
- `state` (dict[Any, Any])
|
||||
|
||||
- `stack` (contextlib.AsyncExitStack | None)
|
||||
|
||||
- `dependency_cache` (dict[(*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any], Task[Any]] | None)
|
||||
|
||||
- **返回**
|
||||
|
||||
- Unknown
|
||||
|
||||
### _classmethod_ `skip(cls)` {#Matcher-skip}
|
||||
|
||||
- **说明**
|
||||
|
||||
跳过当前事件处理函数,继续下一个处理函数
|
||||
|
||||
通常在事件处理函数的依赖中使用。
|
||||
|
||||
- **返回**
|
||||
|
||||
- NoReturn
|
||||
|
||||
### _method_ `stop_propagation(self)` {#Matcher-stop_propagation}
|
||||
|
||||
- **说明**
|
||||
|
||||
阻止事件传播
|
||||
|
||||
- **返回**
|
||||
|
||||
- Unknown
|
||||
|
||||
### _classmethod_ `type_updater(cls, func)` {#Matcher-type_updater}
|
||||
|
||||
- **说明**
|
||||
|
||||
装饰一个函数来更改当前事件响应器的默认响应事件类型更新函数
|
||||
|
||||
- **参数**
|
||||
|
||||
- `func` ((*Any, \*\*Any) -> str | (*Any, \*\*Any) -> Awaitable[str]): 响应事件类型更新函数
|
||||
|
||||
- **返回**
|
||||
|
||||
- (\*Any, \*\*Any) -> str | (\*Any, \*\*Any) -> Awaitable[str]
|
||||
|
||||
### _async method_ `update_permission(self, bot, event)` {#Matcher-update_permission}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `bot` (nonebot.internal.adapter.bot.Bot)
|
||||
|
||||
- `event` (nonebot.internal.adapter.event.Event)
|
||||
|
||||
- **返回**
|
||||
|
||||
- nonebot.internal.permission.Permission
|
||||
|
||||
### _async method_ `update_type(self, bot, event)` {#Matcher-update_type}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `bot` (nonebot.internal.adapter.bot.Bot)
|
||||
|
||||
- `event` (nonebot.internal.adapter.event.Event)
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
## _class_ `MatcherManager()` {#MatcherManager}
|
||||
|
||||
- **说明**
|
||||
|
||||
事件响应器管理器
|
||||
|
||||
实现了常用字典操作,用于管理事件响应器。
|
||||
|
||||
### _method_ `clear(self)` {#MatcherManager-clear}
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _method_ `get(self, key, default=None)` {#MatcherManager-get}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `key` (int)
|
||||
|
||||
- `default` ((~ T) | None)
|
||||
|
||||
- **返回**
|
||||
|
||||
- list[Type[Matcher]] | (~ T) | NoneType
|
||||
|
||||
### _method_ `items(self)` {#MatcherManager-items}
|
||||
|
||||
- **返回**
|
||||
|
||||
- ItemsView[int, list[Type[Matcher]]]
|
||||
|
||||
### _method_ `keys(self)` {#MatcherManager-keys}
|
||||
|
||||
- **返回**
|
||||
|
||||
- KeysView[int]
|
||||
|
||||
### _method_ `pop(self, key)` {#MatcherManager-pop}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `key` (int)
|
||||
|
||||
- **返回**
|
||||
|
||||
- list[Type[Matcher]]
|
||||
|
||||
### _method_ `popitem(self)` {#MatcherManager-popitem}
|
||||
|
||||
- **返回**
|
||||
|
||||
- tuple[int, list[Type[Matcher]]]
|
||||
|
||||
### _method_ `set_provider(self, provider_class)` {#MatcherManager-set_provider}
|
||||
|
||||
- **说明**
|
||||
|
||||
设置事件响应器存储器
|
||||
|
||||
- **参数**
|
||||
|
||||
- `provider_class` (Type[nonebot.internal.matcher.provider.MatcherProvider]): 事件响应器存储器类
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _method_ `setdefault(self, key, default)` {#MatcherManager-setdefault}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `key` (int)
|
||||
|
||||
- `default` (list[Type[Matcher]])
|
||||
|
||||
- **返回**
|
||||
|
||||
- list[Type[Matcher]]
|
||||
|
||||
### _method_ `update(self, _MatcherManager__m)` {#MatcherManager-update}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `_MatcherManager__m` (MutableMapping[int, list[Type[Matcher]]])
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _method_ `values(self)` {#MatcherManager-values}
|
||||
|
||||
- **返回**
|
||||
|
||||
- ValuesView[list[Type[Matcher]]]
|
||||
|
||||
## _abstract class_ `MatcherProvider(matchers)` {#MatcherProvider}
|
||||
|
||||
- **说明**
|
||||
|
||||
事件响应器存储器基类
|
||||
|
||||
- **参数**
|
||||
|
||||
- `matchers` (Mapping[int, list[Type[Matcher]]]): 当前存储器中已有的事件响应器
|
||||
|
||||
## _class_ `DEFAULT_PROVIDER_CLASS(matchers)` {#DEFAULT_PROVIDER_CLASS}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `matchers` (Mapping[int, list[Type[Matcher]]])
|
89
website/versioned_docs/version-2.0.0rc3/api/message.md
Normal file
89
website/versioned_docs/version-2.0.0rc3/api/message.md
Normal file
@ -0,0 +1,89 @@
|
||||
---
|
||||
sidebar_position: 2
|
||||
description: nonebot.message 模块
|
||||
---
|
||||
|
||||
# nonebot.message
|
||||
|
||||
本模块定义了事件处理主要流程。
|
||||
|
||||
NoneBot 内部处理并按优先级分发事件给所有事件响应器,提供了多个插槽以进行事件的预处理等。
|
||||
|
||||
## _def_ `event_preprocessor(func)` {#event_preprocessor}
|
||||
|
||||
- **说明**
|
||||
|
||||
事件预处理。装饰一个函数,使它在每次接收到事件并分发给各响应器之前执行。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `func` ((*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any])
|
||||
|
||||
- **返回**
|
||||
|
||||
- (\*Any, \*\*Any) -> Any | (\*Any, \*\*Any) -> Awaitable[Any]
|
||||
|
||||
## _def_ `event_postprocessor(func)` {#event_postprocessor}
|
||||
|
||||
- **说明**
|
||||
|
||||
事件后处理。装饰一个函数,使它在每次接收到事件并分发给各响应器之后执行。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `func` ((*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any])
|
||||
|
||||
- **返回**
|
||||
|
||||
- (\*Any, \*\*Any) -> Any | (\*Any, \*\*Any) -> Awaitable[Any]
|
||||
|
||||
## _def_ `run_preprocessor(func)` {#run_preprocessor}
|
||||
|
||||
- **说明**
|
||||
|
||||
运行预处理。装饰一个函数,使它在每次事件响应器运行前执行。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `func` ((*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any])
|
||||
|
||||
- **返回**
|
||||
|
||||
- (\*Any, \*\*Any) -> Any | (\*Any, \*\*Any) -> Awaitable[Any]
|
||||
|
||||
## _def_ `run_postprocessor(func)` {#run_postprocessor}
|
||||
|
||||
- **说明**
|
||||
|
||||
运行后处理。装饰一个函数,使它在每次事件响应器运行后执行。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `func` ((*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any])
|
||||
|
||||
- **返回**
|
||||
|
||||
- (\*Any, \*\*Any) -> Any | (\*Any, \*\*Any) -> Awaitable[Any]
|
||||
|
||||
## _async def_ `handle_event(bot, event)` {#handle_event}
|
||||
|
||||
- **说明**
|
||||
|
||||
处理一个事件。调用该函数以实现分发事件。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `bot` (Bot): Bot 对象
|
||||
|
||||
- `event` (Event): Event 对象
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
- **用法**
|
||||
|
||||
```python
|
||||
import asyncio
|
||||
asyncio.create_task(handle_event(bot, event))
|
||||
```
|
388
website/versioned_docs/version-2.0.0rc3/api/params.md
Normal file
388
website/versioned_docs/version-2.0.0rc3/api/params.md
Normal file
@ -0,0 +1,388 @@
|
||||
---
|
||||
sidebar_position: 4
|
||||
description: nonebot.params 模块
|
||||
---
|
||||
|
||||
# nonebot.params
|
||||
|
||||
本模块定义了依赖注入的各类参数。
|
||||
|
||||
## _def_ `Arg(key=None)` {#Arg}
|
||||
|
||||
- **说明**
|
||||
|
||||
`got` 的 Arg 参数消息
|
||||
|
||||
- **参数**
|
||||
|
||||
- `key` (str | None)
|
||||
|
||||
- **返回**
|
||||
|
||||
- Any
|
||||
|
||||
## _def_ `ArgStr(key=None)` {#ArgStr}
|
||||
|
||||
- **说明**
|
||||
|
||||
`got` 的 Arg 参数消息文本
|
||||
|
||||
- **参数**
|
||||
|
||||
- `key` (str | None)
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
## _def_ `Depends(dependency=None, *, use_cache=True)` {#Depends}
|
||||
|
||||
- **说明**
|
||||
|
||||
子依赖装饰器
|
||||
|
||||
- **参数**
|
||||
|
||||
- `dependency` ((*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any] | NoneType): 依赖函数。默认为参数的类型注释。
|
||||
|
||||
- `use_cache` (bool): 是否使用缓存。默认为 `True`。
|
||||
|
||||
- **返回**
|
||||
|
||||
- Any
|
||||
|
||||
- **用法**
|
||||
|
||||
```python
|
||||
def depend_func() -> Any:
|
||||
return ...
|
||||
|
||||
def depend_gen_func():
|
||||
try:
|
||||
yield ...
|
||||
finally:
|
||||
...
|
||||
|
||||
async def handler(param_name: Any = Depends(depend_func), gen: Any = Depends(depend_gen_func)):
|
||||
...
|
||||
```
|
||||
|
||||
## _class_ `ArgParam(default=PydanticUndefined, **kwargs)` {#ArgParam}
|
||||
|
||||
- **说明**
|
||||
|
||||
`got` 的 Arg 参数
|
||||
|
||||
- **参数**
|
||||
|
||||
- `default` (Any)
|
||||
|
||||
- `**kwargs` (Any)
|
||||
|
||||
## _class_ `BotParam(default=PydanticUndefined, **kwargs)` {#BotParam}
|
||||
|
||||
- **说明**
|
||||
|
||||
[Bot](./adapters/index.md#Bot) 参数
|
||||
|
||||
- **参数**
|
||||
|
||||
- `default` (Any)
|
||||
|
||||
- `**kwargs` (Any)
|
||||
|
||||
## _class_ `EventParam(default=PydanticUndefined, **kwargs)` {#EventParam}
|
||||
|
||||
- **说明**
|
||||
|
||||
[Event](./adapters/index.md#Event) 参数
|
||||
|
||||
- **参数**
|
||||
|
||||
- `default` (Any)
|
||||
|
||||
- `**kwargs` (Any)
|
||||
|
||||
## _class_ `StateParam(default=PydanticUndefined, **kwargs)` {#StateParam}
|
||||
|
||||
- **说明**
|
||||
|
||||
事件处理状态参数
|
||||
|
||||
- **参数**
|
||||
|
||||
- `default` (Any)
|
||||
|
||||
- `**kwargs` (Any)
|
||||
|
||||
## _class_ `DependParam(default=PydanticUndefined, **kwargs)` {#DependParam}
|
||||
|
||||
- **说明**
|
||||
|
||||
子依赖参数
|
||||
|
||||
- **参数**
|
||||
|
||||
- `default` (Any)
|
||||
|
||||
- `**kwargs` (Any)
|
||||
|
||||
## _def_ `ArgPlainText(key=None)` {#ArgPlainText}
|
||||
|
||||
- **说明**
|
||||
|
||||
`got` 的 Arg 参数消息纯文本
|
||||
|
||||
- **参数**
|
||||
|
||||
- `key` (str | None)
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
## _class_ `DefaultParam(default=PydanticUndefined, **kwargs)` {#DefaultParam}
|
||||
|
||||
- **说明**
|
||||
|
||||
默认值参数
|
||||
|
||||
- **参数**
|
||||
|
||||
- `default` (Any)
|
||||
|
||||
- `**kwargs` (Any)
|
||||
|
||||
## _class_ `MatcherParam(default=PydanticUndefined, **kwargs)` {#MatcherParam}
|
||||
|
||||
- **说明**
|
||||
|
||||
事件响应器实例参数
|
||||
|
||||
- **参数**
|
||||
|
||||
- `default` (Any)
|
||||
|
||||
- `**kwargs` (Any)
|
||||
|
||||
## _class_ `ExceptionParam(default=PydanticUndefined, **kwargs)` {#ExceptionParam}
|
||||
|
||||
- **说明**
|
||||
|
||||
`run_postprocessor` 的异常参数
|
||||
|
||||
- **参数**
|
||||
|
||||
- `default` (Any)
|
||||
|
||||
- `**kwargs` (Any)
|
||||
|
||||
## _def_ `EventType()` {#EventType}
|
||||
|
||||
- **说明**
|
||||
|
||||
[Event](./adapters/index.md#Event) 类型参数
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
## _def_ `EventMessage()` {#EventMessage}
|
||||
|
||||
- **说明**
|
||||
|
||||
[Event](./adapters/index.md#Event) 消息参数
|
||||
|
||||
- **返回**
|
||||
|
||||
- Any
|
||||
|
||||
## _def_ `EventPlainText()` {#EventPlainText}
|
||||
|
||||
- **说明**
|
||||
|
||||
[Event](./adapters/index.md#Event) 纯文本消息参数
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
## _def_ `EventToMe()` {#EventToMe}
|
||||
|
||||
- **说明**
|
||||
|
||||
[Event](./adapters/index.md#Event) `to_me` 参数
|
||||
|
||||
- **返回**
|
||||
|
||||
- bool
|
||||
|
||||
## _def_ `Command()` {#Command}
|
||||
|
||||
- **说明**
|
||||
|
||||
消息命令元组
|
||||
|
||||
- **返回**
|
||||
|
||||
- tuple[str, ...]
|
||||
|
||||
## _def_ `RawCommand()` {#RawCommand}
|
||||
|
||||
- **说明**
|
||||
|
||||
消息命令文本
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
## _def_ `CommandArg()` {#CommandArg}
|
||||
|
||||
- **说明**
|
||||
|
||||
消息命令参数
|
||||
|
||||
- **返回**
|
||||
|
||||
- Any
|
||||
|
||||
## _def_ `CommandStart()` {#CommandStart}
|
||||
|
||||
- **说明**
|
||||
|
||||
消息命令开头
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
## _def_ `ShellCommandArgs()` {#ShellCommandArgs}
|
||||
|
||||
- **说明**
|
||||
|
||||
shell 命令解析后的参数字典
|
||||
|
||||
- **返回**
|
||||
|
||||
- Any
|
||||
|
||||
## _def_ `ShellCommandArgv()` {#ShellCommandArgv}
|
||||
|
||||
- **说明**
|
||||
|
||||
shell 命令原始参数列表
|
||||
|
||||
- **返回**
|
||||
|
||||
- Any
|
||||
|
||||
## _def_ `RegexMatched()` {#RegexMatched}
|
||||
|
||||
- **说明**
|
||||
|
||||
正则匹配结果
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
## _def_ `RegexStr()` {#RegexStr}
|
||||
|
||||
- **说明**
|
||||
|
||||
正则匹配结果文本
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
## _def_ `RegexGroup()` {#RegexGroup}
|
||||
|
||||
- **说明**
|
||||
|
||||
正则匹配结果 group 元组
|
||||
|
||||
- **返回**
|
||||
|
||||
- tuple[Any, ...]
|
||||
|
||||
## _def_ `RegexDict()` {#RegexDict}
|
||||
|
||||
- **说明**
|
||||
|
||||
正则匹配结果 group 字典
|
||||
|
||||
- **返回**
|
||||
|
||||
- dict[str, Any]
|
||||
|
||||
## _def_ `Startswith()` {#Startswith}
|
||||
|
||||
- **说明**
|
||||
|
||||
响应触发前缀
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
## _def_ `Endswith()` {#Endswith}
|
||||
|
||||
- **说明**
|
||||
|
||||
响应触发后缀
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
## _def_ `Fullmatch()` {#Fullmatch}
|
||||
|
||||
- **说明**
|
||||
|
||||
响应触发完整消息
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
## _def_ `Keyword()` {#Keyword}
|
||||
|
||||
- **说明**
|
||||
|
||||
响应触发关键字
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
## _def_ `Received(id=None, default=None)` {#Received}
|
||||
|
||||
- **说明**
|
||||
|
||||
`receive` 事件参数
|
||||
|
||||
- **参数**
|
||||
|
||||
- `id` (str | None)
|
||||
|
||||
- `default` (Any)
|
||||
|
||||
- **返回**
|
||||
|
||||
- Any
|
||||
|
||||
## _def_ `LastReceived(default=None)` {#LastReceived}
|
||||
|
||||
- **说明**
|
||||
|
||||
`last_receive` 事件参数
|
||||
|
||||
- **参数**
|
||||
|
||||
- `default` (Any)
|
||||
|
||||
- **返回**
|
||||
|
||||
- Any
|
157
website/versioned_docs/version-2.0.0rc3/api/permission.md
Normal file
157
website/versioned_docs/version-2.0.0rc3/api/permission.md
Normal file
@ -0,0 +1,157 @@
|
||||
---
|
||||
sidebar_position: 6
|
||||
description: nonebot.permission 模块
|
||||
---
|
||||
|
||||
# nonebot.permission
|
||||
|
||||
本模块是 {ref}`nonebot.matcher.Matcher.permission` 的类型定义。
|
||||
|
||||
每个 [Matcher](./matcher.md#Matcher) 拥有一个 [Permission](#Permission) ,
|
||||
其中是 `PermissionChecker` 的集合,只要有一个 `PermissionChecker` 检查结果为 `True` 时就会继续运行。
|
||||
|
||||
## _var_ `MESSAGE` {#MESSAGE}
|
||||
|
||||
- **类型:** nonebot.internal.permission.Permission
|
||||
|
||||
- **说明**
|
||||
|
||||
匹配任意 `message` 类型事件
|
||||
|
||||
仅在需要同时捕获不同类型事件时使用,优先使用 message type 的 Matcher。
|
||||
|
||||
## _var_ `NOTICE` {#NOTICE}
|
||||
|
||||
- **类型:** nonebot.internal.permission.Permission
|
||||
|
||||
- **说明**
|
||||
|
||||
匹配任意 `notice` 类型事件
|
||||
|
||||
仅在需要同时捕获不同类型事件时使用,优先使用 notice type 的 Matcher。
|
||||
|
||||
## _var_ `REQUEST` {#REQUEST}
|
||||
|
||||
- **类型:** nonebot.internal.permission.Permission
|
||||
|
||||
- **说明**
|
||||
|
||||
匹配任意 `request` 类型事件
|
||||
|
||||
仅在需要同时捕获不同类型事件时使用,优先使用 request type 的 Matcher。
|
||||
|
||||
## _var_ `METAEVENT` {#METAEVENT}
|
||||
|
||||
- **类型:** nonebot.internal.permission.Permission
|
||||
|
||||
- **说明**
|
||||
|
||||
匹配任意 `meta_event` 类型事件
|
||||
|
||||
仅在需要同时捕获不同类型事件时使用,优先使用 meta_event type 的 Matcher。
|
||||
|
||||
## _var_ `SUPERUSER` {#SUPERUSER}
|
||||
|
||||
- **类型:** nonebot.internal.permission.Permission
|
||||
|
||||
- **说明:** 匹配任意超级用户事件
|
||||
|
||||
## _def_ `USER(*users, perm=None)` {#USER}
|
||||
|
||||
- **说明**
|
||||
|
||||
匹配当前事件属于指定会话
|
||||
|
||||
- **参数**
|
||||
|
||||
- `*users` (str)
|
||||
|
||||
- `perm` (nonebot.internal.permission.Permission | None): 需要同时满足的权限
|
||||
|
||||
- `user`: 会话白名单
|
||||
|
||||
- **返回**
|
||||
|
||||
- Unknown
|
||||
|
||||
## _class_ `User(users, perm=None)` {#User}
|
||||
|
||||
- **说明**
|
||||
|
||||
检查当前事件是否属于指定会话
|
||||
|
||||
- **参数**
|
||||
|
||||
- `users` (tuple[str, ...]): 会话 ID 元组
|
||||
|
||||
- `perm` (nonebot.internal.permission.Permission | None): 需同时满足的权限
|
||||
|
||||
## _class_ `Permission(*checkers)` {#Permission}
|
||||
|
||||
- **说明**
|
||||
|
||||
[Matcher](./matcher.md#Matcher) 权限类。
|
||||
|
||||
当事件传递时,在 [Matcher](./matcher.md#Matcher) 运行前进行检查。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `*checkers` ((*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | [Dependent](./dependencies/index.md#Dependent)[bool]): PermissionChecker
|
||||
|
||||
- **用法**
|
||||
|
||||
```python
|
||||
Permission(async_function) | sync_function
|
||||
# 等价于
|
||||
Permission(async_function, sync_function)
|
||||
```
|
||||
|
||||
### _async method_ `__call__(self, bot, event, stack=None, dependency_cache=None)` {#Permission-**call**}
|
||||
|
||||
- **说明**
|
||||
|
||||
检查是否满足某个权限
|
||||
|
||||
- **参数**
|
||||
|
||||
- `bot` (nonebot.internal.adapter.bot.Bot): Bot 对象
|
||||
|
||||
- `event` (nonebot.internal.adapter.event.Event): Event 对象
|
||||
|
||||
- `stack` (contextlib.AsyncExitStack | None): 异步上下文栈
|
||||
|
||||
- `dependency_cache` (dict[(*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any], Task[Any]] | None): 依赖缓存
|
||||
|
||||
- **返回**
|
||||
|
||||
- bool
|
||||
|
||||
## _class_ `Message()` {#Message}
|
||||
|
||||
- **说明**
|
||||
|
||||
检查是否为消息事件
|
||||
|
||||
## _class_ `Notice()` {#Notice}
|
||||
|
||||
- **说明**
|
||||
|
||||
检查是否为通知事件
|
||||
|
||||
## _class_ `Request()` {#Request}
|
||||
|
||||
- **说明**
|
||||
|
||||
检查是否为请求事件
|
||||
|
||||
## _class_ `MetaEvent()` {#MetaEvent}
|
||||
|
||||
- **说明**
|
||||
|
||||
检查是否为元事件
|
||||
|
||||
## _class_ `SuperUser()` {#SuperUser}
|
||||
|
||||
- **说明**
|
||||
|
||||
检查当前事件是否是消息事件且属于超级管理员
|
@ -0,0 +1,3 @@
|
||||
{
|
||||
"position": 12
|
||||
}
|
89
website/versioned_docs/version-2.0.0rc3/api/plugin/index.md
Normal file
89
website/versioned_docs/version-2.0.0rc3/api/plugin/index.md
Normal file
@ -0,0 +1,89 @@
|
||||
---
|
||||
sidebar_position: 0
|
||||
description: nonebot.plugin 模块
|
||||
---
|
||||
|
||||
# nonebot.plugin
|
||||
|
||||
本模块为 NoneBot 插件开发提供便携的定义函数。
|
||||
|
||||
## 快捷导入
|
||||
|
||||
为方便使用,本模块从子模块导入了部分内容,以下内容可以直接通过本模块导入:
|
||||
|
||||
- `on` => [`on`](./on.md#on)
|
||||
- `on_metaevent` => [`on_metaevent`](./on.md#on_metaevent)
|
||||
- `on_message` => [`on_message`](./on.md#on_message)
|
||||
- `on_notice` => [`on_notice`](./on.md#on_notice)
|
||||
- `on_request` => [`on_request`](./on.md#on_request)
|
||||
- `on_startswith` => [`on_startswith`](./on.md#on_startswith)
|
||||
- `on_endswith` => [`on_endswith`](./on.md#on_endswith)
|
||||
- `on_fullmatch` => [`on_fullmatch`](./on.md#on_fullmatch)
|
||||
- `on_keyword` => [`on_keyword`](./on.md#on_keyword)
|
||||
- `on_command` => [`on_command`](./on.md#on_command)
|
||||
- `on_shell_command` => [`on_shell_command`](./on.md#on_shell_command)
|
||||
- `on_regex` => [`on_regex`](./on.md#on_regex)
|
||||
- `on_type` => [`on_type`](./on.md#on_type)
|
||||
- `CommandGroup` => [`CommandGroup`](./on.md#CommandGroup)
|
||||
- `Matchergroup` => [`MatcherGroup`](./on.md#MatcherGroup)
|
||||
- `load_plugin` => [`load_plugin`](./load.md#load_plugin)
|
||||
- `load_plugins` => [`load_plugins`](./load.md#load_plugins)
|
||||
- `load_all_plugins` => [`load_all_plugins`](./load.md#load_all_plugins)
|
||||
- `load_from_json` => [`load_from_json`](./load.md#load_from_json)
|
||||
- `load_from_toml` => [`load_from_toml`](./load.md#load_from_toml)
|
||||
- `load_builtin_plugin` => [`load_builtin_plugin`](./load.md#load_builtin_plugin)
|
||||
- `load_builtin_plugins` => [`load_builtin_plugins`](./load.md#load_builtin_plugins)
|
||||
- `require` => [`require`](./load.md#require)
|
||||
- `PluginMetadata` => [`PluginMetadata`](./plugin.md#PluginMetadata)
|
||||
|
||||
## _def_ `get_plugin(name)` {#get_plugin}
|
||||
|
||||
- **说明**
|
||||
|
||||
获取已经导入的某个插件。
|
||||
|
||||
如果为 `load_plugins` 文件夹导入的插件,则为文件(夹)名。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `name` (str): 插件名,即 [Plugin.name](./plugin.md#Plugin-name)。
|
||||
|
||||
- **返回**
|
||||
|
||||
- Plugin | None
|
||||
|
||||
## _def_ `get_plugin_by_module_name(module_name)` {#get_plugin_by_module_name}
|
||||
|
||||
- **说明**
|
||||
|
||||
通过模块名获取已经导入的某个插件。
|
||||
|
||||
如果提供的模块名为某个插件的子模块,同样会返回该插件。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `module_name` (str): 模块名,即 [Plugin.module_name](./plugin.md#Plugin-module_name)。
|
||||
|
||||
- **返回**
|
||||
|
||||
- Plugin | None
|
||||
|
||||
## _def_ `get_loaded_plugins()` {#get_loaded_plugins}
|
||||
|
||||
- **说明**
|
||||
|
||||
获取当前已导入的所有插件。
|
||||
|
||||
- **返回**
|
||||
|
||||
- set[Plugin]
|
||||
|
||||
## _def_ `get_available_plugin_names()` {#get_available_plugin_names}
|
||||
|
||||
- **说明**
|
||||
|
||||
获取当前所有可用的插件名(包含尚未加载的插件)。
|
||||
|
||||
- **返回**
|
||||
|
||||
- set[str]
|
157
website/versioned_docs/version-2.0.0rc3/api/plugin/load.md
Normal file
157
website/versioned_docs/version-2.0.0rc3/api/plugin/load.md
Normal file
@ -0,0 +1,157 @@
|
||||
---
|
||||
sidebar_position: 1
|
||||
description: nonebot.plugin.load 模块
|
||||
---
|
||||
|
||||
# nonebot.plugin.load
|
||||
|
||||
本模块定义插件加载接口。
|
||||
|
||||
## _def_ `load_plugin(module_path)` {#load_plugin}
|
||||
|
||||
- **说明**
|
||||
|
||||
加载单个插件,可以是本地插件或是通过 `pip` 安装的插件。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `module_path` (str | pathlib.Path): 插件名称 `path.to.your.plugin` 或插件路径 `pathlib.Path(path/to/your/plugin)`
|
||||
|
||||
- **返回**
|
||||
|
||||
- [Plugin](./plugin.md#Plugin) | None
|
||||
|
||||
## _def_ `load_plugins(*plugin_dir)` {#load_plugins}
|
||||
|
||||
- **说明**
|
||||
|
||||
导入文件夹下多个插件,以 `_` 开头的插件不会被导入!
|
||||
|
||||
- **参数**
|
||||
|
||||
- `*plugin_dir` (str): 文件夹路径
|
||||
|
||||
- **返回**
|
||||
|
||||
- set[[Plugin](./plugin.md#Plugin)]
|
||||
|
||||
## _def_ `load_all_plugins(module_path, plugin_dir)` {#load_all_plugins}
|
||||
|
||||
- **说明**
|
||||
|
||||
导入指定列表中的插件以及指定目录下多个插件,以 `_` 开头的插件不会被导入!
|
||||
|
||||
- **参数**
|
||||
|
||||
- `module_path` (Iterable[str]): 指定插件集合
|
||||
|
||||
- `plugin_dir` (Iterable[str]): 指定文件夹路径集合
|
||||
|
||||
- **返回**
|
||||
|
||||
- set[[Plugin](./plugin.md#Plugin)]
|
||||
|
||||
## _def_ `load_from_json(file_path, encoding='utf-8')` {#load_from_json}
|
||||
|
||||
- **说明**
|
||||
|
||||
导入指定 json 文件中的 `plugins` 以及 `plugin_dirs` 下多个插件,以 `_` 开头的插件不会被导入!
|
||||
|
||||
- **参数**
|
||||
|
||||
- `file_path` (str): 指定 json 文件路径
|
||||
|
||||
- `encoding` (str): 指定 json 文件编码
|
||||
|
||||
- **返回**
|
||||
|
||||
- set[[Plugin](./plugin.md#Plugin)]
|
||||
|
||||
- **用法**
|
||||
|
||||
```json title=plugins.json
|
||||
{
|
||||
"plugins": ["some_plugin"],
|
||||
"plugin_dirs": ["some_dir"]
|
||||
}
|
||||
```
|
||||
|
||||
```python
|
||||
nonebot.load_from_json("plugins.json")
|
||||
```
|
||||
|
||||
## _def_ `load_from_toml(file_path, encoding='utf-8')` {#load_from_toml}
|
||||
|
||||
- **说明**
|
||||
|
||||
导入指定 toml 文件 `[tool.nonebot]` 中的 `plugins` 以及 `plugin_dirs` 下多个插件,以 `_` 开头的插件不会被导入!
|
||||
|
||||
- **参数**
|
||||
|
||||
- `file_path` (str): 指定 toml 文件路径
|
||||
|
||||
- `encoding` (str): 指定 toml 文件编码
|
||||
|
||||
- **返回**
|
||||
|
||||
- set[[Plugin](./plugin.md#Plugin)]
|
||||
|
||||
- **用法**
|
||||
|
||||
```toml title=pyproject.toml
|
||||
[tool.nonebot]
|
||||
plugins = ["some_plugin"]
|
||||
plugin_dirs = ["some_dir"]
|
||||
```
|
||||
|
||||
```python
|
||||
nonebot.load_from_toml("pyproject.toml")
|
||||
```
|
||||
|
||||
## _def_ `load_builtin_plugin(name)` {#load_builtin_plugin}
|
||||
|
||||
- **说明**
|
||||
|
||||
导入 NoneBot 内置插件。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `name` (str): 插件名称
|
||||
|
||||
- **返回**
|
||||
|
||||
- [Plugin](./plugin.md#Plugin) | None
|
||||
|
||||
## _def_ `load_builtin_plugins(*plugins)` {#load_builtin_plugins}
|
||||
|
||||
- **说明**
|
||||
|
||||
导入多个 NoneBot 内置插件。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `*plugins` (str): 插件名称列表
|
||||
|
||||
- **返回**
|
||||
|
||||
- set[[Plugin](./plugin.md#Plugin)]
|
||||
|
||||
## _def_ `require(name)` {#require}
|
||||
|
||||
- **说明**
|
||||
|
||||
获取一个插件的导出内容。
|
||||
|
||||
如果为 `load_plugins` 文件夹导入的插件,则为文件(夹)名。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `name` (str): 插件名,即 [Plugin.name](./plugin.md#Plugin-name)。
|
||||
|
||||
- **返回**
|
||||
|
||||
- module
|
||||
|
||||
- **异常**
|
||||
|
||||
- `RuntimeError`: 插件无法加载
|
122
website/versioned_docs/version-2.0.0rc3/api/plugin/manager.md
Normal file
122
website/versioned_docs/version-2.0.0rc3/api/plugin/manager.md
Normal file
@ -0,0 +1,122 @@
|
||||
---
|
||||
sidebar_position: 5
|
||||
description: nonebot.plugin.manager 模块
|
||||
---
|
||||
|
||||
# nonebot.plugin.manager
|
||||
|
||||
本模块实现插件加载流程。
|
||||
|
||||
参考: [import hooks](https://docs.python.org/3/reference/import.html#import-hooks), [PEP302](https://www.python.org/dev/peps/pep-0302/)
|
||||
|
||||
## _class_ `PluginManager(plugins=None, search_path=None)` {#PluginManager}
|
||||
|
||||
- **说明**
|
||||
|
||||
插件管理器。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `plugins` (Iterable[str] | None): 独立插件模块名集合。
|
||||
|
||||
- `search_path` (Iterable[str] | None): 插件搜索路径(文件夹)。
|
||||
|
||||
### _property_ `available_plugins` {#PluginManager-available_plugins}
|
||||
|
||||
- **类型:** set[str]
|
||||
|
||||
- **说明:** 返回当前插件管理器中可用的插件名称。
|
||||
|
||||
### _property_ `searched_plugins` {#PluginManager-searched_plugins}
|
||||
|
||||
- **类型:** set[str]
|
||||
|
||||
- **说明:** 返回已搜索到的插件名称。
|
||||
|
||||
### _property_ `third_party_plugins` {#PluginManager-third_party_plugins}
|
||||
|
||||
- **类型:** set[str]
|
||||
|
||||
- **说明:** 返回所有独立插件名称。
|
||||
|
||||
### _method_ `load_all_plugins(self)` {#PluginManager-load_all_plugins}
|
||||
|
||||
- **说明**
|
||||
|
||||
加载所有可用插件。
|
||||
|
||||
- **返回**
|
||||
|
||||
- set[[Plugin](./plugin.md#Plugin)]
|
||||
|
||||
### _method_ `load_plugin(self, name)` {#PluginManager-load_plugin}
|
||||
|
||||
- **说明**
|
||||
|
||||
加载指定插件。
|
||||
|
||||
对于独立插件,可以使用完整插件模块名或者插件名称。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `name` (str): 插件名称。
|
||||
|
||||
- **返回**
|
||||
|
||||
- [Plugin](./plugin.md#Plugin) | None
|
||||
|
||||
### _method_ `prepare_plugins(self)` {#PluginManager-prepare_plugins}
|
||||
|
||||
- **说明**
|
||||
|
||||
搜索插件并缓存插件名称。
|
||||
|
||||
- **返回**
|
||||
|
||||
- set[str]
|
||||
|
||||
## _class_ `PluginFinder()` {#PluginFinder}
|
||||
|
||||
### _method_ `find_spec(self, fullname, path, target=None)` {#PluginFinder-find_spec}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `fullname` (str)
|
||||
|
||||
- `path` (Sequence[str] | None)
|
||||
|
||||
- `target` (module | None)
|
||||
|
||||
- **返回**
|
||||
|
||||
- Unknown
|
||||
|
||||
## _class_ `PluginLoader(manager, fullname, path)` {#PluginLoader}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `manager` ([PluginManager](#PluginManager))
|
||||
|
||||
- `fullname` (str)
|
||||
|
||||
- `path`
|
||||
|
||||
### _method_ `create_module(self, spec)` {#PluginLoader-create_module}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `spec`
|
||||
|
||||
- **返回**
|
||||
|
||||
- module | None
|
||||
|
||||
### _method_ `exec_module(self, module)` {#PluginLoader-exec_module}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `module` (module)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
914
website/versioned_docs/version-2.0.0rc3/api/plugin/on.md
Normal file
914
website/versioned_docs/version-2.0.0rc3/api/plugin/on.md
Normal file
@ -0,0 +1,914 @@
|
||||
---
|
||||
sidebar_position: 2
|
||||
description: nonebot.plugin.on 模块
|
||||
---
|
||||
|
||||
# nonebot.plugin.on
|
||||
|
||||
本模块定义事件响应器便携定义函数。
|
||||
|
||||
## _def_ `on(type='', rule=..., permission=..., *, handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#on}
|
||||
|
||||
- **说明**
|
||||
|
||||
注册一个基础事件响应器,可自定义类型。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `type` (str): 事件响应器类型
|
||||
|
||||
- `rule` (nonebot.internal.rule.Rule | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType): 事件响应规则
|
||||
|
||||
- `permission` (nonebot.internal.permission.Permission | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType): 事件响应权限
|
||||
|
||||
- `handlers` (list[(*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any] | [Dependent](../dependencies/index.md#Dependent)] | None): 事件处理函数列表
|
||||
|
||||
- `temp` (bool): 是否为临时事件响应器(仅执行一次)
|
||||
|
||||
- `expire_time` (datetime.datetime | datetime.timedelta | NoneType): 事件响应器最终有效时间点,过时即被删除
|
||||
|
||||
- `priority` (int): 事件响应器优先级
|
||||
|
||||
- `block` (bool): 是否阻止事件向更低优先级传递
|
||||
|
||||
- `state` (dict[Any, Any] | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- Type[nonebot.internal.matcher.matcher.Matcher]
|
||||
|
||||
## _def_ `on_metaevent(rule=..., *, handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#on_metaevent}
|
||||
|
||||
- **说明**
|
||||
|
||||
注册一个元事件响应器。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `rule` (nonebot.internal.rule.Rule | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType): 事件响应规则
|
||||
|
||||
- `handlers` (list[(*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any] | [Dependent](../dependencies/index.md#Dependent)] | None): 事件处理函数列表
|
||||
|
||||
- `temp` (bool): 是否为临时事件响应器(仅执行一次)
|
||||
|
||||
- `expire_time` (datetime.datetime | datetime.timedelta | NoneType): 事件响应器最终有效时间点,过时即被删除
|
||||
|
||||
- `priority` (int): 事件响应器优先级
|
||||
|
||||
- `block` (bool): 是否阻止事件向更低优先级传递
|
||||
|
||||
- `state` (dict[Any, Any] | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- Type[nonebot.internal.matcher.matcher.Matcher]
|
||||
|
||||
## _def_ `on_message(rule=..., permission=..., *, handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#on_message}
|
||||
|
||||
- **说明**
|
||||
|
||||
注册一个消息事件响应器。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `rule` (nonebot.internal.rule.Rule | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType): 事件响应规则
|
||||
|
||||
- `permission` (nonebot.internal.permission.Permission | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType): 事件响应权限
|
||||
|
||||
- `handlers` (list[(*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any] | [Dependent](../dependencies/index.md#Dependent)] | None): 事件处理函数列表
|
||||
|
||||
- `temp` (bool): 是否为临时事件响应器(仅执行一次)
|
||||
|
||||
- `expire_time` (datetime.datetime | datetime.timedelta | NoneType): 事件响应器最终有效时间点,过时即被删除
|
||||
|
||||
- `priority` (int): 事件响应器优先级
|
||||
|
||||
- `block` (bool): 是否阻止事件向更低优先级传递
|
||||
|
||||
- `state` (dict[Any, Any] | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- Type[nonebot.internal.matcher.matcher.Matcher]
|
||||
|
||||
## _def_ `on_notice(rule=..., *, handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#on_notice}
|
||||
|
||||
- **说明**
|
||||
|
||||
注册一个通知事件响应器。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `rule` (nonebot.internal.rule.Rule | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType): 事件响应规则
|
||||
|
||||
- `handlers` (list[(*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any] | [Dependent](../dependencies/index.md#Dependent)] | None): 事件处理函数列表
|
||||
|
||||
- `temp` (bool): 是否为临时事件响应器(仅执行一次)
|
||||
|
||||
- `expire_time` (datetime.datetime | datetime.timedelta | NoneType): 事件响应器最终有效时间点,过时即被删除
|
||||
|
||||
- `priority` (int): 事件响应器优先级
|
||||
|
||||
- `block` (bool): 是否阻止事件向更低优先级传递
|
||||
|
||||
- `state` (dict[Any, Any] | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- Type[nonebot.internal.matcher.matcher.Matcher]
|
||||
|
||||
## _def_ `on_request(rule=..., *, handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#on_request}
|
||||
|
||||
- **说明**
|
||||
|
||||
注册一个请求事件响应器。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `rule` (nonebot.internal.rule.Rule | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType): 事件响应规则
|
||||
|
||||
- `handlers` (list[(*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any] | [Dependent](../dependencies/index.md#Dependent)] | None): 事件处理函数列表
|
||||
|
||||
- `temp` (bool): 是否为临时事件响应器(仅执行一次)
|
||||
|
||||
- `expire_time` (datetime.datetime | datetime.timedelta | NoneType): 事件响应器最终有效时间点,过时即被删除
|
||||
|
||||
- `priority` (int): 事件响应器优先级
|
||||
|
||||
- `block` (bool): 是否阻止事件向更低优先级传递
|
||||
|
||||
- `state` (dict[Any, Any] | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- Type[nonebot.internal.matcher.matcher.Matcher]
|
||||
|
||||
## _def_ `on_startswith(msg, rule=..., ignorecase=..., *, permission=..., handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#on_startswith}
|
||||
|
||||
- **说明**
|
||||
|
||||
注册一个消息事件响应器,并且当消息的**文本部分**以指定内容开头时响应。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `msg` (str | tuple[str, ...]): 指定消息开头内容
|
||||
|
||||
- `rule` (nonebot.internal.rule.Rule | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType): 事件响应规则
|
||||
|
||||
- `ignorecase` (bool): 是否忽略大小写
|
||||
|
||||
- `permission` (nonebot.internal.permission.Permission | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType): 事件响应权限
|
||||
|
||||
- `handlers` (list[(*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any] | [Dependent](../dependencies/index.md#Dependent)] | None): 事件处理函数列表
|
||||
|
||||
- `temp` (bool): 是否为临时事件响应器(仅执行一次)
|
||||
|
||||
- `expire_time` (datetime.datetime | datetime.timedelta | NoneType): 事件响应器最终有效时间点,过时即被删除
|
||||
|
||||
- `priority` (int): 事件响应器优先级
|
||||
|
||||
- `block` (bool): 是否阻止事件向更低优先级传递
|
||||
|
||||
- `state` (dict[Any, Any] | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- Type[nonebot.internal.matcher.matcher.Matcher]
|
||||
|
||||
## _def_ `on_endswith(msg, rule=..., ignorecase=..., *, permission=..., handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#on_endswith}
|
||||
|
||||
- **说明**
|
||||
|
||||
注册一个消息事件响应器,并且当消息的**文本部分**以指定内容结尾时响应。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `msg` (str | tuple[str, ...]): 指定消息结尾内容
|
||||
|
||||
- `rule` (nonebot.internal.rule.Rule | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType): 事件响应规则
|
||||
|
||||
- `ignorecase` (bool): 是否忽略大小写
|
||||
|
||||
- `permission` (nonebot.internal.permission.Permission | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType): 事件响应权限
|
||||
|
||||
- `handlers` (list[(*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any] | [Dependent](../dependencies/index.md#Dependent)] | None): 事件处理函数列表
|
||||
|
||||
- `temp` (bool): 是否为临时事件响应器(仅执行一次)
|
||||
|
||||
- `expire_time` (datetime.datetime | datetime.timedelta | NoneType): 事件响应器最终有效时间点,过时即被删除
|
||||
|
||||
- `priority` (int): 事件响应器优先级
|
||||
|
||||
- `block` (bool): 是否阻止事件向更低优先级传递
|
||||
|
||||
- `state` (dict[Any, Any] | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- Type[nonebot.internal.matcher.matcher.Matcher]
|
||||
|
||||
## _def_ `on_fullmatch(msg, rule=..., ignorecase=..., *, permission=..., handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#on_fullmatch}
|
||||
|
||||
- **说明**
|
||||
|
||||
注册一个消息事件响应器,并且当消息的**文本部分**与指定内容完全一致时响应。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `msg` (str | tuple[str, ...]): 指定消息全匹配内容
|
||||
|
||||
- `rule` (nonebot.internal.rule.Rule | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType): 事件响应规则
|
||||
|
||||
- `ignorecase` (bool): 是否忽略大小写
|
||||
|
||||
- `permission` (nonebot.internal.permission.Permission | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType): 事件响应权限
|
||||
|
||||
- `handlers` (list[(*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any] | [Dependent](../dependencies/index.md#Dependent)] | None): 事件处理函数列表
|
||||
|
||||
- `temp` (bool): 是否为临时事件响应器(仅执行一次)
|
||||
|
||||
- `expire_time` (datetime.datetime | datetime.timedelta | NoneType): 事件响应器最终有效时间点,过时即被删除
|
||||
|
||||
- `priority` (int): 事件响应器优先级
|
||||
|
||||
- `block` (bool): 是否阻止事件向更低优先级传递
|
||||
|
||||
- `state` (dict[Any, Any] | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- Type[nonebot.internal.matcher.matcher.Matcher]
|
||||
|
||||
## _def_ `on_keyword(keywords, rule=..., *, permission=..., handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#on_keyword}
|
||||
|
||||
- **说明**
|
||||
|
||||
注册一个消息事件响应器,并且当消息纯文本部分包含关键词时响应。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `keywords` (set[str]): 关键词列表
|
||||
|
||||
- `rule` (nonebot.internal.rule.Rule | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType): 事件响应规则
|
||||
|
||||
- `permission` (nonebot.internal.permission.Permission | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType): 事件响应权限
|
||||
|
||||
- `handlers` (list[(*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any] | [Dependent](../dependencies/index.md#Dependent)] | None): 事件处理函数列表
|
||||
|
||||
- `temp` (bool): 是否为临时事件响应器(仅执行一次)
|
||||
|
||||
- `expire_time` (datetime.datetime | datetime.timedelta | NoneType): 事件响应器最终有效时间点,过时即被删除
|
||||
|
||||
- `priority` (int): 事件响应器优先级
|
||||
|
||||
- `block` (bool): 是否阻止事件向更低优先级传递
|
||||
|
||||
- `state` (dict[Any, Any] | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- Type[nonebot.internal.matcher.matcher.Matcher]
|
||||
|
||||
## _def_ `on_command(cmd, rule=..., aliases=..., *, permission=..., handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#on_command}
|
||||
|
||||
- **说明**
|
||||
|
||||
注册一个消息事件响应器,并且当消息以指定命令开头时响应。
|
||||
|
||||
命令匹配规则参考: `命令形式匹配 <rule.md#command-command>`\_
|
||||
|
||||
- **参数**
|
||||
|
||||
- `cmd` (str | tuple[str, ...]): 指定命令内容
|
||||
|
||||
- `rule` (nonebot.internal.rule.Rule | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType): 事件响应规则
|
||||
|
||||
- `aliases` (set[str | tuple[str, ...]] | None): 命令别名
|
||||
|
||||
- `permission` (nonebot.internal.permission.Permission | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType): 事件响应权限
|
||||
|
||||
- `handlers` (list[(*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any] | [Dependent](../dependencies/index.md#Dependent)] | None): 事件处理函数列表
|
||||
|
||||
- `temp` (bool): 是否为临时事件响应器(仅执行一次)
|
||||
|
||||
- `expire_time` (datetime.datetime | datetime.timedelta | NoneType): 事件响应器最终有效时间点,过时即被删除
|
||||
|
||||
- `priority` (int): 事件响应器优先级
|
||||
|
||||
- `block` (bool): 是否阻止事件向更低优先级传递
|
||||
|
||||
- `state` (dict[Any, Any] | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- Type[nonebot.internal.matcher.matcher.Matcher]
|
||||
|
||||
## _def_ `on_shell_command(cmd, rule=..., aliases=..., parser=..., *, permission=..., handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#on_shell_command}
|
||||
|
||||
- **说明**
|
||||
|
||||
注册一个支持 `shell_like` 解析参数的命令消息事件响应器。
|
||||
|
||||
与普通的 `on_command` 不同的是,在添加 `parser` 参数时, 响应器会自动处理消息。
|
||||
|
||||
并将用户输入的原始参数列表保存在 `state["argv"]`, `parser` 处理的参数保存在 `state["args"]` 中
|
||||
|
||||
- **参数**
|
||||
|
||||
- `cmd` (str | tuple[str, ...]): 指定命令内容
|
||||
|
||||
- `rule` (nonebot.internal.rule.Rule | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType): 事件响应规则
|
||||
|
||||
- `aliases` (set[str | tuple[str, ...]] | None): 命令别名
|
||||
|
||||
- `parser` ([ArgumentParser](../rule.md#ArgumentParser) | None): `nonebot.rule.ArgumentParser` 对象
|
||||
|
||||
- `permission` (nonebot.internal.permission.Permission | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType): 事件响应权限
|
||||
|
||||
- `handlers` (list[(*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any] | [Dependent](../dependencies/index.md#Dependent)] | None): 事件处理函数列表
|
||||
|
||||
- `temp` (bool): 是否为临时事件响应器(仅执行一次)
|
||||
|
||||
- `expire_time` (datetime.datetime | datetime.timedelta | NoneType): 事件响应器最终有效时间点,过时即被删除
|
||||
|
||||
- `priority` (int): 事件响应器优先级
|
||||
|
||||
- `block` (bool): 是否阻止事件向更低优先级传递
|
||||
|
||||
- `state` (dict[Any, Any] | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- Type[nonebot.internal.matcher.matcher.Matcher]
|
||||
|
||||
## _def_ `on_regex(pattern, flags=..., rule=..., *, permission=..., handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#on_regex}
|
||||
|
||||
- **说明**
|
||||
|
||||
注册一个消息事件响应器,并且当消息匹配正则表达式时响应。
|
||||
|
||||
命令匹配规则参考: `正则匹配 <rule.md#regex-regex-flags-0>`\_
|
||||
|
||||
- **参数**
|
||||
|
||||
- `pattern` (str): 正则表达式
|
||||
|
||||
- `flags` (int | re.RegexFlag): 正则匹配标志
|
||||
|
||||
- `rule` (nonebot.internal.rule.Rule | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType): 事件响应规则
|
||||
|
||||
- `permission` (nonebot.internal.permission.Permission | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType): 事件响应权限
|
||||
|
||||
- `handlers` (list[(*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any] | [Dependent](../dependencies/index.md#Dependent)] | None): 事件处理函数列表
|
||||
|
||||
- `temp` (bool): 是否为临时事件响应器(仅执行一次)
|
||||
|
||||
- `expire_time` (datetime.datetime | datetime.timedelta | NoneType): 事件响应器最终有效时间点,过时即被删除
|
||||
|
||||
- `priority` (int): 事件响应器优先级
|
||||
|
||||
- `block` (bool): 是否阻止事件向更低优先级传递
|
||||
|
||||
- `state` (dict[Any, Any] | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- Type[nonebot.internal.matcher.matcher.Matcher]
|
||||
|
||||
## _def_ `on_type(types, rule=..., *, permission=..., handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#on_type}
|
||||
|
||||
- **说明**
|
||||
|
||||
注册一个事件响应器,并且当事件为指定类型时响应。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `types` (Type[nonebot.internal.adapter.event.Event] | tuple[Type[nonebot.internal.adapter.event.Event], ...]): 事件类型
|
||||
|
||||
- `rule` (nonebot.internal.rule.Rule | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType): 事件响应规则
|
||||
|
||||
- `permission` (nonebot.internal.permission.Permission | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType): 事件响应权限
|
||||
|
||||
- `handlers` (list[(*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any] | [Dependent](../dependencies/index.md#Dependent)] | None): 事件处理函数列表
|
||||
|
||||
- `temp` (bool): 是否为临时事件响应器(仅执行一次)
|
||||
|
||||
- `expire_time` (datetime.datetime | datetime.timedelta | NoneType): 事件响应器最终有效时间点,过时即被删除
|
||||
|
||||
- `priority` (int): 事件响应器优先级
|
||||
|
||||
- `block` (bool): 是否阻止事件向更低优先级传递
|
||||
|
||||
- `state` (dict[Any, Any] | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- Type[nonebot.internal.matcher.matcher.Matcher]
|
||||
|
||||
## _class_ `CommandGroup(cmd, *, rule=..., permission=..., handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#CommandGroup}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `cmd` (str | tuple[str, ...])
|
||||
|
||||
- `rule` (nonebot.internal.rule.Rule | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType)
|
||||
|
||||
- `permission` (nonebot.internal.permission.Permission | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType)
|
||||
|
||||
- `handlers` (list[(*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any] | [Dependent](../dependencies/index.md#Dependent)] | None)
|
||||
|
||||
- `temp` (bool)
|
||||
|
||||
- `expire_time` (datetime.datetime | datetime.timedelta | NoneType)
|
||||
|
||||
- `priority` (int)
|
||||
|
||||
- `block` (bool)
|
||||
|
||||
- `state` (dict[Any, Any] | None)
|
||||
|
||||
### _method_ `command(self, cmd, *, rule=..., aliases=..., permission=..., handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#CommandGroup-command}
|
||||
|
||||
- **说明**
|
||||
|
||||
注册一个新的命令。新参数将会覆盖命令组默认值
|
||||
|
||||
- **参数**
|
||||
|
||||
- `cmd` (str | tuple[str, ...]): 指定命令内容
|
||||
|
||||
- `rule` (nonebot.internal.rule.Rule | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType): 事件响应规则
|
||||
|
||||
- `aliases` (set[str | tuple[str, ...]] | None): 命令别名
|
||||
|
||||
- `permission` (nonebot.internal.permission.Permission | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType): 事件响应权限
|
||||
|
||||
- `handlers` (list[(*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any] | [Dependent](../dependencies/index.md#Dependent)] | None): 事件处理函数列表
|
||||
|
||||
- `temp` (bool): 是否为临时事件响应器(仅执行一次)
|
||||
|
||||
- `expire_time` (datetime.datetime | datetime.timedelta | NoneType): 事件响应器最终有效时间点,过时即被删除
|
||||
|
||||
- `priority` (int): 事件响应器优先级
|
||||
|
||||
- `block` (bool): 是否阻止事件向更低优先级传递
|
||||
|
||||
- `state` (dict[Any, Any] | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- Type[nonebot.internal.matcher.matcher.Matcher]
|
||||
|
||||
### _method_ `shell_command(self, cmd, *, rule=..., aliases=..., parser=..., permission=..., handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#CommandGroup-shell_command}
|
||||
|
||||
- **说明**
|
||||
|
||||
注册一个新的 `shell_like` 命令。新参数将会覆盖命令组默认值
|
||||
|
||||
- **参数**
|
||||
|
||||
- `cmd` (str | tuple[str, ...]): 指定命令内容
|
||||
|
||||
- `rule` (nonebot.internal.rule.Rule | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType): 事件响应规则
|
||||
|
||||
- `aliases` (set[str | tuple[str, ...]] | None): 命令别名
|
||||
|
||||
- `parser` ([ArgumentParser](../rule.md#ArgumentParser) | None): `nonebot.rule.ArgumentParser` 对象
|
||||
|
||||
- `permission` (nonebot.internal.permission.Permission | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType): 事件响应权限
|
||||
|
||||
- `handlers` (list[(*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any] | [Dependent](../dependencies/index.md#Dependent)] | None): 事件处理函数列表
|
||||
|
||||
- `temp` (bool): 是否为临时事件响应器(仅执行一次)
|
||||
|
||||
- `expire_time` (datetime.datetime | datetime.timedelta | NoneType): 事件响应器最终有效时间点,过时即被删除
|
||||
|
||||
- `priority` (int): 事件响应器优先级
|
||||
|
||||
- `block` (bool): 是否阻止事件向更低优先级传递
|
||||
|
||||
- `state` (dict[Any, Any] | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- Type[nonebot.internal.matcher.matcher.Matcher]
|
||||
|
||||
## _class_ `MatcherGroup(*, type=..., rule=..., permission=..., handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#MatcherGroup}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `type` (str)
|
||||
|
||||
- `rule` (nonebot.internal.rule.Rule | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType)
|
||||
|
||||
- `permission` (nonebot.internal.permission.Permission | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType)
|
||||
|
||||
- `handlers` (list[(*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any] | [Dependent](../dependencies/index.md#Dependent)] | None)
|
||||
|
||||
- `temp` (bool)
|
||||
|
||||
- `expire_time` (datetime.datetime | datetime.timedelta | NoneType)
|
||||
|
||||
- `priority` (int)
|
||||
|
||||
- `block` (bool)
|
||||
|
||||
- `state` (dict[Any, Any] | None)
|
||||
|
||||
### _method_ `on(self, *, type=..., rule=..., permission=..., handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#MatcherGroup-on}
|
||||
|
||||
- **说明**
|
||||
|
||||
注册一个基础事件响应器,可自定义类型。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `type` (str): 事件响应器类型
|
||||
|
||||
- `rule` (nonebot.internal.rule.Rule | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType): 事件响应规则
|
||||
|
||||
- `permission` (nonebot.internal.permission.Permission | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType): 事件响应权限
|
||||
|
||||
- `handlers` (list[(*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any] | [Dependent](../dependencies/index.md#Dependent)] | None): 事件处理函数列表
|
||||
|
||||
- `temp` (bool): 是否为临时事件响应器(仅执行一次)
|
||||
|
||||
- `expire_time` (datetime.datetime | datetime.timedelta | NoneType): 事件响应器最终有效时间点,过时即被删除
|
||||
|
||||
- `priority` (int): 事件响应器优先级
|
||||
|
||||
- `block` (bool): 是否阻止事件向更低优先级传递
|
||||
|
||||
- `state` (dict[Any, Any] | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- Type[nonebot.internal.matcher.matcher.Matcher]
|
||||
|
||||
### _method_ `on_command(self, cmd, aliases=..., *, rule=..., permission=..., handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#MatcherGroup-on_command}
|
||||
|
||||
- **说明**
|
||||
|
||||
注册一个消息事件响应器,并且当消息以指定命令开头时响应。
|
||||
|
||||
命令匹配规则参考: `命令形式匹配 <rule.md#command-command>`\_
|
||||
|
||||
- **参数**
|
||||
|
||||
- `cmd` (str | tuple[str, ...]): 指定命令内容
|
||||
|
||||
- `aliases` (set[str | tuple[str, ...]] | None): 命令别名
|
||||
|
||||
- `rule` (nonebot.internal.rule.Rule | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType): 事件响应规则
|
||||
|
||||
- `permission` (nonebot.internal.permission.Permission | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType): 事件响应权限
|
||||
|
||||
- `handlers` (list[(*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any] | [Dependent](../dependencies/index.md#Dependent)] | None): 事件处理函数列表
|
||||
|
||||
- `temp` (bool): 是否为临时事件响应器(仅执行一次)
|
||||
|
||||
- `expire_time` (datetime.datetime | datetime.timedelta | NoneType): 事件响应器最终有效时间点,过时即被删除
|
||||
|
||||
- `priority` (int): 事件响应器优先级
|
||||
|
||||
- `block` (bool): 是否阻止事件向更低优先级传递
|
||||
|
||||
- `state` (dict[Any, Any] | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- Type[nonebot.internal.matcher.matcher.Matcher]
|
||||
|
||||
### _method_ `on_endswith(self, msg, *, ignorecase=..., rule=..., permission=..., handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#MatcherGroup-on_endswith}
|
||||
|
||||
- **说明**
|
||||
|
||||
注册一个消息事件响应器,并且当消息的**文本部分**以指定内容结尾时响应。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `msg` (str | tuple[str, ...]): 指定消息结尾内容
|
||||
|
||||
- `ignorecase` (bool): 是否忽略大小写
|
||||
|
||||
- `rule` (nonebot.internal.rule.Rule | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType): 事件响应规则
|
||||
|
||||
- `permission` (nonebot.internal.permission.Permission | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType): 事件响应权限
|
||||
|
||||
- `handlers` (list[(*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any] | [Dependent](../dependencies/index.md#Dependent)] | None): 事件处理函数列表
|
||||
|
||||
- `temp` (bool): 是否为临时事件响应器(仅执行一次)
|
||||
|
||||
- `expire_time` (datetime.datetime | datetime.timedelta | NoneType): 事件响应器最终有效时间点,过时即被删除
|
||||
|
||||
- `priority` (int): 事件响应器优先级
|
||||
|
||||
- `block` (bool): 是否阻止事件向更低优先级传递
|
||||
|
||||
- `state` (dict[Any, Any] | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- Type[nonebot.internal.matcher.matcher.Matcher]
|
||||
|
||||
### _method_ `on_fullmatch(self, msg, *, ignorecase=..., rule=..., permission=..., handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#MatcherGroup-on_fullmatch}
|
||||
|
||||
- **说明**
|
||||
|
||||
注册一个消息事件响应器,并且当消息的**文本部分**与指定内容完全一致时响应。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `msg` (str | tuple[str, ...]): 指定消息全匹配内容
|
||||
|
||||
- `ignorecase` (bool): 是否忽略大小写
|
||||
|
||||
- `rule` (nonebot.internal.rule.Rule | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType): 事件响应规则
|
||||
|
||||
- `permission` (nonebot.internal.permission.Permission | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType): 事件响应权限
|
||||
|
||||
- `handlers` (list[(*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any] | [Dependent](../dependencies/index.md#Dependent)] | None): 事件处理函数列表
|
||||
|
||||
- `temp` (bool): 是否为临时事件响应器(仅执行一次)
|
||||
|
||||
- `expire_time` (datetime.datetime | datetime.timedelta | NoneType): 事件响应器最终有效时间点,过时即被删除
|
||||
|
||||
- `priority` (int): 事件响应器优先级
|
||||
|
||||
- `block` (bool): 是否阻止事件向更低优先级传递
|
||||
|
||||
- `state` (dict[Any, Any] | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- Type[nonebot.internal.matcher.matcher.Matcher]
|
||||
|
||||
### _method_ `on_keyword(self, keywords, *, rule=..., permission=..., handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#MatcherGroup-on_keyword}
|
||||
|
||||
- **说明**
|
||||
|
||||
注册一个消息事件响应器,并且当消息纯文本部分包含关键词时响应。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `keywords` (set[str]): 关键词列表
|
||||
|
||||
- `rule` (nonebot.internal.rule.Rule | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType): 事件响应规则
|
||||
|
||||
- `permission` (nonebot.internal.permission.Permission | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType): 事件响应权限
|
||||
|
||||
- `handlers` (list[(*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any] | [Dependent](../dependencies/index.md#Dependent)] | None): 事件处理函数列表
|
||||
|
||||
- `temp` (bool): 是否为临时事件响应器(仅执行一次)
|
||||
|
||||
- `expire_time` (datetime.datetime | datetime.timedelta | NoneType): 事件响应器最终有效时间点,过时即被删除
|
||||
|
||||
- `priority` (int): 事件响应器优先级
|
||||
|
||||
- `block` (bool): 是否阻止事件向更低优先级传递
|
||||
|
||||
- `state` (dict[Any, Any] | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- Type[nonebot.internal.matcher.matcher.Matcher]
|
||||
|
||||
### _method_ `on_message(self, *, rule=..., permission=..., handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#MatcherGroup-on_message}
|
||||
|
||||
- **说明**
|
||||
|
||||
注册一个消息事件响应器。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `rule` (nonebot.internal.rule.Rule | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType): 事件响应规则
|
||||
|
||||
- `permission` (nonebot.internal.permission.Permission | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType): 事件响应权限
|
||||
|
||||
- `handlers` (list[(*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any] | [Dependent](../dependencies/index.md#Dependent)] | None): 事件处理函数列表
|
||||
|
||||
- `temp` (bool): 是否为临时事件响应器(仅执行一次)
|
||||
|
||||
- `expire_time` (datetime.datetime | datetime.timedelta | NoneType): 事件响应器最终有效时间点,过时即被删除
|
||||
|
||||
- `priority` (int): 事件响应器优先级
|
||||
|
||||
- `block` (bool): 是否阻止事件向更低优先级传递
|
||||
|
||||
- `state` (dict[Any, Any] | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- Type[nonebot.internal.matcher.matcher.Matcher]
|
||||
|
||||
### _method_ `on_metaevent(self, *, rule=..., handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#MatcherGroup-on_metaevent}
|
||||
|
||||
- **说明**
|
||||
|
||||
注册一个元事件响应器。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `rule` (nonebot.internal.rule.Rule | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType): 事件响应规则
|
||||
|
||||
- `handlers` (list[(*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any] | [Dependent](../dependencies/index.md#Dependent)] | None): 事件处理函数列表
|
||||
|
||||
- `temp` (bool): 是否为临时事件响应器(仅执行一次)
|
||||
|
||||
- `expire_time` (datetime.datetime | datetime.timedelta | NoneType): 事件响应器最终有效时间点,过时即被删除
|
||||
|
||||
- `priority` (int): 事件响应器优先级
|
||||
|
||||
- `block` (bool): 是否阻止事件向更低优先级传递
|
||||
|
||||
- `state` (dict[Any, Any] | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- Type[nonebot.internal.matcher.matcher.Matcher]
|
||||
|
||||
### _method_ `on_notice(self, *, rule=..., handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#MatcherGroup-on_notice}
|
||||
|
||||
- **说明**
|
||||
|
||||
注册一个通知事件响应器。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `rule` (nonebot.internal.rule.Rule | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType): 事件响应规则
|
||||
|
||||
- `handlers` (list[(*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any] | [Dependent](../dependencies/index.md#Dependent)] | None): 事件处理函数列表
|
||||
|
||||
- `temp` (bool): 是否为临时事件响应器(仅执行一次)
|
||||
|
||||
- `expire_time` (datetime.datetime | datetime.timedelta | NoneType): 事件响应器最终有效时间点,过时即被删除
|
||||
|
||||
- `priority` (int): 事件响应器优先级
|
||||
|
||||
- `block` (bool): 是否阻止事件向更低优先级传递
|
||||
|
||||
- `state` (dict[Any, Any] | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- Type[nonebot.internal.matcher.matcher.Matcher]
|
||||
|
||||
### _method_ `on_regex(self, pattern, flags=..., *, rule=..., permission=..., handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#MatcherGroup-on_regex}
|
||||
|
||||
- **说明**
|
||||
|
||||
注册一个消息事件响应器,并且当消息匹配正则表达式时响应。
|
||||
|
||||
命令匹配规则参考: `正则匹配 <rule.md#regex-regex-flags-0>`\_
|
||||
|
||||
- **参数**
|
||||
|
||||
- `pattern` (str): 正则表达式
|
||||
|
||||
- `flags` (int | re.RegexFlag): 正则匹配标志
|
||||
|
||||
- `rule` (nonebot.internal.rule.Rule | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType): 事件响应规则
|
||||
|
||||
- `permission` (nonebot.internal.permission.Permission | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType): 事件响应权限
|
||||
|
||||
- `handlers` (list[(*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any] | [Dependent](../dependencies/index.md#Dependent)] | None): 事件处理函数列表
|
||||
|
||||
- `temp` (bool): 是否为临时事件响应器(仅执行一次)
|
||||
|
||||
- `expire_time` (datetime.datetime | datetime.timedelta | NoneType): 事件响应器最终有效时间点,过时即被删除
|
||||
|
||||
- `priority` (int): 事件响应器优先级
|
||||
|
||||
- `block` (bool): 是否阻止事件向更低优先级传递
|
||||
|
||||
- `state` (dict[Any, Any] | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- Type[nonebot.internal.matcher.matcher.Matcher]
|
||||
|
||||
### _method_ `on_request(self, *, rule=..., handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#MatcherGroup-on_request}
|
||||
|
||||
- **说明**
|
||||
|
||||
注册一个请求事件响应器。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `rule` (nonebot.internal.rule.Rule | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType): 事件响应规则
|
||||
|
||||
- `handlers` (list[(*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any] | [Dependent](../dependencies/index.md#Dependent)] | None): 事件处理函数列表
|
||||
|
||||
- `temp` (bool): 是否为临时事件响应器(仅执行一次)
|
||||
|
||||
- `expire_time` (datetime.datetime | datetime.timedelta | NoneType): 事件响应器最终有效时间点,过时即被删除
|
||||
|
||||
- `priority` (int): 事件响应器优先级
|
||||
|
||||
- `block` (bool): 是否阻止事件向更低优先级传递
|
||||
|
||||
- `state` (dict[Any, Any] | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- Type[nonebot.internal.matcher.matcher.Matcher]
|
||||
|
||||
### _method_ `on_shell_command(self, cmd, aliases=..., parser=..., *, rule=..., permission=..., handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#MatcherGroup-on_shell_command}
|
||||
|
||||
- **说明**
|
||||
|
||||
注册一个支持 `shell_like` 解析参数的命令消息事件响应器。
|
||||
|
||||
与普通的 `on_command` 不同的是,在添加 `parser` 参数时, 响应器会自动处理消息。
|
||||
|
||||
并将用户输入的原始参数列表保存在 `state["argv"]`, `parser` 处理的参数保存在 `state["args"]` 中
|
||||
|
||||
- **参数**
|
||||
|
||||
- `cmd` (str | tuple[str, ...]): 指定命令内容
|
||||
|
||||
- `aliases` (set[str | tuple[str, ...]] | None): 命令别名
|
||||
|
||||
- `parser` ([ArgumentParser](../rule.md#ArgumentParser) | None): `nonebot.rule.ArgumentParser` 对象
|
||||
|
||||
- `rule` (nonebot.internal.rule.Rule | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType): 事件响应规则
|
||||
|
||||
- `permission` (nonebot.internal.permission.Permission | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType): 事件响应权限
|
||||
|
||||
- `handlers` (list[(*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any] | [Dependent](../dependencies/index.md#Dependent)] | None): 事件处理函数列表
|
||||
|
||||
- `temp` (bool): 是否为临时事件响应器(仅执行一次)
|
||||
|
||||
- `expire_time` (datetime.datetime | datetime.timedelta | NoneType): 事件响应器最终有效时间点,过时即被删除
|
||||
|
||||
- `priority` (int): 事件响应器优先级
|
||||
|
||||
- `block` (bool): 是否阻止事件向更低优先级传递
|
||||
|
||||
- `state` (dict[Any, Any] | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- Type[nonebot.internal.matcher.matcher.Matcher]
|
||||
|
||||
### _method_ `on_startswith(self, msg, *, ignorecase=..., rule=..., permission=..., handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#MatcherGroup-on_startswith}
|
||||
|
||||
- **说明**
|
||||
|
||||
注册一个消息事件响应器,并且当消息的**文本部分**以指定内容开头时响应。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `msg` (str | tuple[str, ...]): 指定消息开头内容
|
||||
|
||||
- `ignorecase` (bool): 是否忽略大小写
|
||||
|
||||
- `rule` (nonebot.internal.rule.Rule | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType): 事件响应规则
|
||||
|
||||
- `permission` (nonebot.internal.permission.Permission | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType): 事件响应权限
|
||||
|
||||
- `handlers` (list[(*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any] | [Dependent](../dependencies/index.md#Dependent)] | None): 事件处理函数列表
|
||||
|
||||
- `temp` (bool): 是否为临时事件响应器(仅执行一次)
|
||||
|
||||
- `expire_time` (datetime.datetime | datetime.timedelta | NoneType): 事件响应器最终有效时间点,过时即被删除
|
||||
|
||||
- `priority` (int): 事件响应器优先级
|
||||
|
||||
- `block` (bool): 是否阻止事件向更低优先级传递
|
||||
|
||||
- `state` (dict[Any, Any] | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- Type[nonebot.internal.matcher.matcher.Matcher]
|
||||
|
||||
### _method_ `on_type(self, types, *, rule=..., permission=..., handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#MatcherGroup-on_type}
|
||||
|
||||
- **说明**
|
||||
|
||||
注册一个事件响应器,并且当事件为指定类型时响应。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `types` (Type[nonebot.internal.adapter.event.Event] | tuple[Type[nonebot.internal.adapter.event.Event]]): 事件类型
|
||||
|
||||
- `rule` (nonebot.internal.rule.Rule | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType): 事件响应规则
|
||||
|
||||
- `permission` (nonebot.internal.permission.Permission | (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | NoneType): 事件响应权限
|
||||
|
||||
- `handlers` (list[(*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any] | [Dependent](../dependencies/index.md#Dependent)] | None): 事件处理函数列表
|
||||
|
||||
- `temp` (bool): 是否为临时事件响应器(仅执行一次)
|
||||
|
||||
- `expire_time` (datetime.datetime | datetime.timedelta | NoneType): 事件响应器最终有效时间点,过时即被删除
|
||||
|
||||
- `priority` (int): 事件响应器优先级
|
||||
|
||||
- `block` (bool): 是否阻止事件向更低优先级传递
|
||||
|
||||
- `state` (dict[Any, Any] | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- Type[nonebot.internal.matcher.matcher.Matcher]
|
116
website/versioned_docs/version-2.0.0rc3/api/plugin/plugin.md
Normal file
116
website/versioned_docs/version-2.0.0rc3/api/plugin/plugin.md
Normal file
@ -0,0 +1,116 @@
|
||||
---
|
||||
sidebar_position: 3
|
||||
description: nonebot.plugin.plugin 模块
|
||||
---
|
||||
|
||||
# nonebot.plugin.plugin
|
||||
|
||||
本模块定义插件对象。
|
||||
|
||||
## _class_ `PluginMetadata(name, description, usage, config=None, extra=<factory>)` {#PluginMetadata}
|
||||
|
||||
- **说明**
|
||||
|
||||
插件元信息,由插件编写者提供
|
||||
|
||||
- **参数**
|
||||
|
||||
- `name` (str)
|
||||
|
||||
- `description` (str)
|
||||
|
||||
- `usage` (str)
|
||||
|
||||
- `config` (Type[pydantic.main.BaseModel] | None)
|
||||
|
||||
- `extra` (dict[Any, Any])
|
||||
|
||||
### _class-var_ `config` {#PluginMetadata-config}
|
||||
|
||||
- **类型:** Type[pydantic.main.BaseModel] | None
|
||||
|
||||
- **说明:** 插件配置项
|
||||
|
||||
### _instance-var_ `name` {#PluginMetadata-name}
|
||||
|
||||
- **类型:** str
|
||||
|
||||
- **说明:** 插件可阅读名称
|
||||
|
||||
### _instance-var_ `description` {#PluginMetadata-description}
|
||||
|
||||
- **类型:** str
|
||||
|
||||
- **说明:** 插件功能介绍
|
||||
|
||||
### _instance-var_ `usage` {#PluginMetadata-usage}
|
||||
|
||||
- **类型:** str
|
||||
|
||||
- **说明:** 插件使用方法
|
||||
|
||||
## _class_ `Plugin(name, module, module_name, manager, matcher=<factory>, parent_plugin=None, sub_plugins=<factory>, metadata=None)` {#Plugin}
|
||||
|
||||
- **说明**
|
||||
|
||||
存储插件信息
|
||||
|
||||
- **参数**
|
||||
|
||||
- `name` (str)
|
||||
|
||||
- `module` (module)
|
||||
|
||||
- `module_name` (str)
|
||||
|
||||
- `manager` (PluginManager)
|
||||
|
||||
- `matcher` (set[Type[nonebot.internal.matcher.matcher.Matcher]])
|
||||
|
||||
- `parent_plugin` (Plugin | None)
|
||||
|
||||
- `sub_plugins` (set[Plugin])
|
||||
|
||||
- `metadata` ([PluginMetadata](#PluginMetadata) | None)
|
||||
|
||||
### _class-var_ `parent_plugin` {#Plugin-parent_plugin}
|
||||
|
||||
- **类型:** Plugin | None
|
||||
|
||||
- **说明:** 父插件
|
||||
|
||||
### _instance-var_ `name` {#Plugin-name}
|
||||
|
||||
- **类型:** str
|
||||
|
||||
- **说明:** 插件索引标识,NoneBot 使用 文件/文件夹 名称作为标识符
|
||||
|
||||
### _instance-var_ `module` {#Plugin-module}
|
||||
|
||||
- **类型:** module
|
||||
|
||||
- **说明:** 插件模块对象
|
||||
|
||||
### _instance-var_ `module_name` {#Plugin-module_name}
|
||||
|
||||
- **类型:** str
|
||||
|
||||
- **说明:** 点分割模块路径
|
||||
|
||||
### _instance-var_ `manager` {#Plugin-manager}
|
||||
|
||||
- **类型:** PluginManager
|
||||
|
||||
- **说明:** 导入该插件的插件管理器
|
||||
|
||||
### _instance-var_ `matcher` {#Plugin-matcher}
|
||||
|
||||
- **类型:** set[Type[nonebot.internal.matcher.matcher.Matcher]]
|
||||
|
||||
- **说明:** 插件内定义的 `Matcher`
|
||||
|
||||
### _instance-var_ `sub_plugins` {#Plugin-sub_plugins}
|
||||
|
||||
- **类型:** set[Plugin]
|
||||
|
||||
- **说明:** 子插件集合
|
396
website/versioned_docs/version-2.0.0rc3/api/rule.md
Normal file
396
website/versioned_docs/version-2.0.0rc3/api/rule.md
Normal file
@ -0,0 +1,396 @@
|
||||
---
|
||||
sidebar_position: 5
|
||||
description: nonebot.rule 模块
|
||||
---
|
||||
|
||||
# nonebot.rule
|
||||
|
||||
本模块是 {ref}`nonebot.matcher.Matcher.rule` 的类型定义。
|
||||
|
||||
每个事件响应器 [Matcher](./matcher.md#Matcher) 拥有一个匹配规则 [Rule](#Rule)
|
||||
其中是 `RuleChecker` 的集合,只有当所有 `RuleChecker` 检查结果为 `True` 时继续运行。
|
||||
|
||||
## _class_ `Rule(*checkers)` {#Rule}
|
||||
|
||||
- **说明**
|
||||
|
||||
[Matcher](./matcher.md#Matcher) 规则类。
|
||||
|
||||
当事件传递时,在 [Matcher](./matcher.md#Matcher) 运行前进行检查。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `*checkers` ((*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool] | [Dependent](./dependencies/index.md#Dependent)[bool])
|
||||
|
||||
- **用法**
|
||||
|
||||
```python
|
||||
Rule(async_function) & sync_function
|
||||
# 等价于
|
||||
Rule(async_function, sync_function)
|
||||
```
|
||||
|
||||
### _async method_ `__call__(self, bot, event, state, stack=None, dependency_cache=None)` {#Rule-**call**}
|
||||
|
||||
- **说明**
|
||||
|
||||
检查是否符合所有规则
|
||||
|
||||
- **参数**
|
||||
|
||||
- `bot` (nonebot.internal.adapter.bot.Bot): Bot 对象
|
||||
|
||||
- `event` (nonebot.internal.adapter.event.Event): Event 对象
|
||||
|
||||
- `state` (dict[Any, Any]): 当前 State
|
||||
|
||||
- `stack` (contextlib.AsyncExitStack | None): 异步上下文栈
|
||||
|
||||
- `dependency_cache` (dict[(*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any], Task[Any]] | None): 依赖缓存
|
||||
|
||||
- **返回**
|
||||
|
||||
- bool
|
||||
|
||||
## _class_ `CMD_RESULT()` {#CMD_RESULT}
|
||||
|
||||
## _class_ `TRIE_VALUE(command_start, command)` {#TRIE_VALUE}
|
||||
|
||||
- **说明**
|
||||
|
||||
TRIE_VALUE(command_start, command)
|
||||
|
||||
- **参数**
|
||||
|
||||
- `command_start` (str)
|
||||
|
||||
- `command` (tuple[str, ...])
|
||||
|
||||
## _class_ `StartswithRule(msg, ignorecase=False)` {#StartswithRule}
|
||||
|
||||
- **说明**
|
||||
|
||||
检查消息纯文本是否以指定字符串开头。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `msg` (tuple[str, ...]): 指定消息开头字符串元组
|
||||
|
||||
- `ignorecase` (bool): 是否忽略大小写
|
||||
|
||||
## _def_ `startswith(msg, ignorecase=False)` {#startswith}
|
||||
|
||||
- **说明**
|
||||
|
||||
匹配消息纯文本开头。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `msg` (str | tuple[str, ...]): 指定消息开头字符串元组
|
||||
|
||||
- `ignorecase` (bool): 是否忽略大小写
|
||||
|
||||
- **返回**
|
||||
|
||||
- nonebot.internal.rule.Rule
|
||||
|
||||
## _class_ `EndswithRule(msg, ignorecase=False)` {#EndswithRule}
|
||||
|
||||
- **说明**
|
||||
|
||||
检查消息纯文本是否以指定字符串结尾。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `msg` (tuple[str, ...]): 指定消息结尾字符串元组
|
||||
|
||||
- `ignorecase` (bool): 是否忽略大小写
|
||||
|
||||
## _def_ `endswith(msg, ignorecase=False)` {#endswith}
|
||||
|
||||
- **说明**
|
||||
|
||||
匹配消息纯文本结尾。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `msg` (str | tuple[str, ...]): 指定消息开头字符串元组
|
||||
|
||||
- `ignorecase` (bool): 是否忽略大小写
|
||||
|
||||
- **返回**
|
||||
|
||||
- nonebot.internal.rule.Rule
|
||||
|
||||
## _class_ `FullmatchRule(msg, ignorecase=False)` {#FullmatchRule}
|
||||
|
||||
- **说明**
|
||||
|
||||
检查消息纯文本是否与指定字符串全匹配。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `msg` (tuple[str, ...]): 指定消息全匹配字符串元组
|
||||
|
||||
- `ignorecase` (bool): 是否忽略大小写
|
||||
|
||||
## _def_ `fullmatch(msg, ignorecase=False)` {#fullmatch}
|
||||
|
||||
- **说明**
|
||||
|
||||
完全匹配消息。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `msg` (str | tuple[str, ...]): 指定消息全匹配字符串元组
|
||||
|
||||
- `ignorecase` (bool): 是否忽略大小写
|
||||
|
||||
- **返回**
|
||||
|
||||
- nonebot.internal.rule.Rule
|
||||
|
||||
## _class_ `KeywordsRule(*keywords)` {#KeywordsRule}
|
||||
|
||||
- **说明**
|
||||
|
||||
检查消息纯文本是否包含指定关键字。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `*keywords` (str): 指定关键字元组
|
||||
|
||||
## _def_ `keyword(*keywords)` {#keyword}
|
||||
|
||||
- **说明**
|
||||
|
||||
匹配消息纯文本关键词。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `*keywords` (str): 指定关键字元组
|
||||
|
||||
- **返回**
|
||||
|
||||
- nonebot.internal.rule.Rule
|
||||
|
||||
## _class_ `CommandRule(cmds)` {#CommandRule}
|
||||
|
||||
- **说明**
|
||||
|
||||
检查消息是否为指定命令。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `cmds` (list[tuple[str, ...]]): 指定命令元组列表
|
||||
|
||||
## _def_ `command(*cmds)` {#command}
|
||||
|
||||
- **说明**
|
||||
|
||||
匹配消息命令。
|
||||
|
||||
根据配置里提供的 [`command_start`](./config.md#Config-command_start),
|
||||
[`command_sep`](./config.md#Config-command_sep) 判断消息是否为命令。
|
||||
|
||||
可以通过 [Command](./params.md#Command) 获取匹配成功的命令(例: `("test",)`),
|
||||
通过 [RawCommand](./params.md#RawCommand) 获取匹配成功的原始命令文本(例: `"/test"`),
|
||||
通过 [CommandArg](./params.md#CommandArg) 获取匹配成功的命令参数。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `*cmds` (str | tuple[str, ...]): 命令文本或命令元组
|
||||
|
||||
- **返回**
|
||||
|
||||
- nonebot.internal.rule.Rule
|
||||
|
||||
- **用法**
|
||||
|
||||
使用默认 `command_start`, `command_sep` 配置
|
||||
|
||||
命令 `("test",)` 可以匹配: `/test` 开头的消息
|
||||
命令 `("test", "sub")` 可以匹配: `/test.sub` 开头的消息
|
||||
|
||||
:::tip 提示
|
||||
命令内容与后续消息间无需空格!
|
||||
:::
|
||||
|
||||
## _class_ `ArgumentParser(prog=None, usage=None, description=None, epilog=None, parents=[], formatter_class=HelpFormatter, prefix_chars='-', fromfile_prefix_chars=None, argument_default=None, conflict_handler='error', add_help=True, allow_abbrev=True, exit_on_error=True)` {#ArgumentParser}
|
||||
|
||||
- **说明**
|
||||
|
||||
`shell_like` 命令参数解析器,解析出错时不会退出程序。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `prog`
|
||||
|
||||
- `usage`
|
||||
|
||||
- `description`
|
||||
|
||||
- `epilog`
|
||||
|
||||
- `parents`
|
||||
|
||||
- `formatter_class`
|
||||
|
||||
- `prefix_chars`
|
||||
|
||||
- `fromfile_prefix_chars`
|
||||
|
||||
- `argument_default`
|
||||
|
||||
- `conflict_handler`
|
||||
|
||||
- `add_help`
|
||||
|
||||
- `allow_abbrev`
|
||||
|
||||
- `exit_on_error`
|
||||
|
||||
- **用法**
|
||||
|
||||
用法与 `argparse.ArgumentParser` 相同,
|
||||
参考文档: [argparse](https://docs.python.org/3/library/argparse.html)
|
||||
|
||||
## _class_ `ShellCommandRule(cmds, parser)` {#ShellCommandRule}
|
||||
|
||||
- **说明**
|
||||
|
||||
检查消息是否为指定 shell 命令。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `cmds` (list[tuple[str, ...]]): 指定命令元组列表
|
||||
|
||||
- `parser` ([ArgumentParser](#ArgumentParser) | None): 可选参数解析器
|
||||
|
||||
## _def_ `shell_command(*cmds, parser=None)` {#shell_command}
|
||||
|
||||
- **说明**
|
||||
|
||||
匹配 `shell_like` 形式的消息命令。
|
||||
|
||||
根据配置里提供的 [`command_start`](./config.md#Config-command_start),
|
||||
[`command_sep`](./config.md#Config-command_sep) 判断消息是否为命令。
|
||||
|
||||
可以通过 [Command](./params.md#Command) 获取匹配成功的命令(例: `("test",)`),
|
||||
通过 [RawCommand](./params.md#RawCommand) 获取匹配成功的原始命令文本(例: `"/test"`),
|
||||
通过 [ShellCommandArgv](./params.md#ShellCommandArgv) 获取解析前的参数列表(例: `["arg", "-h"]`),
|
||||
通过 [ShellCommandArgs](./params.md#ShellCommandArgs) 获取解析后的参数字典(例: `{"arg": "arg", "h": True}`)。
|
||||
|
||||
:::warning 警告
|
||||
如果参数解析失败,则通过 [ShellCommandArgs](./params.md#ShellCommandArgs)
|
||||
获取的将是 [ParserExit](./exception.md#ParserExit) 异常。
|
||||
:::
|
||||
|
||||
- **参数**
|
||||
|
||||
- `*cmds` (str | tuple[str, ...]): 命令文本或命令元组
|
||||
|
||||
- `parser` ([ArgumentParser](#ArgumentParser) | None): [ArgumentParser](#ArgumentParser) 对象
|
||||
|
||||
- **返回**
|
||||
|
||||
- nonebot.internal.rule.Rule
|
||||
|
||||
- **用法**
|
||||
|
||||
使用默认 `command_start`, `command_sep` 配置,更多示例参考 `argparse` 标准库文档。
|
||||
|
||||
```python
|
||||
from nonebot.rule import ArgumentParser
|
||||
|
||||
parser = ArgumentParser()
|
||||
parser.add_argument("-a", action="store_true")
|
||||
|
||||
rule = shell_command("ls", parser=parser)
|
||||
```
|
||||
|
||||
:::tip 提示
|
||||
命令内容与后续消息间无需空格!
|
||||
:::
|
||||
|
||||
## _class_ `RegexRule(regex, flags=0)` {#RegexRule}
|
||||
|
||||
- **说明**
|
||||
|
||||
检查消息字符串是否符合指定正则表达式。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `regex` (str): 正则表达式
|
||||
|
||||
- `flags` (int): 正则表达式标记
|
||||
|
||||
## _def_ `regex(regex, flags=0)` {#regex}
|
||||
|
||||
- **说明**
|
||||
|
||||
匹配符合正则表达式的消息字符串。
|
||||
|
||||
可以通过 [RegexStr](./params.md#RegexStr) 获取匹配成功的字符串,
|
||||
通过 [RegexGroup](./params.md#RegexGroup) 获取匹配成功的 group 元组,
|
||||
通过 [RegexDict](./params.md#RegexDict) 获取匹配成功的 group 字典。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `regex` (str): 正则表达式
|
||||
|
||||
flags: 正则表达式标记
|
||||
|
||||
:::tip 提示
|
||||
正则表达式匹配使用 search 而非 match,如需从头匹配请使用 `r"^xxx"` 来确保匹配开头
|
||||
:::
|
||||
|
||||
:::tip 提示
|
||||
正则表达式匹配使用 `EventMessage` 的 `str` 字符串,而非 `EventMessage` 的 `PlainText` 纯文本字符串
|
||||
:::
|
||||
|
||||
- `flags` (int | re.RegexFlag)
|
||||
|
||||
- **返回**
|
||||
|
||||
- nonebot.internal.rule.Rule
|
||||
|
||||
## _class_ `ToMeRule()` {#ToMeRule}
|
||||
|
||||
- **说明**
|
||||
|
||||
检查事件是否与机器人有关。
|
||||
|
||||
## _def_ `to_me()` {#to_me}
|
||||
|
||||
- **说明**
|
||||
|
||||
匹配与机器人有关的事件。
|
||||
|
||||
- **返回**
|
||||
|
||||
- nonebot.internal.rule.Rule
|
||||
|
||||
## _class_ `IsTypeRule(*types)` {#IsTypeRule}
|
||||
|
||||
- **说明**
|
||||
|
||||
检查事件类型是否为指定类型。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `*types` (Type[nonebot.internal.adapter.event.Event])
|
||||
|
||||
## _def_ `is_type(*types)` {#is_type}
|
||||
|
||||
- **说明**
|
||||
|
||||
匹配事件类型。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `*types` (Type[nonebot.internal.adapter.event.Event]): 事件类型
|
||||
|
||||
- **返回**
|
||||
|
||||
- nonebot.internal.rule.Rule
|
219
website/versioned_docs/version-2.0.0rc3/api/typing.md
Normal file
219
website/versioned_docs/version-2.0.0rc3/api/typing.md
Normal file
@ -0,0 +1,219 @@
|
||||
---
|
||||
sidebar_position: 11
|
||||
description: nonebot.typing 模块
|
||||
---
|
||||
|
||||
# nonebot.typing
|
||||
|
||||
本模块定义了 NoneBot 模块中共享的一些类型。
|
||||
|
||||
下面的文档中,「类型」部分使用 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 内置类型的别名。
|
||||
|
||||
## _var_ `T_State` {#T_State}
|
||||
|
||||
- **类型:** dict[Any, Any]
|
||||
|
||||
- **说明:** 事件处理状态 State 类型
|
||||
|
||||
## _var_ `T_BotConnectionHook` {#T_BotConnectionHook}
|
||||
|
||||
- **类型:** (*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any]
|
||||
|
||||
- **说明**
|
||||
|
||||
Bot 连接建立时钩子函数
|
||||
|
||||
依赖参数:
|
||||
|
||||
- DependParam: 子依赖参数
|
||||
- BotParam: Bot 对象
|
||||
- DefaultParam: 带有默认值的参数
|
||||
|
||||
## _var_ `T_BotDisconnectionHook` {#T_BotDisconnectionHook}
|
||||
|
||||
- **类型:** (*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any]
|
||||
|
||||
- **说明**
|
||||
|
||||
Bot 连接断开时钩子函数
|
||||
|
||||
依赖参数:
|
||||
|
||||
- DependParam: 子依赖参数
|
||||
- BotParam: Bot 对象
|
||||
- DefaultParam: 带有默认值的参数
|
||||
|
||||
## _var_ `T_CallingAPIHook` {#T_CallingAPIHook}
|
||||
|
||||
- **类型:** (Bot, str, dict[str, Any]) -> Awaitable[Any]
|
||||
|
||||
- **说明:** `bot.call_api` 钩子函数
|
||||
|
||||
## _var_ `T_CalledAPIHook` {#T_CalledAPIHook}
|
||||
|
||||
- **类型:** (Bot, Exception | None, str, dict[str, Any], Any) -> Awaitable[Any]
|
||||
|
||||
- **说明:** `bot.call_api` 后执行的函数,参数分别为 bot, exception, api, data, result
|
||||
|
||||
## _var_ `T_EventPreProcessor` {#T_EventPreProcessor}
|
||||
|
||||
- **类型:** (*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any]
|
||||
|
||||
- **说明**
|
||||
|
||||
事件预处理函数 EventPreProcessor 类型
|
||||
|
||||
依赖参数:
|
||||
|
||||
- DependParam: 子依赖参数
|
||||
- BotParam: Bot 对象
|
||||
- EventParam: Event 对象
|
||||
- StateParam: State 对象
|
||||
- DefaultParam: 带有默认值的参数
|
||||
|
||||
## _var_ `T_EventPostProcessor` {#T_EventPostProcessor}
|
||||
|
||||
- **类型:** (*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any]
|
||||
|
||||
- **说明**
|
||||
|
||||
事件预处理函数 EventPostProcessor 类型
|
||||
|
||||
依赖参数:
|
||||
|
||||
- DependParam: 子依赖参数
|
||||
- BotParam: Bot 对象
|
||||
- EventParam: Event 对象
|
||||
- StateParam: State 对象
|
||||
- DefaultParam: 带有默认值的参数
|
||||
|
||||
## _var_ `T_RunPreProcessor` {#T_RunPreProcessor}
|
||||
|
||||
- **类型:** (*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any]
|
||||
|
||||
- **说明**
|
||||
|
||||
事件响应器运行前预处理函数 RunPreProcessor 类型
|
||||
|
||||
依赖参数:
|
||||
|
||||
- DependParam: 子依赖参数
|
||||
- BotParam: Bot 对象
|
||||
- EventParam: Event 对象
|
||||
- StateParam: State 对象
|
||||
- MatcherParam: Matcher 对象
|
||||
- DefaultParam: 带有默认值的参数
|
||||
|
||||
## _var_ `T_RunPostProcessor` {#T_RunPostProcessor}
|
||||
|
||||
- **类型:** (*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any]
|
||||
|
||||
- **说明**
|
||||
|
||||
事件响应器运行后后处理函数 RunPostProcessor 类型
|
||||
|
||||
依赖参数:
|
||||
|
||||
- DependParam: 子依赖参数
|
||||
- BotParam: Bot 对象
|
||||
- EventParam: Event 对象
|
||||
- StateParam: State 对象
|
||||
- MatcherParam: Matcher 对象
|
||||
- ExceptionParam: 异常对象(可能为 None)
|
||||
- DefaultParam: 带有默认值的参数
|
||||
|
||||
## _var_ `T_RuleChecker` {#T_RuleChecker}
|
||||
|
||||
- **类型:** (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool]
|
||||
|
||||
- **说明**
|
||||
|
||||
RuleChecker 即判断是否响应事件的处理函数。
|
||||
|
||||
依赖参数:
|
||||
|
||||
- DependParam: 子依赖参数
|
||||
- BotParam: Bot 对象
|
||||
- EventParam: Event 对象
|
||||
- StateParam: State 对象
|
||||
- DefaultParam: 带有默认值的参数
|
||||
|
||||
## _var_ `T_PermissionChecker` {#T_PermissionChecker}
|
||||
|
||||
- **类型:** (*Any, \*\*Any) -> bool | (*Any, \*\*Any) -> Awaitable[bool]
|
||||
|
||||
- **说明**
|
||||
|
||||
PermissionChecker 即判断事件是否满足权限的处理函数。
|
||||
|
||||
依赖参数:
|
||||
|
||||
- DependParam: 子依赖参数
|
||||
- BotParam: Bot 对象
|
||||
- EventParam: Event 对象
|
||||
- DefaultParam: 带有默认值的参数
|
||||
|
||||
## _var_ `T_Handler` {#T_Handler}
|
||||
|
||||
- **类型:** (*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any]
|
||||
|
||||
- **说明:** Handler 处理函数。
|
||||
|
||||
## _var_ `T_TypeUpdater` {#T_TypeUpdater}
|
||||
|
||||
- **类型:** (*Any, \*\*Any) -> str | (*Any, \*\*Any) -> Awaitable[str]
|
||||
|
||||
- **说明**
|
||||
|
||||
TypeUpdater 在 Matcher.pause, Matcher.reject 时被运行,用于更新响应的事件类型。默认会更新为 `message`。
|
||||
|
||||
依赖参数:
|
||||
|
||||
- DependParam: 子依赖参数
|
||||
- BotParam: Bot 对象
|
||||
- EventParam: Event 对象
|
||||
- StateParam: State 对象
|
||||
- MatcherParam: Matcher 对象
|
||||
- DefaultParam: 带有默认值的参数
|
||||
|
||||
## _var_ `T_PermissionUpdater` {#T_PermissionUpdater}
|
||||
|
||||
- **类型:** (*Any, \*\*Any) -> Permission | (*Any, \*\*Any) -> Awaitable[Permission]
|
||||
|
||||
- **说明**
|
||||
|
||||
PermissionUpdater 在 Matcher.pause, Matcher.reject 时被运行,用于更新会话对象权限。默认会更新为当前事件的触发对象。
|
||||
|
||||
依赖参数:
|
||||
|
||||
- DependParam: 子依赖参数
|
||||
- BotParam: Bot 对象
|
||||
- EventParam: Event 对象
|
||||
- StateParam: State 对象
|
||||
- MatcherParam: Matcher 对象
|
||||
- DefaultParam: 带有默认值的参数
|
||||
|
||||
## _var_ `T_DependencyCache` {#T_DependencyCache}
|
||||
|
||||
- **类型:** dict[(*Any, \*\*Any) -> Any | (*Any, \*\*Any) -> Awaitable[Any], Task[Any]]
|
||||
|
||||
- **说明:** 依赖缓存, 用于存储依赖函数的返回值
|
||||
|
||||
## _def_ `overrides(InterfaceClass)` {#overrides}
|
||||
|
||||
- **说明**
|
||||
|
||||
标记一个方法为父类 interface 的 implement
|
||||
|
||||
- **参数**
|
||||
|
||||
- `InterfaceClass` (object)
|
||||
|
||||
- **返回**
|
||||
|
||||
- ((~ T_Wrapped)) -> (~ T_Wrapped)
|
217
website/versioned_docs/version-2.0.0rc3/api/utils.md
Normal file
217
website/versioned_docs/version-2.0.0rc3/api/utils.md
Normal file
@ -0,0 +1,217 @@
|
||||
---
|
||||
sidebar_position: 8
|
||||
description: nonebot.utils 模块
|
||||
---
|
||||
|
||||
# nonebot.utils
|
||||
|
||||
本模块包含了 NoneBot 的一些工具函数
|
||||
|
||||
## _def_ `escape_tag(s)` {#escape_tag}
|
||||
|
||||
- **说明**
|
||||
|
||||
用于记录带颜色日志时转义 `<tag>` 类型特殊标签
|
||||
|
||||
参考: [loguru color 标签](https://loguru.readthedocs.io/en/stable/api/logger.html#color)
|
||||
|
||||
- **参数**
|
||||
|
||||
- `s` (str): 需要转义的字符串
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
## _def_ `generic_check_issubclass(cls, class_or_tuple)` {#generic_check_issubclass}
|
||||
|
||||
- **说明**
|
||||
|
||||
检查 cls 是否是 class_or_tuple 中的一个类型子类。
|
||||
|
||||
特别的,如果 cls 是 `typing.Union` 或 `types.UnionType` 类型,
|
||||
则会检查其中的类型是否是 class_or_tuple 中的一个类型子类。(None 会被忽略)
|
||||
|
||||
- **参数**
|
||||
|
||||
- `class_or_tuple` (Type[Any] | tuple[Type[Any], ...])
|
||||
|
||||
- **返回**
|
||||
|
||||
- bool
|
||||
|
||||
## _def_ `is_coroutine_callable(call)` {#is_coroutine_callable}
|
||||
|
||||
- **说明**
|
||||
|
||||
检查 call 是否是一个 callable 协程函数
|
||||
|
||||
- **参数**
|
||||
|
||||
- `call` ((\*Any, \*\*Any) -> Any)
|
||||
|
||||
- **返回**
|
||||
|
||||
- bool
|
||||
|
||||
## _def_ `is_gen_callable(call)` {#is_gen_callable}
|
||||
|
||||
- **说明**
|
||||
|
||||
检查 call 是否是一个生成器函数
|
||||
|
||||
- **参数**
|
||||
|
||||
- `call` ((\*Any, \*\*Any) -> Any)
|
||||
|
||||
- **返回**
|
||||
|
||||
- bool
|
||||
|
||||
## _def_ `is_async_gen_callable(call)` {#is_async_gen_callable}
|
||||
|
||||
- **说明**
|
||||
|
||||
检查 call 是否是一个异步生成器函数
|
||||
|
||||
- **参数**
|
||||
|
||||
- `call` ((\*Any, \*\*Any) -> Any)
|
||||
|
||||
- **返回**
|
||||
|
||||
- bool
|
||||
|
||||
## _def_ `run_sync(call)` {#run_sync}
|
||||
|
||||
- **说明**
|
||||
|
||||
一个用于包装 sync function 为 async function 的装饰器
|
||||
|
||||
- **参数**
|
||||
|
||||
- `call` (((~ P)) -> (~ R)): 被装饰的同步函数
|
||||
|
||||
- **返回**
|
||||
|
||||
- ((~ P)) -> Coroutine[NoneType, NoneType, (~ R)]
|
||||
|
||||
## _def_ `run_sync_ctx_manager(cm)` {#run_sync_ctx_manager}
|
||||
|
||||
- **说明**
|
||||
|
||||
一个用于包装 sync context manager 为 async context manager 的执行函数
|
||||
|
||||
- **参数**
|
||||
|
||||
- `cm` (ContextManager[(~ T)])
|
||||
|
||||
- **返回**
|
||||
|
||||
- AsyncGenerator[(~ T), NoneType]
|
||||
|
||||
## _async def_ `run_coro_with_catch(coro, exc, return_on_err=None)` {#run_coro_with_catch}
|
||||
|
||||
- **重载**
|
||||
|
||||
**1.** `(coro, exc)`
|
||||
|
||||
- **参数**
|
||||
|
||||
- `coro` (Coroutine[Any, Any, (~ T)])
|
||||
|
||||
- `exc` (tuple[Type[Exception], ...])
|
||||
|
||||
- **返回**
|
||||
|
||||
- (~ T) | None
|
||||
|
||||
**2.** `(coro, exc, return_on_err)`
|
||||
|
||||
- **参数**
|
||||
|
||||
- `coro` (Coroutine[Any, Any, (~ T)])
|
||||
|
||||
- `exc` (tuple[Type[Exception], ...])
|
||||
|
||||
- `return_on_err` ((~ R))
|
||||
|
||||
- **返回**
|
||||
|
||||
- (~ T) | (~ R)
|
||||
|
||||
## _def_ `get_name(obj)` {#get_name}
|
||||
|
||||
- **说明**
|
||||
|
||||
获取对象的名称
|
||||
|
||||
- **参数**
|
||||
|
||||
- `obj` (Any)
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
## _def_ `path_to_module_name(path)` {#path_to_module_name}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `path` (pathlib.Path)
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
## _class_ `DataclassEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)` {#DataclassEncoder}
|
||||
|
||||
- **说明**
|
||||
|
||||
在 JSON 序列化 {re}`nonebot.adapters._message.Message` (List[Dataclass]) 时使用的 `JSONEncoder`
|
||||
|
||||
- **参数**
|
||||
|
||||
- `skipkeys`
|
||||
|
||||
- `ensure_ascii`
|
||||
|
||||
- `check_circular`
|
||||
|
||||
- `allow_nan`
|
||||
|
||||
- `sort_keys`
|
||||
|
||||
- `indent`
|
||||
|
||||
- `separators`
|
||||
|
||||
- `default`
|
||||
|
||||
### _method_ `default(self, o)` {#DataclassEncoder-default}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `o`
|
||||
|
||||
- **返回**
|
||||
|
||||
- Unknown
|
||||
|
||||
## _def_ `logger_wrapper(logger_name)` {#logger_wrapper}
|
||||
|
||||
- **说明**
|
||||
|
||||
用于打印 adapter 的日志。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `logger_name` (str): adapter 的名称
|
||||
|
||||
- **返回**
|
||||
|
||||
- Unknown: 日志记录函数
|
||||
|
||||
- level: 日志等级
|
||||
- message: 日志信息
|
||||
- exception: 异常信息
|
Reference in New Issue
Block a user