mirror of
https://github.com/langbot-app/LangBot.git
synced 2025-11-25 03:15:06 +08:00
chore: stash
This commit is contained in:
6
main.py
6
main.py
@@ -422,7 +422,7 @@ def stop():
|
||||
raise e
|
||||
|
||||
|
||||
def main():
|
||||
async def main():
|
||||
global use_override
|
||||
# 检查是否携带了 --override 或 -r 参数
|
||||
if '--override' in sys.argv or '-r' in sys.argv:
|
||||
@@ -450,7 +450,7 @@ def main():
|
||||
elif len(sys.argv) > 1 and sys.argv[1] == 'update':
|
||||
print("正在进行程序更新...")
|
||||
import pkg.utils.updater as updater
|
||||
updater.update_all(cli=True)
|
||||
await updater.update_all(cli=True)
|
||||
sys.exit(0)
|
||||
|
||||
# 关闭urllib的http警告
|
||||
@@ -486,5 +486,5 @@ def main():
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
asyncio.run(main())
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import threading
|
||||
import asyncio
|
||||
import traceback
|
||||
|
||||
from .. import aamgr
|
||||
@@ -20,9 +21,9 @@ class UpdateCommand(aamgr.AbstractCommandNode):
|
||||
import pkg.utils.reloader
|
||||
import pkg.utils.context
|
||||
|
||||
def update_task():
|
||||
async def update_task():
|
||||
try:
|
||||
if pkg.utils.updater.update_all():
|
||||
if await pkg.utils.updater.update_all():
|
||||
pkg.utils.context.get_qqbot_manager().notify_admin("更新完成, 请手动重启程序。")
|
||||
else:
|
||||
pkg.utils.context.get_qqbot_manager().notify_admin("无新版本")
|
||||
@@ -31,7 +32,10 @@ class UpdateCommand(aamgr.AbstractCommandNode):
|
||||
pkg.utils.context.get_qqbot_manager().notify_admin("更新失败:{}".format(e0))
|
||||
return
|
||||
|
||||
threading.Thread(target=update_task, daemon=True).start()
|
||||
def wrapper():
|
||||
asyncio.run(update_task())
|
||||
|
||||
threading.Thread(target=wrapper).start()
|
||||
|
||||
reply = ["[bot]正在更新,请耐心等待,请勿重复发起更新..."]
|
||||
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import datetime
|
||||
import logging
|
||||
import os.path
|
||||
import time
|
||||
|
||||
import requests
|
||||
|
||||
from . import constants
|
||||
from . import network
|
||||
from . import context
|
||||
|
||||
|
||||
def check_dulwich_closure():
|
||||
@@ -105,9 +109,12 @@ def compare_version_str(v0: str, v1: str) -> int:
|
||||
return 0
|
||||
|
||||
|
||||
def update_all(cli: bool = False) -> bool:
|
||||
async def update_all(cli: bool = False) -> bool:
|
||||
"""检查更新并下载源码"""
|
||||
start_time = time.time()
|
||||
|
||||
current_tag = get_current_tag()
|
||||
old_tag = current_tag
|
||||
|
||||
rls_list = get_release_list()
|
||||
|
||||
@@ -200,6 +207,13 @@ def update_all(cli: bool = False) -> bool:
|
||||
with open("current_tag", "w") as f:
|
||||
f.write(current_tag)
|
||||
|
||||
await context.get_center_v2_api().main.post_update_record(
|
||||
spent_seconds=int(time.time()-start_time),
|
||||
infer_reason="update",
|
||||
old_version=old_tag,
|
||||
new_version=current_tag,
|
||||
)
|
||||
|
||||
# 通知管理员
|
||||
if not cli:
|
||||
import pkg.utils.context
|
||||
|
||||
Reference in New Issue
Block a user