1
0
forked from bot/app

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

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" # 默认语言
alconna_auto_completion: false # alconna是否自动补全指令默认false建议开启
# 开发者选项
allow_update: true # 是否允许更新
log_level: "INFO" # 日志等级
log_icon: true # 是否显示日志等级图标(某些控制台字体不可用)
auto_report: true # 是否自动上报问题给轻雪服务器

View File

@ -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.")