Nonebot Plugin Manager base on import hook
Project description
Nonebot Plugin Manager
适用于 nonebot2 的非侵入式插件管理器
安装
从 PyPI 安装(推荐)
- 使用 nb-cli
nb plugin install nonebot_plugin_manager
- 使用 poetry
poetry add nonebot_plugin_manager
- 使用 pip
pip install nonebot_plugin_manager
从 GitHub 安装(不推荐)
git clone https://github.com/Jigsaw111/nonebot_plugin_manager.git
使用
使用前请先确保命令前缀为空,否则请在以下命令前加上命令前缀 (默认为 /
)。
-
npm list
查看插件列表 -
-s, --store
可选参数,查看 nonebot 插件商店(仅超级用户可用)
-
-d, --default
可选参数,管理默认设置(仅超级用户可用)
-
-g group_id, --group group_id
可选参数,管理群设置(仅超级用户可用)
-
npm block 插件名...
屏蔽插件 (仅群管及超级用户可用) -
-a, --all
可选参数,全选插件
-
-d, --default
可选参数,管理默认设置 (仅超级用户可用)
-
-g group_id, --group group_id
可选参数,管理群设置(仅超级用户可用)
-
npm unblock 插件名...
启用插件 (仅群管及超级用户可用) -
-a, --all
可选参数,全选插件
-
-d, --default
可选参数,管理默认设置 (仅超级用户可用)
-
-g group_id, --group group_id
可选参数,管理群设置(仅超级用户可用)
-
npm install 插件名...
安装插件 (仅超级用户可用) -
-i index, --index index
指定 PyPI 源
-
npm update 插件名...
更新插件 (仅超级用户可用) -
-i index, --index index
指定 PyPI 源
-
-a, --all
可选参数,全选插件
-
npm uninstall 插件名...
卸载插件 (仅超级用户可用) -
-a, --all
可选参数,全选插件
导出
from nonebot import require
export = require("nonebot_plugin_manager")
# 加载插件列表
export.load_()
# 保存插件列表
export.dump_()
示例
例如我有一个插件需要有自己的开关功能,那么我们就可以通过导出来实现这一点。
# 启用插件
plugin_list=export.load_()
plugin_list['nodice'].update({str(kargs["group_id"]):True})
export.dump_(plugin_list)
Q&A
- 这是什么?
基于 import hook 的插件管理器,能够在不重启 nonebot2 的情况下分群管理插件。 - 有什么用?
在 nonebot2 仍然缺乏插件管理机制的时期暂时充当插件管理器。 - 自造 Rule 不是更好?
Rule 当然更好且更有效率,但是 Rule 是一种侵入式的插件管理方式,需要用户自行修改其他插件,这对于管理从 pypi 安装的插件来说相对复杂。而使用本插件,你不需要修改其他插件的任何内容,更符合插件之间松耦合的设计原则。
Thanks
展开更多
原理
使用 run_preprocessor
装饰器,在 Matcher 运行之前检测其所属的 Plugin 判断是否打断。
事实上 Nonebot 还是加载了插件,所以只能算是屏蔽而非卸载。
当然,你也可以使用 npm uninstall
命令来真正卸载插件,但我不建议你这样做,因为该命令将会重启 Nonebot 。
TO DO
- 分群插件管理
- 安装卸载插件
Bug
- 无法停用 Matcher 以外的功能(也就是说无法屏蔽主动发消息的插件,例如 Harukabot )。
- 目前任何人都可以屏蔽/启用插件
Changelog
- 210312,重构 0.3.0,
setting.json
重命名为plugin_list.json
,结构改为plugin:{group_id:true,group_id:false}
。 - 210310,0.3.0 完工,将__init__.py分离成 setting,command,nb 三个文件。
- 210310,0.2.0 完工,命令格式改为 shelllike,使用
setting.json
作为配置文件,基本结构为group_id:{plugin:true,plugin:false}
。 - 210307,0.1.0 完工,上架插件商店。确定了通过
run_preprocessor
屏蔽 Matcher 的基本原理,使用block_list
作为全局设置(即只屏蔽 block_list 中的插件)
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_manager-0.3.3.post1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | b9dac41a2098d249dacdbc935b8d19f165efb9ff245516eb0bc04579135775df |
|
MD5 | f46be2664de04f7504c4819e7afbc728 |
|
BLAKE2b-256 | 98c66f344b598ea78594019735199aedf4f029f96c2695af713a5db318e4747d |
Close
Hashes for nonebot_plugin_manager-0.3.3.post1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a17d949ce25f42313cd872a8dab9dc7f3d3732812d4450b1a6a2a1eb2c82dda |
|
MD5 | aa4ea54f0a4f1dd9015ed1f332415e5a |
|
BLAKE2b-256 | 10e450d79f9d4e147ab9ef935e4ebf4da923cb5920d9fef78532dea90ecb97fa |