From 4deb7d11a106fef169c1e947751ac0e2c07d14d7 Mon Sep 17 00:00:00 2001 From: snowy Date: Sun, 26 May 2024 18:15:57 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E6=96=B0=E5=A2=9E=E5=BC=80?= =?UTF-8?q?=E5=8F=91=E8=80=85=E9=80=89=E9=A1=B9=E6=98=AF=E5=90=A6=E5=85=81?= =?UTF-8?q?=E8=AE=B8=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/deployment/config.md | 1 + liteyuki/liteyuki_main/api.py | 40 ++++++++++++++++++++--------------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/docs/deployment/config.md b/docs/deployment/config.md index 1125e6e..a94b37e 100644 --- a/docs/deployment/config.md +++ b/docs/deployment/config.md @@ -29,6 +29,7 @@ onebot_access_token: "" # 访问令牌,对公开放时建议设置 default_language: "zh-CN" # 默认语言 alconna_auto_completion: false # alconna是否自动补全指令,默认false,建议开启 # 开发者选项 +allow_update: true # 是否允许更新 log_level: "INFO" # 日志等级 log_icon: true # 是否显示日志等级图标(某些控制台字体不可用) auto_report: true # 是否自动上报问题给轻雪服务器 diff --git a/liteyuki/liteyuki_main/api.py b/liteyuki/liteyuki_main/api.py index b79d3d9..9cdcb94 100644 --- a/liteyuki/liteyuki_main/api.py +++ b/liteyuki/liteyuki_main/api.py @@ -1,6 +1,8 @@ import nonebot from git import Repo +from liteyuki.utils.base.config import get_config + remote_urls = [ "https://github.com/snowykami/LiteyukiBot.git", "https://gitee.com/snowykami/LiteyukiBot.git" @@ -21,21 +23,25 @@ def update_liteyuki() -> tuple[bool, str]: """更新轻雪 :return: 是否更新成功,更新变动""" - new_commit_detected = detect_update() - if new_commit_detected: - repo = Repo(".") - logs = "" - # 对每个远程仓库进行更新 - for remote_url in remote_urls: - try: - logs += f"\nremote: {remote_url}" - repo.remotes.origin.set_url(remote_url) - repo.remotes.origin.pull() - diffs = repo.head.commit.diff("origin/main") - for diff in diffs.iter_change_type('M'): - logs += f"\n{diff.a_path}" - return True, logs - except: - continue + if get_config("allow_update", True): + new_commit_detected = detect_update() + if new_commit_detected: + repo = Repo(".") + logs = "" + # 对每个远程仓库进行更新 + for remote_url in remote_urls: + try: + logs += f"\nremote: {remote_url}" + repo.remotes.origin.set_url(remote_url) + repo.remotes.origin.pull() + diffs = repo.head.commit.diff("origin/main") + for diff in diffs.iter_change_type('M'): + logs += f"\n{diff.a_path}" + return True, logs + except: + continue + else: + return False, "Nothing Changed" + else: - return False, "Nothing Changed" + raise PermissionError("Update is not allowed.")