mirror of
https://github.com/RockChinQ/QChatGPT.git
synced 2024-11-16 03:32:33 +08:00
feat: 基本插件指令
This commit is contained in:
parent
2c9e7f70f2
commit
6af55d8a1d
|
@ -92,6 +92,25 @@ def unload_plugins():
|
|||
logging.error("插件{}卸载时发生错误: {}".format(plugin['name'], sys.exc_info()))
|
||||
|
||||
|
||||
def install_plugin(repo_url: str):
|
||||
""" 安装插件,从git储存库获取并解决依赖 """
|
||||
try:
|
||||
import pkg.utils.pkgmgr
|
||||
pkg.utils.pkgmgr.ensure_dulwich()
|
||||
except:
|
||||
pass
|
||||
|
||||
try:
|
||||
import dulwich
|
||||
except ModuleNotFoundError:
|
||||
raise Exception("dulwich模块未安装,请查看 https://github.com/RockChinQ/QChatGPT/issues/77")
|
||||
|
||||
from dulwich import porcelain
|
||||
|
||||
logging.info("克隆插件储存库: {}".format(repo_url))
|
||||
repo = porcelain.clone(repo_url, "plugins", checkout=True)
|
||||
|
||||
|
||||
class EventContext:
|
||||
""" 事件上下文 """
|
||||
eid = 0
|
||||
|
|
|
@ -80,6 +80,35 @@ def config_operation(cmd, params):
|
|||
return reply
|
||||
|
||||
|
||||
def plugin_operation(cmd, params, is_admin):
|
||||
reply = []
|
||||
|
||||
import pkg.plugin.host as plugin_host
|
||||
|
||||
plugin_list = plugin_host.__plugins__
|
||||
|
||||
if len(params) == 0:
|
||||
reply_str = "[bot]所有插件:\n\n"
|
||||
idx = 0
|
||||
for key in plugin_list:
|
||||
plugin = plugin_list[key]
|
||||
print(plugin)
|
||||
reply_str += "#{} {}:\n{}\nv{}\n作者:{}\n\n".format((idx+1), plugin['name'], plugin['description'],
|
||||
plugin['version'], plugin['author'])
|
||||
idx += 1
|
||||
|
||||
reply = [reply_str]
|
||||
elif params[0] == 'update':
|
||||
pass
|
||||
elif params[0].startswith("http"):
|
||||
if is_admin:
|
||||
threading.Thread(target=plugin_host.install_plugin, args=(params[0],)).start()
|
||||
reply = ["[bot]正在安装插件..."]
|
||||
else:
|
||||
reply = ["[bot]err:权限不足,请使用管理员账号私聊发起"]
|
||||
return reply
|
||||
|
||||
|
||||
def process_command(session_name: str, text_message: str, mgr, config,
|
||||
launcher_type: str, launcher_id: int, sender_id: int) -> list:
|
||||
reply = []
|
||||
|
@ -197,6 +226,11 @@ def process_command(session_name: str, text_message: str, mgr, config,
|
|||
pass
|
||||
|
||||
reply = [reply_str]
|
||||
|
||||
elif cmd == 'plugin':
|
||||
reply = plugin_operation(cmd, params, True
|
||||
if (launcher_type == 'person' and launcher_id == config.admin_qq)
|
||||
else False)
|
||||
elif cmd == 'reload' and launcher_type == 'person' and launcher_id == config.admin_qq:
|
||||
def reload_task():
|
||||
pkg.utils.reloader.reload_all()
|
||||
|
|
Loading…
Reference in New Issue
Block a user