Skip to main content

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


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_rauthman-2.0.0a13.tar.gz (18.8 kB view hashes)

Uploaded Source

Built Distribution

nonebot_plugin_rauthman-2.0.0a13-py3-none-any.whl (18.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page