Rule-based authorization manager worked with nonebot2
Project description
nonebot_plugin_rauthman
功能
- 基于规则的授权管理
开始使用
建议使用 poetry
- 通过 poetry 添加到
nonebot2
项目的pyproject.toml
poetry add nonebot-plugin-rauthman
- 也可以通过 pip 从 PyPI 安装
pip install nonebot-plugin-rauthman
- 在
nonebot2
项目中设置nonebot.load_plugin()
当使用 nb-cli 添加本插件时,该条会被自动添加
nonebot.load_plugin('nonebot_plugin_rauthman')
- 参照下文在
nonebot2
项目的环境文件.env.*
中添加配置项
配置项
-
授权管理信息保存位置(必须):
savedata: str
保存相对路径,示例意为保存至运行目录下的Yuni/savedata
目录
savedata = Yuni/savedata
-
授权管理应用策略(可选):
0
根据可用功能授权,当功能在群聊的可用功能列表内时为可用(默认值)1
根据功能级别授权,当群聊级别不低于功能所需级别时为可用
auth_policy = 0
-
授权管理指令所需的参数(可选):
auth_command: str
指令名,默认为auth
auth_add: str
启用功能(根据可用功能授权),默认为-a
auth_rm: str
禁用功能(根据可用功能授权),默认为-rm
auth_show: str
展示群功能状态(根据可用功能授权),默认为-s
auth_available: str
展示全局可用功能(根据可用功能授权),默认为-av
auth_command = auth
auth_add = -a
auth_rm = -rm
auth_show = -s
auth_available = -av
- 为需要管理的
on_*
事件设置规则授权,示例意为将一个on_command
事件划入一个名为servicename
的功能,同时设置功能级别1
from nonebot.plugin import on_command
from nonebot_plugin_rauthman import isInService
command = on_command('cmd', rule=isInService('servicename', 1))
- 这样,群聊必须被启用了该功能,或功能级别高于指定值(取决于当前应用的授权管理应用策略)才会进入事件处理
特别感谢
优化建议
如有优化建议请积极提交 Issues 或 Pull requests
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_rauthman-2.0.0a8.post9.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5fb84a920f35393a4a812ad528baeb17e5b22f651fd5195282a1c143c1498b2c |
|
MD5 | 1c17b14f78f3a568872a221d6d251f4e |
|
BLAKE2b-256 | f6d03e601137158c33a0706edd1da32e0c54c7e70fa14a3a48580f2cc15d23cf |
Close
Hashes for nonebot_plugin_rauthman-2.0.0a8.post9-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c332db1ddffbec15f8bfc8c425196201272d0096bea53d7a6846dda3b5cb285 |
|
MD5 | 2f7aa69277b0c9d5722c9f6a412ed024 |
|
BLAKE2b-256 | 0ef4b2dbe2be152a37ff3f5b8dd93b61aa4812c786be6e918e9837b4abad661f |