基于 SOC 职业分类
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/advent259141/astrbot_self_manager_skill --skill plugin-manager命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
| name | plugin-manager |
| description | 管理 AstrBot 插件的安装、卸载、启停、更新和重载操作 |
| version | 2.0.0 |
| author | AstrBot Community |
| requires_admin | true |
| requires_computer_use | true |
你是一个专门负责 AstrBot 插件管理的助手。本 Skill 提供完整的插件生命周期管理能力。
当用户提出以下需求时,使用本 Skill:
⚠️ 本 Skill 的所有操作都需要管理员权限。
在执行任何操作前,必须先检查权限:
if not event.is_admin():
print("❌ 错误:仅管理员可执行插件管理操作。")
sys.exit(1)
功能: 显示所有已安装的插件及其状态
使用时机:
Python 代码:
#!/usr/bin/env python3
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)
功能: 从 Git 仓库 URL 安装新插件
参数:
url (str): Git 仓库地址,支持 GitHub/GitLab/Giteebranch (str, 可选): 指定分支,默认为 main/master使用时机:
Python 代码:
#!/usr/bin/env python3
import asyncio
import subprocess
async def install_plugin(context, url: str, branch: str = ""):
"""从 Git URL 安装插件"""
try:
# 使用 context 的插件管理器
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}"
# 执行(从用户输入提取 URL)
result = await install_plugin(context, url="<用户提供的URL>")
print(result)
功能: 完全移除指定的插件
参数:
plugin_name (str): 插件名称注意事项:
Python 代码:
#!/usr/bin/env python3
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)
功能: 切换插件的启用状态
参数:
plugin_name (str): 插件名称enable (bool): True=启用, False=禁用Python 代码:
#!/usr/bin/env python3
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)
功能: 从 Git 仓库拉取最新代码更新插件
参数:
plugin_name (str): 插件名称,留空则更新所有插件Python 代码:
#!/usr/bin/env python3
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}」不存在。"
# 执行 git pull
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)
功能: 重新加载插件(停止后重新启动)
用途:
Python 代码:
#!/usr/bin/env python3
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)
用户: "有哪些插件?"
Agent 操作:
plugin-manager.mdlist_plugins 代码预期输出:
📦 已安装的插件:
- [✅启用] **music_player**: 音乐播放插件
- [❌禁用] **weather**: 天气查询插件
- [✅启用] **translator**: 翻译插件
用户: "帮我安装 https://github.com/example/astrbot-plugin-example 这个插件"
Agent 操作:
plugin-manager.mdhttps://github.com/example/astrbot-plugin-exampleinstall_plugin 代码预期输出:
✅ 插件安装成功:astrbot-plugin-example
路径:data/plugins/astrbot-plugin-example
用户: "把音乐插件关掉"
Agent 操作:
plugin-manager.mdmusic_playertoggle_plugin(context, "music_player", False)预期输出:
✅ 已禁用插件「music_player」。
所有操作开始前,必须验证管理员权限:
if not event.is_admin():
print("❌ 错误:仅管理员可执行此操作。")
sys.exit(1)
每个操作都应该有完整的异常捕获:
try:
# 执行操作
result = await do_something()
except FileNotFoundError:
return "❌ 插件不存在"
except PermissionError:
return "❌ 权限不足"
except Exception as e:
return f"❌ 操作失败:{e}"
对于危险操作(卸载、删除),建议先确认:
# 卸载前确认
print(f"⚠️ 即将卸载插件「{plugin_name}」,此操作不可逆。")
print("如需继续,请用户回复「确认卸载」。")
本 Skill 需要执行 Python 代码,用户必须启用 Computer Use 模式:
如果用户未启用,提示:
⚠️ 本功能需要启用 Computer Use 模式。
请在 AstrBot 配置中启用「本地执行」或「沙箱执行」。
版本: 2.0.0
最后更新: 2024-01
兼容: AstrBot v4.13.0+