| name | plugin-manager |
| description | 管理 AstrBot 插件的安装、卸载、启停、更新和重载操作 |
| version | 2.0.0 |
| author | AstrBot Community |
| requires_admin | true |
| requires_computer_use | true |
Plugin Manager Skill
你是一个专门负责 AstrBot 插件管理的助手。本 Skill 提供完整的插件生命周期管理能力。
使用场景
当用户提出以下需求时,使用本 Skill:
- 📋 列出插件:"有哪些插件?" / "列出所有插件" / "显示插件列表"
- ⬇️ 安装插件:"安装 XXX 插件" / "帮我装一个插件"
- 🗑️ 卸载插件:"卸载 XXX 插件" / "删除 XXX 插件"
- ⚡ 启停插件:"启用/禁用 XXX 插件" / "把 XXX 插件关掉"
- 🔄 更新插件:"更新 XXX 插件" / "更新所有插件"
- 🔁 重载插件:"重载 XXX 插件" / "重新加载配置"
权限要求
⚠️ 本 Skill 的所有操作都需要管理员权限。
在执行任何操作前,必须先检查权限:
if not event.is_admin():
print("❌ 错误:仅管理员可执行插件管理操作。")
sys.exit(1)
工作流程
- 读取本 SKILL.md - Agent 必须先读取完整的技能定义
- 权限检查 - 验证用户是否为管理员
- 意图识别 - 根据用户请求确定具体操作
- 执行 Python 代码 - 调用下方的工具实现
- 返回结果 - 以清晰的格式返回给用户
可用工具
1. 列出插件 (list_plugins)
功能: 显示所有已安装的插件及其状态
使用时机:
- 用户询问"有哪些插件"
- 用户想查看插件列表
- 执行其他操作前需要确认插件名称
Python 代码:
import asyncio
async def list_plugins(context):
"""列出所有插件及其状态"""
plugins = context.get_registered_stars()
if not plugins:
return "当前没有已安装的插件。"
lines = ["📦 已安装的插件:\n"]
for plugin_info in plugins:
name = plugin_info.get("name", "unknown")
enabled = plugin_info.get("enabled", False)
status = "✅启用" if enabled else "❌禁用"
desc = plugin_info.get("description", "无描述")
lines.append(f"- [{status}] **{name}**: {desc}")
return "\n".join(lines)
result = await list_plugins(context)
print(result)
2. 安装插件 (install_plugin)
功能: 从 Git 仓库 URL 安装新插件
参数:
url (str): Git 仓库地址,支持 GitHub/GitLab/Gitee
branch (str, 可选): 指定分支,默认为 main/master
使用时机:
- 用户提供了 GitHub 等仓库链接
- 用户说"安装 XXX 插件"并提供了 URL
Python 代码:
import asyncio
import subprocess
async def install_plugin(context, url: str, branch: str = ""):
"""从 Git URL 安装插件"""
try:
plugin_mgr = context.plugin_mgr
result = await plugin_mgr.install_plugin_from_git(url, branch)
return f"✅ 插件安装成功:{result['name']}\n路径:{result['path']}"
except Exception as e:
return f"❌ 安装失败:{e}"
result = await install_plugin(context, url="<用户提供的URL>")
print(result)
3. 卸载插件 (uninstall_plugin)
功能: 完全移除指定的插件
参数:
注意事项:
- ⚠️ 卸载是不可逆操作
- ⚠️ 会删除插件目录和所有数据
- 建议先确认用户是否真的要删除
Python 代码:
import asyncio
import shutil
import os
async def uninstall_plugin(context, plugin_name: str):
"""卸载指定插件"""
try:
plugin_mgr = context.plugin_mgr
plugin_path = plugin_mgr.get_plugin_path(plugin_name)
if not plugin_path or not os.path.exists(plugin_path):
return f"❌ 插件「{plugin_name}」不存在。"
await plugin_mgr.unload_plugin(plugin_name)
shutil.rmtree(plugin_path)
return f"✅ 插件「{plugin_name}」已成功卸载。"
except Exception as e:
return f"❌ 卸载失败:{e}"
result = await uninstall_plugin(context, plugin_name="<插件名>")
print(result)
4. 启用/禁用插件 (toggle_plugin)
功能: 切换插件的启用状态
参数:
plugin_name (str): 插件名称
enable (bool): True=启用, False=禁用
Python 代码:
import asyncio
async def toggle_plugin(context, plugin_name: str, enable: bool):
"""启用或禁用插件"""
try:
plugin_mgr = context.plugin_mgr
if enable:
await plugin_mgr.load_plugin(plugin_name)
return f"✅ 已启用插件「{plugin_name}」。"
else:
await plugin_mgr.unload_plugin(plugin_name)
return f"✅ 已禁用插件「{plugin_name}」。"
except Exception as e:
action = "启用" if enable else "禁用"
return f"❌ {action}失败:{e}"
result = await toggle_plugin(context, plugin_name="<插件名>", enable=True)
print(result)
5. 更新插件 (update_plugin)
功能: 从 Git 仓库拉取最新代码更新插件
参数:
plugin_name (str): 插件名称,留空则更新所有插件
Python 代码:
import asyncio
import subprocess
import os
async def update_plugin(context, plugin_name: str = ""):
"""更新插件"""
try:
plugin_mgr = context.plugin_mgr
if plugin_name:
plugin_path = plugin_mgr.get_plugin_path(plugin_name)
if not plugin_path:
return f"❌ 插件「{plugin_name}」不存在。"
result = subprocess.run(
["git", "pull"],
cwd=plugin_path,
capture_output=True,
text=True
)
if result.returncode == 0:
return f"✅ 插件「{plugin_name}」已更新。\n{result.stdout}"
else:
return f"❌ 更新失败:{result.stderr}"
else:
results = []
plugins = context.get_registered_stars()
for plugin_info in plugins:
name = plugin_info.get("name")
res = await update_plugin(context, name)
results.append(f"{name}: {res}")
return .join(results)
Exception e:
result = update_plugin(context, plugin_name=)
(result)
6. 重载插件 (reload_plugin)
功能: 重新加载插件(停止后重新启动)
用途:
- 插件代码更新后需要重载
- 插件配置更改后需要应用
- 插件出现异常需要重启
Python 代码:
import asyncio
async def reload_plugin(context, plugin_name: str):
"""重载插件"""
try:
plugin_mgr = context.plugin_mgr
await plugin_mgr.unload_plugin(plugin_name)
await plugin_mgr.load_plugin(plugin_name)
return f"✅ 插件「{plugin_name}」已重载。"
except Exception as e:
return f"❌ 重载失败:{e}"
result = await reload_plugin(context, plugin_name="<插件名>")
print(result)
使用示例
示例 1: 列出所有插件
用户: "有哪些插件?"
Agent 操作:
- 读取
plugin-manager.md
- 执行
list_plugins 代码
- 返回插件列表
预期输出:
📦 已安装的插件:
- [✅启用] **music_player**: 音乐播放插件
- [❌禁用] **weather**: 天气查询插件
- [✅启用] **translator**: 翻译插件
示例 2: 安装新插件
用户: "帮我安装 https://github.com/example/astrbot-plugin-example 这个插件"
Agent 操作:
- 读取
plugin-manager.md
- 提取 URL:
https://github.com/example/astrbot-plugin-example
- 执行
install_plugin 代码
- 返回安装结果
预期输出:
✅ 插件安装成功:astrbot-plugin-example
路径:data/plugins/astrbot-plugin-example
示例 3: 禁用插件
用户: "把音乐插件关掉"
Agent 操作:
- 读取
plugin-manager.md
- 识别插件名:
music_player
- 执行
toggle_plugin(context, "music_player", False)
- 返回结果
预期输出:
✅ 已禁用插件「music_player」。
注意事项
1. 权限控制
所有操作开始前,必须验证管理员权限:
if not event.is_admin():
print("❌ 错误:仅管理员可执行此操作。")
sys.exit(1)
2. 错误处理
每个操作都应该有完整的异常捕获:
try:
result = await do_something()
except FileNotFoundError:
return "❌ 插件不存在"
except PermissionError:
return "❌ 权限不足"
except Exception as e:
return f"❌ 操作失败:{e}"
3. 用户确认
对于危险操作(卸载、删除),建议先确认:
print(f"⚠️ 即将卸载插件「{plugin_name}」,此操作不可逆。")
print("如需继续,请用户回复「确认卸载」。")
4. 依赖 Computer Use 模式
本 Skill 需要执行 Python 代码,用户必须启用 Computer Use 模式:
- 本地模式: 在 AstrBot 运行环境中直接执行
- 沙箱模式: 在隔离的沙箱环境中执行(更安全)
如果用户未启用,提示:
⚠️ 本功能需要启用 Computer Use 模式。
请在 AstrBot 配置中启用「本地执行」或「沙箱执行」。
相关 Skill
- skill-manager: 管理 AstrBot Skills
- config-manager: 修改插件配置
- system-monitor: 查看插件运行状态
版本: 2.0.0
最后更新: 2024-01
兼容: AstrBot v4.13.0+