精细化的 NoneBot 权限管理插件
Project description
nonebot-plugin-flexperm
精细化的 NoneBot 权限管理插件。
提供对用户精确到人或群、对插件精确到指令或更细粒度的权限管理功能。
安装
- 使用 nb-cli
nb plugin install nonebot-plugin-flexperm
- 使用 poetry
poetry add nonebot-plugin-flexperm
- 使用 pip
pip install nonebot-plugin-flexperm
依赖
依赖nonebot^2.0.0,支持的协议见这里。
使用
本插件主要通过 NoneBot 的 require 机制向其他插件提供功能。本插件也提供了一组命令,用于直接管理权限配置。
from nonebot import require
require("nonebot_plugin_flexperm")
from nonebot_plugin_flexperm import register
P = register("my_plugin")
P是一个可调用对象,以权限名为参数调用即可得到相应的检查器。P的其他接口详见接口文档。
from nonebot import on_command
cmd = on_command("my_command", permission=P("my_command"))
@cmd.handle()
async def _(bot, event):
...
这样,运行时只有具有my_plugin.my_command权限的用户或群才能使用该命令。
权限配置文件
权限配置文件使用 YAML 格式,详见权限配置文档。示例:
anyone:
permissions:
- my_plugin.help
group_admin:
permissions:
- my_plugin.my_command
- another_plugin.*
- -another_plugin.another_command
这个配置文件授予了所有用户my_plugin.help权限,同时授予了群管理员my_plugin.my_command权限和another_plugin下的所有子权限,但撤销another_plugin.another_command权限。
命令
权限配置文件可以在运行时修改,然后使用/flexperm.reload命令重新加载。
也可以通过命令编辑权限配置,详见命令文档。
配置
本插件使用3个配置项,均为可选。如需修改,写入 NoneBot 项目环境文件.env.*即可。
flexperm_base: 权限配置文件所在目录,默认为permissions。flexperm_debug_check: 是否输出检查权限过程中的调试信息,默认为false。未启用 NoneBot 的调试模式时无效。flexperm_default_adapter: 检查基于用户ID的权限配置时的默认适配器名,不区分大小写,默认为onebot。
鸣谢
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nonebot_plugin_flexperm-0.7.0.tar.gz.
File metadata
- Download URL: nonebot_plugin_flexperm-0.7.0.tar.gz
- Upload date:
- Size: 14.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f25f13dc56ef67e98a2d6835302ec5d93785efc624b915dfeed5960f2a277168
|
|
| MD5 |
9e60f19bda2785702feff1fdd608213e
|
|
| BLAKE2b-256 |
c3f7d7db3a214b60d9c9401207e9b06db69a5e9f991f0dce38c3312aea063848
|
File details
Details for the file nonebot_plugin_flexperm-0.7.0-py3-none-any.whl.
File metadata
- Download URL: nonebot_plugin_flexperm-0.7.0-py3-none-any.whl
- Upload date:
- Size: 17.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e46868c0e827320a0e8f47b00561763c800be757ef11bfbd2c2cf82febff756c
|
|
| MD5 |
d44a0fffe80332d4b8df3a13789b9ca0
|
|
| BLAKE2b-256 |
606954374884e97c9b7b9b19a048b177a6120e48be68b950d729800e9e5b41b9
|