mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-09-07 12:36:47 +00:00
💡 update docstring for several modules
This commit is contained in:
@ -4,10 +4,10 @@
|
||||
规则
|
||||
====
|
||||
|
||||
每个 ``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
|
||||
\:\:\:
|
||||
"""
|
||||
|
||||
@ -185,6 +185,12 @@ def endswith(msg: str) -> Rule:
|
||||
|
||||
|
||||
def keyword(msg: str) -> Rule:
|
||||
"""
|
||||
:说明:
|
||||
匹配消息关键词
|
||||
:参数:
|
||||
* ``msg: str``: 关键词
|
||||
"""
|
||||
|
||||
async def _keyword(bot: Bot, event: Event, state: dict) -> bool:
|
||||
return bool(event.plain_text and msg in event.plain_text)
|
||||
@ -193,6 +199,22 @@ def keyword(msg: str) -> Rule:
|
||||
|
||||
|
||||
def command(command: Tuple[str, ...]) -> Rule:
|
||||
"""
|
||||
:说明:
|
||||
命令形式匹配,根据配置里提供的 ``command_start``, ``command_sep`` 判断消息是否为命令。
|
||||
:参数:
|
||||
* ``command: Tuples[str, ...]``: 命令内容
|
||||
:示例:
|
||||
使用默认 ``command_start``, ``command_sep`` 配置
|
||||
|
||||
命令 ``("test",)`` 可以匹配:``/test`` 开头的消息
|
||||
命令 ``("test", "sub")`` 可以匹配”``/test.sub`` 开头的消息
|
||||
|
||||
\:\:\:tip 提示
|
||||
命令内容与后续消息间无需空格!
|
||||
\:\:\:
|
||||
"""
|
||||
|
||||
config = get_driver().config
|
||||
command_start = config.command_start
|
||||
command_sep = config.command_sep
|
||||
@ -210,6 +232,14 @@ def command(command: Tuple[str, ...]) -> Rule:
|
||||
|
||||
|
||||
def regex(regex: str, flags: Union[int, re.RegexFlag] = 0) -> Rule:
|
||||
"""
|
||||
:说明:
|
||||
根据正则表达式进行匹配
|
||||
:参数:
|
||||
* ``regex: str``: 正则表达式
|
||||
* ``flags: Union[int, re.RegexFlag]``: 正则标志
|
||||
"""
|
||||
|
||||
pattern = re.compile(regex, flags)
|
||||
|
||||
async def _regex(bot: Bot, event: Event, state: dict) -> bool:
|
||||
@ -219,6 +249,12 @@ def regex(regex: str, flags: Union[int, re.RegexFlag] = 0) -> Rule:
|
||||
|
||||
|
||||
def to_me() -> Rule:
|
||||
"""
|
||||
:说明:
|
||||
通过 ``event.to_me`` 判断消息是否是发送给机器人
|
||||
:参数:
|
||||
* 无
|
||||
"""
|
||||
|
||||
async def _to_me(bot: Bot, event: Event, state: dict) -> bool:
|
||||
return bool(event.to_me)
|
||||
|
Reference in New Issue
Block a user