mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-07-28 08:41:29 +00:00
💡 update docstring for several modules
This commit is contained in:
@ -88,21 +88,13 @@ module.exports = context => ({
|
||||
title: "nonebot 模块",
|
||||
path: "nonebot"
|
||||
},
|
||||
{
|
||||
title: "nonebot.typing 模块",
|
||||
path: "typing"
|
||||
},
|
||||
{
|
||||
title: "nonebot.config 模块",
|
||||
path: "config"
|
||||
},
|
||||
{
|
||||
title: "nonebot.sched 模块",
|
||||
path: "sched"
|
||||
},
|
||||
{
|
||||
title: "nonebot.log 模块",
|
||||
path: "log"
|
||||
title: "nonebot.matcher 模块",
|
||||
path: "matcher"
|
||||
},
|
||||
{
|
||||
title: "nonebot.rule 模块",
|
||||
@ -112,10 +104,22 @@ module.exports = context => ({
|
||||
title: "nonebot.permission 模块",
|
||||
path: "permission"
|
||||
},
|
||||
{
|
||||
title: "nonebot.sched 模块",
|
||||
path: "sched"
|
||||
},
|
||||
{
|
||||
title: "nonebot.log 模块",
|
||||
path: "log"
|
||||
},
|
||||
{
|
||||
title: "nonebot.utils 模块",
|
||||
path: "utils"
|
||||
},
|
||||
{
|
||||
title: "nonebot.typing 模块",
|
||||
path: "typing"
|
||||
},
|
||||
{
|
||||
title: "nonebot.exception 模块",
|
||||
path: "exception"
|
||||
|
@ -7,16 +7,10 @@
|
||||
* [nonebot](nonebot.html)
|
||||
|
||||
|
||||
* [nonebot.typing](typing.html)
|
||||
|
||||
|
||||
* [nonebot.config](config.html)
|
||||
|
||||
|
||||
* [nonebot.sched](sched.html)
|
||||
|
||||
|
||||
* [nonebot.log](log.html)
|
||||
* [nonebot.matcher](matcher.html)
|
||||
|
||||
|
||||
* [nonebot.rule](rule.html)
|
||||
@ -25,10 +19,22 @@
|
||||
* [nonebot.permission](permission.html)
|
||||
|
||||
|
||||
* [nonebot.sched](sched.html)
|
||||
|
||||
|
||||
* [nonebot.log](log.html)
|
||||
|
||||
|
||||
* [nonebot.utils](utils.html)
|
||||
|
||||
|
||||
* [nonebot.typing](typing.html)
|
||||
|
||||
|
||||
* [nonebot.exception](exception.html)
|
||||
|
||||
|
||||
* [nonebot.adapters](adapters/)
|
||||
|
||||
|
||||
* [nonebot.adapters.cqhttp](adapters/cqhttp.html)
|
||||
|
@ -323,10 +323,10 @@ CQHTTP 协议 Event 适配。继承属性参考 [BaseEvent](./#class-baseevent)
|
||||
### _property_ `sub_type`
|
||||
|
||||
|
||||
* 类型: `str`
|
||||
* 类型: `Optional[str]`
|
||||
|
||||
|
||||
* 说明: 事件类型
|
||||
* 说明: 事件子类型
|
||||
|
||||
|
||||
### _property_ `user_id`
|
||||
|
328
docs/api/matcher.md
Normal file
328
docs/api/matcher.md
Normal file
@ -0,0 +1,328 @@
|
||||
---
|
||||
contentSidebar: true
|
||||
sidebarDepth: 0
|
||||
---
|
||||
|
||||
# NoneBot.matcher 模块
|
||||
|
||||
## 事件响应器
|
||||
|
||||
该模块实现事件响应器的创建与运行,并提供一些快捷方法来帮助用户更好的与机器人进行 对话 。
|
||||
|
||||
|
||||
## `matchers`
|
||||
|
||||
|
||||
* **类型**
|
||||
|
||||
`Dict[int, List[Type[Matcher]]]`
|
||||
|
||||
|
||||
|
||||
* **说明**
|
||||
|
||||
用于存储当前所有的事件响应器
|
||||
|
||||
|
||||
|
||||
## _class_ `Matcher`
|
||||
|
||||
基类:`object`
|
||||
|
||||
事件响应器类
|
||||
|
||||
|
||||
### `module`
|
||||
|
||||
|
||||
* **类型**
|
||||
|
||||
`Optional[str]`
|
||||
|
||||
|
||||
|
||||
* **说明**
|
||||
|
||||
事件响应器所在模块名称
|
||||
|
||||
|
||||
|
||||
### `type`
|
||||
|
||||
|
||||
* **类型**
|
||||
|
||||
`str`
|
||||
|
||||
|
||||
|
||||
* **说明**
|
||||
|
||||
事件响应器类型
|
||||
|
||||
|
||||
|
||||
### `rule`
|
||||
|
||||
|
||||
* **类型**
|
||||
|
||||
`Rule`
|
||||
|
||||
|
||||
|
||||
* **说明**
|
||||
|
||||
事件响应器匹配规则
|
||||
|
||||
|
||||
|
||||
### `permission`
|
||||
|
||||
|
||||
* **类型**
|
||||
|
||||
`Permission`
|
||||
|
||||
|
||||
|
||||
* **说明**
|
||||
|
||||
事件响应器触发权限
|
||||
|
||||
|
||||
|
||||
### `priority`
|
||||
|
||||
|
||||
* **类型**
|
||||
|
||||
`int`
|
||||
|
||||
|
||||
|
||||
* **说明**
|
||||
|
||||
事件响应器优先级
|
||||
|
||||
|
||||
|
||||
### `block`
|
||||
|
||||
|
||||
* **类型**
|
||||
|
||||
`bool`
|
||||
|
||||
|
||||
|
||||
* **说明**
|
||||
|
||||
事件响应器是否阻止事件传播
|
||||
|
||||
|
||||
|
||||
### `temp`
|
||||
|
||||
|
||||
* **类型**
|
||||
|
||||
`bool`
|
||||
|
||||
|
||||
|
||||
* **说明**
|
||||
|
||||
事件响应器是否为临时
|
||||
|
||||
|
||||
|
||||
### `expire_time`
|
||||
|
||||
|
||||
* **类型**
|
||||
|
||||
`Optional[datetime]`
|
||||
|
||||
|
||||
|
||||
* **说明**
|
||||
|
||||
事件响应器过期时间点
|
||||
|
||||
|
||||
|
||||
### `_default_state`
|
||||
|
||||
|
||||
* **类型**
|
||||
|
||||
`dict`
|
||||
|
||||
|
||||
|
||||
* **说明**
|
||||
|
||||
事件响应器默认状态
|
||||
|
||||
|
||||
|
||||
### `_default_parser`
|
||||
|
||||
|
||||
* **类型**
|
||||
|
||||
`Optional[ArgsParser]`
|
||||
|
||||
|
||||
|
||||
* **说明**
|
||||
|
||||
事件响应器默认参数解析函数
|
||||
|
||||
|
||||
|
||||
### `handlers`
|
||||
|
||||
|
||||
* **类型**
|
||||
|
||||
`List[Handler]`
|
||||
|
||||
|
||||
|
||||
* **说明**
|
||||
|
||||
事件响应器拥有的事件处理函数列表
|
||||
|
||||
|
||||
|
||||
### _classmethod_ `new(type_='', rule=None, permission=None, handlers=None, temp=False, priority=1, block=False, *, module=None, default_state=None, expire_time=None)`
|
||||
|
||||
|
||||
* **说明**
|
||||
|
||||
创建一个新的事件响应器,并存储至 [matchers](#matchers)
|
||||
|
||||
|
||||
|
||||
* **参数**
|
||||
|
||||
|
||||
* `type_: str`: 事件响应器类型,与 `event.type` 一致时触发,空字符串表示任意
|
||||
|
||||
|
||||
* `rule: Optional[Rule]`: 匹配规则
|
||||
|
||||
|
||||
* `permission: Optional[Permission]`: 权限
|
||||
|
||||
|
||||
* `handlers: Optional[List[Handler]]`: 事件处理函数列表
|
||||
|
||||
|
||||
* `temp: bool`: 是否为临时事件响应器,即触发一次后删除
|
||||
|
||||
|
||||
* `priority: int`: 响应优先级
|
||||
|
||||
|
||||
* `block: bool`: 是否阻止事件向更低优先级的响应器传播
|
||||
|
||||
|
||||
* `module: Optional[str]`: 事件响应器所在模块名称
|
||||
|
||||
|
||||
* `default_state: Optional[dict]`: 默认状态 `state`
|
||||
|
||||
|
||||
* `expire_time: Optional[datetime]`: 事件响应器最终有效时间点,过时即被删除
|
||||
|
||||
|
||||
|
||||
* **返回**
|
||||
|
||||
|
||||
* `Type[Matcher]`: 新的事件响应器类
|
||||
|
||||
|
||||
|
||||
### _async classmethod_ `check_perm(bot, event)`
|
||||
|
||||
|
||||
* **说明**
|
||||
|
||||
检查是否满足触发权限
|
||||
|
||||
|
||||
|
||||
* **参数**
|
||||
|
||||
|
||||
* `bot: Bot`: Bot 对象
|
||||
|
||||
|
||||
* `event: Event`: 上报事件
|
||||
|
||||
|
||||
|
||||
* **返回**
|
||||
|
||||
|
||||
* `bool`: 是否满足权限
|
||||
|
||||
|
||||
|
||||
### _async classmethod_ `check_rule(bot, event, state)`
|
||||
|
||||
|
||||
* **说明**
|
||||
|
||||
检查是否满足匹配规则
|
||||
|
||||
|
||||
|
||||
* **参数**
|
||||
|
||||
|
||||
* `bot: Bot`: Bot 对象
|
||||
|
||||
|
||||
* `event: Event`: 上报事件
|
||||
|
||||
|
||||
* `state: dict`: 当前状态
|
||||
|
||||
|
||||
|
||||
* **返回**
|
||||
|
||||
|
||||
* `bool`: 是否满足匹配规则
|
||||
|
||||
|
||||
|
||||
### _classmethod_ `args_parser(func)`
|
||||
|
||||
|
||||
* **说明**
|
||||
|
||||
用于装饰一个函数来更改当前事件响应器的默认参数解析函数
|
||||
|
||||
|
||||
|
||||
* **参数**
|
||||
|
||||
|
||||
* `func: ArgsParser`: 参数解析函数
|
||||
|
||||
|
||||
|
||||
### _classmethod_ `handle()`
|
||||
|
||||
直接处理消息事件
|
||||
|
||||
|
||||
### _classmethod_ `receive()`
|
||||
|
||||
接收一条新消息并处理
|
@ -7,10 +7,10 @@ sidebarDepth: 0
|
||||
|
||||
## 规则
|
||||
|
||||
每个 `Matcher` 拥有一个 `Rule` ,其中是 **异步** `RuleChecker` 的集合,只有当所有 `RuleChecker` 检查结果为 `True` 时继续运行。
|
||||
每个事件响应器 `Matcher` 拥有一个匹配规则 `Rule` ,其中是 **异步** `RuleChecker` 的集合,只有当所有 `RuleChecker` 检查结果为 `True` 时继续运行。
|
||||
|
||||
:::tip 提示
|
||||
`RuleChecker` 既可以是 async function 也可以是 sync function
|
||||
`RuleChecker` 既可以是 async function 也可以是 sync function,但在最终会被 `nonebot.utils.run_sync` 转换为 async function
|
||||
:::
|
||||
|
||||
|
||||
@ -120,3 +120,83 @@ Rule(async_function, run_sync(sync_function))
|
||||
|
||||
|
||||
* `msg: str`: 消息结尾字符串
|
||||
|
||||
|
||||
|
||||
## `keyword(msg)`
|
||||
|
||||
|
||||
* **说明**
|
||||
|
||||
匹配消息关键词
|
||||
|
||||
|
||||
|
||||
* **参数**
|
||||
|
||||
|
||||
* `msg: str`: 关键词
|
||||
|
||||
|
||||
|
||||
## `command(command)`
|
||||
|
||||
|
||||
* **说明**
|
||||
|
||||
命令形式匹配,根据配置里提供的 `command_start`, `command_sep` 判断消息是否为命令。
|
||||
|
||||
|
||||
|
||||
* **参数**
|
||||
|
||||
|
||||
* `command: Tuples[str, ...]`: 命令内容
|
||||
|
||||
|
||||
|
||||
* **示例**
|
||||
|
||||
使用默认 `command_start`, `command_sep` 配置
|
||||
|
||||
命令 `("test",)` 可以匹配:`/test` 开头的消息
|
||||
命令 `("test", "sub")` 可以匹配”`/test.sub` 开头的消息
|
||||
|
||||
|
||||
:::tip 提示
|
||||
命令内容与后续消息间无需空格!
|
||||
:::
|
||||
|
||||
|
||||
## `regex(regex, flags=0)`
|
||||
|
||||
|
||||
* **说明**
|
||||
|
||||
根据正则表达式进行匹配
|
||||
|
||||
|
||||
|
||||
* **参数**
|
||||
|
||||
|
||||
* `regex: str`: 正则表达式
|
||||
|
||||
|
||||
* `flags: Union[int, re.RegexFlag]`: 正则标志
|
||||
|
||||
|
||||
|
||||
## `to_me()`
|
||||
|
||||
|
||||
* **说明**
|
||||
|
||||
通过 `event.to_me` 判断消息是否是发送给机器人
|
||||
|
||||
|
||||
|
||||
* **参数**
|
||||
|
||||
|
||||
* 无
|
||||
|
Reference in New Issue
Block a user