新增开发者选项是否允许更新

This commit is contained in:
远野千束 2024-05-26 18:15:57 +08:00
parent 6f069f83d4
commit 4deb7d11a1
2 changed files with 24 additions and 17 deletions

View File

@ -29,6 +29,7 @@ onebot_access_token: "" # 访问令牌,对公开放时建议设置
default_language: "zh-CN" # 默认语言 default_language: "zh-CN" # 默认语言
alconna_auto_completion: false # alconna是否自动补全指令默认false建议开启 alconna_auto_completion: false # alconna是否自动补全指令默认false建议开启
# 开发者选项 # 开发者选项
allow_update: true # 是否允许更新
log_level: "INFO" # 日志等级 log_level: "INFO" # 日志等级
log_icon: true # 是否显示日志等级图标(某些控制台字体不可用) log_icon: true # 是否显示日志等级图标(某些控制台字体不可用)
auto_report: true # 是否自动上报问题给轻雪服务器 auto_report: true # 是否自动上报问题给轻雪服务器

View File

@ -1,6 +1,8 @@
import nonebot import nonebot
from git import Repo from git import Repo
from liteyuki.utils.base.config import get_config
remote_urls = [ remote_urls = [
"https://github.com/snowykami/LiteyukiBot.git", "https://github.com/snowykami/LiteyukiBot.git",
"https://gitee.com/snowykami/LiteyukiBot.git" "https://gitee.com/snowykami/LiteyukiBot.git"
@ -21,21 +23,25 @@ def update_liteyuki() -> tuple[bool, str]:
"""更新轻雪 """更新轻雪
:return: 是否更新成功更新变动""" :return: 是否更新成功更新变动"""
new_commit_detected = detect_update() if get_config("allow_update", True):
if new_commit_detected: new_commit_detected = detect_update()
repo = Repo(".") if new_commit_detected:
logs = "" repo = Repo(".")
# 对每个远程仓库进行更新 logs = ""
for remote_url in remote_urls: # 对每个远程仓库进行更新
try: for remote_url in remote_urls:
logs += f"\nremote: {remote_url}" try:
repo.remotes.origin.set_url(remote_url) logs += f"\nremote: {remote_url}"
repo.remotes.origin.pull() repo.remotes.origin.set_url(remote_url)
diffs = repo.head.commit.diff("origin/main") repo.remotes.origin.pull()
for diff in diffs.iter_change_type('M'): diffs = repo.head.commit.diff("origin/main")
logs += f"\n{diff.a_path}" for diff in diffs.iter_change_type('M'):
return True, logs logs += f"\n{diff.a_path}"
except: return True, logs
continue except:
continue
else:
return False, "Nothing Changed"
else: else:
return False, "Nothing Changed" raise PermissionError("Update is not allowed.")