perf: 更新时的通知逻辑

This commit is contained in:
Rock Chin
2023-01-05 21:04:52 +08:00
parent 8bb8a72060
commit ee76929fee
2 changed files with 9 additions and 5 deletions

View File

@@ -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: elif cmd == 'update' and launcher_type == 'person' and launcher_id == config.admin_qq:
def update_task(): def update_task():
try: 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: except Exception as e0:
pkg.utils.context.get_qqbot_manager().notify_admin("更新失败:{}".format(e0)) pkg.utils.context.get_qqbot_manager().notify_admin("更新失败:{}".format(e0))
return return
pkg.utils.reloader.reload_all(notify=False)
pkg.utils.context.get_qqbot_manager().notify_admin("更新完成")
threading.Thread(target=update_task, daemon=True).start() threading.Thread(target=update_task, daemon=True).start()

View File

@@ -3,7 +3,7 @@ import datetime
import pkg.utils.context import pkg.utils.context
def update_all(): def update_all() -> bool:
"""使用dulwich更新源码""" """使用dulwich更新源码"""
try: try:
import dulwich import dulwich
@@ -14,7 +14,6 @@ def update_all():
from dulwich import porcelain from dulwich import porcelain
repo = porcelain.open_repo('.') repo = porcelain.open_repo('.')
porcelain.pull(repo) porcelain.pull(repo)
after_commit_id = get_current_commit_id()
change_log = "" change_log = ""
@@ -27,6 +26,9 @@ def update_all():
if change_log != "": if change_log != "":
pkg.utils.context.get_qqbot_manager().notify_admin("代码拉取完成,更新内容如下:\n"+change_log) pkg.utils.context.get_qqbot_manager().notify_admin("代码拉取完成,更新内容如下:\n"+change_log)
return True
else:
return False
except ModuleNotFoundError: except ModuleNotFoundError:
raise Exception("dulwich模块未安装,请查看 https://github.com/RockChinQ/QChatGPT/issues/77") raise Exception("dulwich模块未安装,请查看 https://github.com/RockChinQ/QChatGPT/issues/77")
except dulwich.porcelain.DivergedBranches: except dulwich.porcelain.DivergedBranches: