From ee76929feeeab9d6d8f033f9166049f853da65ed Mon Sep 17 00:00:00 2001 From: Rock Chin <1010553892@qq.com> Date: Thu, 5 Jan 2023 21:04:52 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E6=9B=B4=E6=96=B0=E6=97=B6=E7=9A=84?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/qqbot/process.py | 8 +++++--- pkg/utils/updater.py | 6 ++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/pkg/qqbot/process.py b/pkg/qqbot/process.py index 9a00d84d..40234449 100644 --- a/pkg/qqbot/process.py +++ b/pkg/qqbot/process.py @@ -252,12 +252,14 @@ def process_message(launcher_type: str, launcher_id: int, text_message: str, mes elif cmd == 'update' and launcher_type == 'person' and launcher_id == config.admin_qq: def update_task(): try: - pkg.utils.updater.update_all() + if pkg.utils.updater.update_all(): + pkg.utils.reloader.reload_all(notify=False) + pkg.utils.context.get_qqbot_manager().notify_admin("更新完成") + else: + pkg.utils.context.get_qqbot_manager().notify_admin("无新版本") except Exception as e0: pkg.utils.context.get_qqbot_manager().notify_admin("更新失败:{}".format(e0)) return - pkg.utils.reloader.reload_all(notify=False) - pkg.utils.context.get_qqbot_manager().notify_admin("更新完成") threading.Thread(target=update_task, daemon=True).start() diff --git a/pkg/utils/updater.py b/pkg/utils/updater.py index 79c5bd6b..8b832eba 100644 --- a/pkg/utils/updater.py +++ b/pkg/utils/updater.py @@ -3,7 +3,7 @@ import datetime import pkg.utils.context -def update_all(): +def update_all() -> bool: """使用dulwich更新源码""" try: import dulwich @@ -14,7 +14,6 @@ def update_all(): from dulwich import porcelain repo = porcelain.open_repo('.') porcelain.pull(repo) - after_commit_id = get_current_commit_id() change_log = "" @@ -27,6 +26,9 @@ def update_all(): if change_log != "": pkg.utils.context.get_qqbot_manager().notify_admin("代码拉取完成,更新内容如下:\n"+change_log) + return True + else: + return False except ModuleNotFoundError: raise Exception("dulwich模块未安装,请查看 https://github.com/RockChinQ/QChatGPT/issues/77") except dulwich.porcelain.DivergedBranches: