diff --git a/docs/api/matcher.md b/docs/api/matcher.md index 9282e698..28e4cbe4 100644 --- a/docs/api/matcher.md +++ b/docs/api/matcher.md @@ -292,7 +292,7 @@ sidebarDepth: 0 -### _classmethod_ `new(type_='', rule=None, permission=None, handlers=None, temp=False, priority=1, block=False, *, module=None, default_state=None, default_state_factory=None, expire_time=None)` +### _classmethod_ `new(type_='', rule=None, permission=None, handlers=None, temp=False, priority=1, block=False, *, module=None, expire_time=None, default_state=None, default_state_factory=None, default_parser=None, default_type_updater=None, default_permission_updater=None)` * **说明** diff --git a/docs/api/permission.md b/docs/api/permission.md index 1c42b2c8..fef1b4d2 100644 --- a/docs/api/permission.md +++ b/docs/api/permission.md @@ -14,6 +14,80 @@ sidebarDepth: 0 ::: +## _class_ `Permission` + +基类:`object` + + +* **说明** + + `Matcher` 规则类,当事件传递时,在 `Matcher` 运行前进行检查。 + + + +* **示例** + + +```python +Permission(async_function) | sync_function +# 等价于 +from nonebot.utils import run_sync +Permission(async_function, run_sync(sync_function)) +``` + + +### `__init__(*checkers)` + + +* **参数** + + + * `*checkers: Callable[[Bot, Event], Awaitable[bool]]`: **异步** PermissionChecker + + + +### `checkers` + + +* **说明** + + 存储 `PermissionChecker` + + + +* **类型** + + + * `Set[Callable[[Bot, Event], Awaitable[bool]]]` + + + +### _async_ `__call__(bot, event)` + + +* **说明** + + 检查是否满足某个权限 + + + +* **参数** + + + * `bot: Bot`: Bot 对象 + + + * `event: Event`: Event 对象 + + + +* **返回** + + + * `bool` + + + ## `MESSAGE` diff --git a/docs_build/permission.rst b/docs_build/permission.rst index 783a65f5..0dde5fa8 100644 --- a/docs_build/permission.rst +++ b/docs_build/permission.rst @@ -9,3 +9,4 @@ NoneBot.permission 模块 .. automodule:: nonebot.permission :members: :show-inheritance: + :special-members: diff --git a/nonebot/permission.py b/nonebot/permission.py index 55e9f16b..de6c6475 100644 --- a/nonebot/permission.py +++ b/nonebot/permission.py @@ -20,6 +20,20 @@ if TYPE_CHECKING: class Permission: + """ + :说明: + + ``Matcher`` 规则类,当事件传递时,在 ``Matcher`` 运行前进行检查。 + + :示例: + + .. code-block:: python + + Permission(async_function) | sync_function + # 等价于 + from nonebot.utils import run_sync + Permission(async_function, run_sync(sync_function)) + """ __slots__ = ("checkers",) def __init__(