# nonebot-plugin-flexperm
精细化的 NoneBot 权限管理插件。
提供对用户精确到人或群、对插件精确到指令或更细粒度的权限管理功能。
## 安装
- 使用 nb-cli
```shell
nb plugin install nonebot-plugin-flexperm
```
- 使用 poetry
```shell
poetry add nonebot-plugin-flexperm
```
- 使用 pip
```shell
pip install nonebot-plugin-flexperm
```
## 依赖
依赖`nonebot^2.0.0`,支持的协议见[这里](docs/adapters.md)。
## 使用
本插件主要通过 NoneBot 的 require 机制向**其他插件**提供功能。本插件也提供了一组命令,用于直接管理权限配置。
```python
from nonebot import require
require("nonebot_plugin_flexperm")
from nonebot_plugin_flexperm import register
P = register("my_plugin")
```
`P`是一个可调用对象,以权限名为参数调用即可得到相应的检查器。`P`的其他接口详见[接口文档](docs/interface.md)。
```python
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 格式,详见[权限配置文档](docs/permdesc.md)。示例:
```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`命令重新加载。
也可以通过命令编辑权限配置,详见[命令文档](docs/command.md)。
## 配置
本插件使用3个配置项,均为可选。如需修改,写入 NoneBot 项目环境文件`.env.*`即可。
- `flexperm_base`: 权限配置文件所在目录,默认为`permissions`。
- `flexperm_debug_check`: 是否输出检查权限过程中的调试信息,默认为`false`。未启用 NoneBot 的调试模式时无效。
- `flexperm_default_adapter`: 检查基于用户ID的权限配置时的默认适配器名,不区分大小写,默认为`onebot`。
## 鸣谢
- [nonebot / nonebot2](https://github.com/nonebot/nonebot2)
- [Mrs4s / go-cqhttp](https://github.com/Mrs4s/go-cqhttp)
Raw data
{
"_id": null,
"home_page": "https://github.com/rmuchan/nonebot-plugin-flexperm",
"name": "nonebot-plugin-flexperm",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8,<4.0",
"maintainer_email": "",
"keywords": "nonebot",
"author": "Muchan",
"author_email": "liuzh1773@buaa.edu.cn",
"download_url": "https://files.pythonhosted.org/packages/c3/f7/d7db3a214b60d9c9401207e9b06db69a5e9f991f0dce38c3312aea063848/nonebot_plugin_flexperm-0.7.0.tar.gz",
"platform": null,
"description": "# nonebot-plugin-flexperm\n\n\u7cbe\u7ec6\u5316\u7684 NoneBot \u6743\u9650\u7ba1\u7406\u63d2\u4ef6\u3002\n\n\u63d0\u4f9b\u5bf9\u7528\u6237\u7cbe\u786e\u5230\u4eba\u6216\u7fa4\u3001\u5bf9\u63d2\u4ef6\u7cbe\u786e\u5230\u6307\u4ee4\u6216\u66f4\u7ec6\u7c92\u5ea6\u7684\u6743\u9650\u7ba1\u7406\u529f\u80fd\u3002\n\n## \u5b89\u88c5\n\n- \u4f7f\u7528 nb-cli\n\n```shell\nnb plugin install nonebot-plugin-flexperm\n```\n\n- \u4f7f\u7528 poetry\n\n```shell\npoetry add nonebot-plugin-flexperm\n```\n\n- \u4f7f\u7528 pip\n\n```shell\npip install nonebot-plugin-flexperm\n```\n\n## \u4f9d\u8d56\n\n\u4f9d\u8d56`nonebot^2.0.0`\uff0c\u652f\u6301\u7684\u534f\u8bae\u89c1[\u8fd9\u91cc](docs/adapters.md)\u3002\n\n## \u4f7f\u7528\n\n\u672c\u63d2\u4ef6\u4e3b\u8981\u901a\u8fc7 NoneBot \u7684 require \u673a\u5236\u5411**\u5176\u4ed6\u63d2\u4ef6**\u63d0\u4f9b\u529f\u80fd\u3002\u672c\u63d2\u4ef6\u4e5f\u63d0\u4f9b\u4e86\u4e00\u7ec4\u547d\u4ee4\uff0c\u7528\u4e8e\u76f4\u63a5\u7ba1\u7406\u6743\u9650\u914d\u7f6e\u3002\n\n```python\nfrom nonebot import require\nrequire(\"nonebot_plugin_flexperm\")\nfrom nonebot_plugin_flexperm import register\nP = register(\"my_plugin\")\n```\n\n`P`\u662f\u4e00\u4e2a\u53ef\u8c03\u7528\u5bf9\u8c61\uff0c\u4ee5\u6743\u9650\u540d\u4e3a\u53c2\u6570\u8c03\u7528\u5373\u53ef\u5f97\u5230\u76f8\u5e94\u7684\u68c0\u67e5\u5668\u3002`P`\u7684\u5176\u4ed6\u63a5\u53e3\u8be6\u89c1[\u63a5\u53e3\u6587\u6863](docs/interface.md)\u3002\n\n```python\nfrom nonebot import on_command\ncmd = on_command(\"my_command\", permission=P(\"my_command\"))\n\n@cmd.handle()\nasync def _(bot, event):\n ...\n```\n\n\u8fd9\u6837\uff0c\u8fd0\u884c\u65f6\u53ea\u6709\u5177\u6709`my_plugin.my_command`\u6743\u9650\u7684\u7528\u6237\u6216\u7fa4\u624d\u80fd\u4f7f\u7528\u8be5\u547d\u4ee4\u3002\n\n### \u6743\u9650\u914d\u7f6e\u6587\u4ef6\n\n\u6743\u9650\u914d\u7f6e\u6587\u4ef6\u4f7f\u7528 YAML \u683c\u5f0f\uff0c\u8be6\u89c1[\u6743\u9650\u914d\u7f6e\u6587\u6863](docs/permdesc.md)\u3002\u793a\u4f8b\uff1a\n\n```yaml\nanyone:\n permissions:\n - my_plugin.help\n\ngroup_admin:\n permissions:\n - my_plugin.my_command\n - another_plugin.*\n - -another_plugin.another_command\n```\n\n\u8fd9\u4e2a\u914d\u7f6e\u6587\u4ef6\u6388\u4e88\u4e86\u6240\u6709\u7528\u6237`my_plugin.help`\u6743\u9650\uff0c\u540c\u65f6\u6388\u4e88\u4e86\u7fa4\u7ba1\u7406\u5458`my_plugin.my_command`\u6743\u9650\u548c`another_plugin`\u4e0b\u7684\u6240\u6709\u5b50\u6743\u9650\uff0c\u4f46\u64a4\u9500`another_plugin.another_command`\u6743\u9650\u3002\n\n### \u547d\u4ee4\n\n\u6743\u9650\u914d\u7f6e\u6587\u4ef6\u53ef\u4ee5\u5728\u8fd0\u884c\u65f6\u4fee\u6539\uff0c\u7136\u540e\u4f7f\u7528`/flexperm.reload`\u547d\u4ee4\u91cd\u65b0\u52a0\u8f7d\u3002\n\n\u4e5f\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u7f16\u8f91\u6743\u9650\u914d\u7f6e\uff0c\u8be6\u89c1[\u547d\u4ee4\u6587\u6863](docs/command.md)\u3002\n\n## \u914d\u7f6e\n\n\u672c\u63d2\u4ef6\u4f7f\u75283\u4e2a\u914d\u7f6e\u9879\uff0c\u5747\u4e3a\u53ef\u9009\u3002\u5982\u9700\u4fee\u6539\uff0c\u5199\u5165 NoneBot \u9879\u76ee\u73af\u5883\u6587\u4ef6`.env.*`\u5373\u53ef\u3002\n\n- `flexperm_base`: \u6743\u9650\u914d\u7f6e\u6587\u4ef6\u6240\u5728\u76ee\u5f55\uff0c\u9ed8\u8ba4\u4e3a`permissions`\u3002\n- `flexperm_debug_check`: \u662f\u5426\u8f93\u51fa\u68c0\u67e5\u6743\u9650\u8fc7\u7a0b\u4e2d\u7684\u8c03\u8bd5\u4fe1\u606f\uff0c\u9ed8\u8ba4\u4e3a`false`\u3002\u672a\u542f\u7528 NoneBot \u7684\u8c03\u8bd5\u6a21\u5f0f\u65f6\u65e0\u6548\u3002\n- `flexperm_default_adapter`: \u68c0\u67e5\u57fa\u4e8e\u7528\u6237ID\u7684\u6743\u9650\u914d\u7f6e\u65f6\u7684\u9ed8\u8ba4\u9002\u914d\u5668\u540d\uff0c\u4e0d\u533a\u5206\u5927\u5c0f\u5199\uff0c\u9ed8\u8ba4\u4e3a`onebot`\u3002\n\n## \u9e23\u8c22\n\n- [nonebot / nonebot2](https://github.com/nonebot/nonebot2)\n- [Mrs4s / go-cqhttp](https://github.com/Mrs4s/go-cqhttp)\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "\u7cbe\u7ec6\u5316\u7684 NoneBot \u6743\u9650\u7ba1\u7406\u63d2\u4ef6",
"version": "0.7.0",
"project_urls": {
"Homepage": "https://github.com/rmuchan/nonebot-plugin-flexperm",
"Repository": "https://github.com/rmuchan/nonebot-plugin-flexperm"
},
"split_keywords": [
"nonebot"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "606954374884e97c9b7b9b19a048b177a6120e48be68b950d729800e9e5b41b9",
"md5": "d44a0fffe80332d4b8df3a13789b9ca0",
"sha256": "e46868c0e827320a0e8f47b00561763c800be757ef11bfbd2c2cf82febff756c"
},
"downloads": -1,
"filename": "nonebot_plugin_flexperm-0.7.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "d44a0fffe80332d4b8df3a13789b9ca0",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8,<4.0",
"size": 17828,
"upload_time": "2023-06-13T10:41:21",
"upload_time_iso_8601": "2023-06-13T10:41:21.102121Z",
"url": "https://files.pythonhosted.org/packages/60/69/54374884e97c9b7b9b19a048b177a6120e48be68b950d729800e9e5b41b9/nonebot_plugin_flexperm-0.7.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "c3f7d7db3a214b60d9c9401207e9b06db69a5e9f991f0dce38c3312aea063848",
"md5": "9e60f19bda2785702feff1fdd608213e",
"sha256": "f25f13dc56ef67e98a2d6835302ec5d93785efc624b915dfeed5960f2a277168"
},
"downloads": -1,
"filename": "nonebot_plugin_flexperm-0.7.0.tar.gz",
"has_sig": false,
"md5_digest": "9e60f19bda2785702feff1fdd608213e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8,<4.0",
"size": 14852,
"upload_time": "2023-06-13T10:41:23",
"upload_time_iso_8601": "2023-06-13T10:41:23.359604Z",
"url": "https://files.pythonhosted.org/packages/c3/f7/d7db3a214b60d9c9401207e9b06db69a5e9f991f0dce38c3312aea063848/nonebot_plugin_flexperm-0.7.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-06-13 10:41:23",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "rmuchan",
"github_project": "nonebot-plugin-flexperm",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "nonebot-plugin-flexperm"
}