From 690e542f37c831aad7a0364859c8c2bed0922447 Mon Sep 17 00:00:00 2001 From: Rock Chin <1010553892@qq.com> Date: Tue, 17 Jan 2023 12:35:40 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/qqbot/command.py | 18 +++++++++++++++++- pkg/utils/updater.py | 13 ++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/pkg/qqbot/command.py b/pkg/qqbot/command.py index aedd6622..04eba40c 100644 --- a/pkg/qqbot/command.py +++ b/pkg/qqbot/command.py @@ -106,7 +106,23 @@ def plugin_operation(cmd, params, is_admin): reply = [reply_str] elif params[0] == 'update': - pass + # 更新所有插件 + if is_admin: + def closure(): + updated = [] + for key in plugin_list: + plugin = plugin_list[key] + if updater.is_repo("/".join(plugin['path'].split('/')[:-1])): + success = updater.pull_latest("/".join(plugin['path'].split('/')[:-1])) + if success: + updated.append(plugin['name']) + + pkg.utils.context.get_qqbot_manager().notify_admin("[bot]已更新插件: {}".format(", ".join(updated))) + + threading.Thread(target=closure).start() + reply = ["[bot]正在更新所有插件..."] + else: + reply = ["[bot]err:权限不足"] elif params[0].startswith("http"): if is_admin: diff --git a/pkg/utils/updater.py b/pkg/utils/updater.py index dbc2c485..7c55dd7b 100644 --- a/pkg/utils/updater.py +++ b/pkg/utils/updater.py @@ -16,6 +16,18 @@ def check_dulwich_closure(): raise Exception("dulwich模块未安装,请查看 https://github.com/RockChinQ/QChatGPT/issues/77") +def pull_latest(repo_path: str) -> bool: + """拉取最新代码""" + check_dulwich_closure() + + from dulwich import porcelain + + repo = porcelain.open_repo(repo_path) + porcelain.pull(repo) + + return True + + def update_all() -> bool: """使用dulwich更新源码""" check_dulwich_closure() @@ -58,7 +70,6 @@ def is_repo(path: str) -> bool: return False - def get_remote_url(repo_path: str) -> str: """获取远程仓库地址""" check_dulwich_closure()