精细化的 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
依赖
目前只支持 OneBot V11 协议,之后可能会支持其他协议。
使用
本插件主要通过 NoneBot 的 require 机制向其他插件提供功能。本插件也提供了一组命令,用于直接管理权限配置。
from nonebot import require
P = require("nonebot_plugin_flexperm").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
命令重新加载。
也可以通过命令编辑权限配置,详见命令文档。
配置
本插件使用两个配置项,均为可选。如需修改,写入 NoneBot 项目环境文件.env.*
即可。
flexperm_base
: 权限配置文件所在目录,默认为permissions
。flexperm_debug_check
: 是否输出检查权限过程中的调试信息,默认为false
。未启用 NoneBot 的调试模式时无效。
鸣谢
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
Close
Hashes for nonebot-plugin-flexperm-0.4.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | de1860214293f95e58e0e06e9d6d6022668233e30dd558ca2c6e1d8a4eae6a72 |
|
MD5 | 64a42c3d818eec12ae91a10a208bd216 |
|
BLAKE2b-256 | 54fae0c3c21dd776085153e80b1023794590905dd3a0e208a1e7c94397fb0a6c |
Close
Hashes for nonebot_plugin_flexperm-0.4.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a906adfdd0be5bd706dc97d2a6731b6d8e8c6146243a2c295568714df08e0ab |
|
MD5 | 4042b878250f6df2b42a8201bbd825f5 |
|
BLAKE2b-256 | ac34b16a0a15f08ddd2ed4d28268d67fc38fc17520232a904226cacdac3d8e0e |