Skip to content

Commit

Permalink
chore: stash
Browse files Browse the repository at this point in the history
  • Loading branch information
RockChinQ committed Dec 21, 2023
1 parent 38357dd commit b8776fb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
6 changes: 3 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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警告
Expand Down Expand Up @@ -486,5 +486,5 @@ def run_wrapper():


if __name__ == '__main__':
main()
asyncio.run(main())

10 changes: 7 additions & 3 deletions pkg/qqbot/cmds/system/update.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import threading
import asyncio
import traceback

from .. import aamgr
Expand All @@ -20,9 +21,9 @@ def process(cls, ctx: aamgr.Context) -> tuple[bool, list]:
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("无新版本")
Expand All @@ -31,7 +32,10 @@ def update_task():
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]正在更新,请耐心等待,请勿重复发起更新..."]

Expand Down
16 changes: 15 additions & 1 deletion pkg/utils/updater.py
Original file line number Diff line number Diff line change
@@ -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():
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b8776fb

Please sign in to comment.