From 27dbd470a7ea33da00d3160d19514450059c543c Mon Sep 17 00:00:00 2001 From: Rock Chin <1010553892@qq.com> Date: Mon, 2 Jan 2023 12:54:38 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E8=87=AA=E5=8A=A8=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=97=B6=E7=9A=84=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 1 - pkg/qqbot/process.py | 6 +++++- pkg/utils/updater.py | 7 ++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index d1f4a228..20a35855 100644 --- a/main.py +++ b/main.py @@ -115,7 +115,6 @@ def stop(): if __name__ == '__main__': - print('程序启动') # 检查是否有config.py,如果没有就把config-template.py复制一份,并退出程序 if not os.path.exists('config.py'): shutil.copy('config-template.py', 'config.py') diff --git a/pkg/qqbot/process.py b/pkg/qqbot/process.py index 6ef30e70..6d95ce45 100644 --- a/pkg/qqbot/process.py +++ b/pkg/qqbot/process.py @@ -167,7 +167,11 @@ def process_message(launcher_type: str, launcher_id: int, text_message: str, mes threading.Thread(target=reload_task, daemon=True).start() elif cmd == 'update' and launcher_type == 'person' and launcher_id == config.admin_qq: def update_task(): - pkg.utils.updater.update_all() + try: + pkg.utils.updater.update_all() + except Exception as e0: + pkg.utils.context.get_qqbot_manager().notify_admin("更新失败:{}".format(e0)) + return pkg.utils.reloader.reload_all() threading.Thread(target=update_task, daemon=True).start() diff --git a/pkg/utils/updater.py b/pkg/utils/updater.py index cba1d87d..834c5ceb 100644 --- a/pkg/utils/updater.py +++ b/pkg/utils/updater.py @@ -1,7 +1,12 @@ +import dulwich.porcelain + + def update_all(): try: from dulwich import porcelain repo = porcelain.open_repo('.') porcelain.pull(repo) except ModuleNotFoundError: - raise Exception("dulwich模块未安装,请查看 https://github.com/RockChinQ/QChatGPT/issues/77") \ No newline at end of file + raise Exception("dulwich模块未安装,请查看 https://github.com/RockChinQ/QChatGPT/issues/77") + except dulwich.porcelain.DivergedBranches: + raise Exception("分支不一致,自动更新仅支持master分支,请手动更新")