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, ROOT, NodeState

matcher = on_command("test")

@matcher.handle()
async def handle(owner: UserOwner):
    state: NodeState = ROOT.get(owner, "command.test")

通过指令设置权限

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

通过代码设置权限

from nonebot_plugin_permission import ROOT, NodeState, monitor

@matcher.handle()
async def _():
    owner = await monitor.get_or_new_user("xxx")
    # 设置权限
    ROOT.set(owner, "command.test", NodeState("vma"))
    # 取消权限
    ROOT.set(owner, "command.test", NodeState("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.1.0.tar.gz (13.6 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.1.0-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nonebot_plugin_permission-0.1.0.tar.gz
  • Upload date:
  • Size: 13.6 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.1.0.tar.gz
Algorithm Hash digest
SHA256 fe18bfd27299740dfff43f4a03d3436d501c039cc0ab13e0a6cf691fd449db3c
MD5 2af77e4015f5190fd2f4f44ad75a6dc8
BLAKE2b-256 f21b24a27b53e7ef06739aa24d8e1f94f413388c77cc1d76be40afd520225ae4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for nonebot_plugin_permission-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1c75296b3bccb9e51e875bf3a157d8a2b605767839190c82a611870e25dbc9e8
MD5 7fccdb6a8934beb7a4e4c9d32a5833ef
BLAKE2b-256 87d8c0b55c6294a832713fc179515a5e4ccbf7b23ad9a90408a6418117bf5076

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