diff --git a/docs/deployment/config.md b/docs/deployment/config.md index 1125e6e2..a94b37e0 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 b79d3d99..9cdcb941 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.")