Skip to main content

Permission Plugin based on Arclet Cithun

Project description

nonebot

nonebot-plugin-permission

Nonebot2 通用权限插件 ✨

license Python NoneBot pypi

本插件基于 arclet-cithun, 提供了一套通用的权限管理系统

安装

  • 使用 nb-cli
nb plugin install nonebot-plugin-permission
  • 使用 pip
pip install nonebot-plugin-permission

使用

设置 Matcher 级别的权限

from nonebot import on_command
from nonebot_plugin_permission import require_permission

matcher = on_command("test", rule=require_permission("command.test"))

设置 Handler 级别的权限

from nonebot import on_command
from nonebot_plugin_permission import depends_permission

matcher = on_command("test")

@matcher.handle(parameterless=depends_permission("command.test"))
async def handle():
    ...

依赖注入权限所有者模型

from nonebot import on_command
from nonebot_plugin_permission import UserOwner

matcher = on_command("test")

@matcher.handle()
async def handle(owner: UserOwner):
    # owner 表示当前用户所代表的权限所有者
    ...

查看具体权限

from nonebot import on_command
from nonebot_plugin_permission import UserOwner, Permission, system

matcher = on_command("test")

@matcher.handle()
async def handle(owner: UserOwner):
    state: Permission = await system.get(owner, "command.test")

通过指令设置权限

permission [@user] set <permission> <state>

通过代码设置权限

from nonebot_plugin_permission import Permission, system

@matcher.handle()
async def _():
    owner = await system.get_or_create_user("xxx")
    # 设置权限
    await system.suset(owner, "command.test", Permission("vma"))
    # 取消权限
    await system.suset(owner, "command.test", Permission("v--"))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nonebot_plugin_permission-0.2.1.tar.gz (14.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nonebot_plugin_permission-0.2.1-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

Details for the file nonebot_plugin_permission-0.2.1.tar.gz.

File metadata

  • Download URL: nonebot_plugin_permission-0.2.1.tar.gz
  • Upload date:
  • Size: 14.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.25.6 CPython/3.11.7 Windows/10

File hashes

Hashes for nonebot_plugin_permission-0.2.1.tar.gz
Algorithm Hash digest
SHA256 9c9a6f46ff58b4f1924841f144e864b8e6b8efa8122c86b12cc155e807db8265
MD5 211439d761bb71b0b335dcf7be78a3f9
BLAKE2b-256 dab33201a5021282a5fff80c3ec78637fd5da4b30b59608f0d5c0f1daaf23f7d

See more details on using hashes here.

File details

Details for the file nonebot_plugin_permission-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for nonebot_plugin_permission-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a43c5963ca2e2e6e4a382e20119419c65980786b2737e1a5fcd9d896f916afbd
MD5 c0ffca649726bc795a4a2e1ad5087bb5
BLAKE2b-256 6cc358e517f6614407496ea9ff24a86a2a09fbb6fb77a03fad014b89a5b5f278

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page