mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 14:22:55 +08:00
Update data_source.py
This commit is contained in:
parent
440b548a4f
commit
29f47878e9
@ -59,7 +59,7 @@ async def remind(bot: Bot):
|
||||
is_restart_file.unlink()
|
||||
|
||||
|
||||
async def check_update(bot: Bot) -> int:
|
||||
async def check_update(bot: Bot) -> 'int, str':
|
||||
logger.info("开始检查更新真寻酱....")
|
||||
_version = "v0.0.0"
|
||||
if _version_file.exists():
|
||||
@ -79,9 +79,11 @@ async def check_update(bot: Bot) -> int:
|
||||
logger.info(f"开始下载真寻最新版文件....")
|
||||
if await download_latest_file(tar_gz_url):
|
||||
logger.info("下载真寻最新版文件完成....")
|
||||
await asyncio.get_event_loop().run_in_executor(
|
||||
error = await asyncio.get_event_loop().run_in_executor(
|
||||
None, _file_handle, latest_version
|
||||
)
|
||||
if error:
|
||||
return 998, error
|
||||
logger.info("真寻更新完毕,清理文件完成....")
|
||||
logger.info("开始获取真寻更新日志.....")
|
||||
update_info = data["body"]
|
||||
@ -100,7 +102,7 @@ async def check_update(bot: Bot) -> int:
|
||||
f"更新日志:\n"
|
||||
f"{image('update_info.png')}"),
|
||||
)
|
||||
return 200
|
||||
return 200, ''
|
||||
else:
|
||||
logger.warning(f"下载真寻最新版本失败...版本号:{latest_version}")
|
||||
await bot.send_private_msg(
|
||||
@ -118,14 +120,17 @@ async def check_update(bot: Bot) -> int:
|
||||
await bot.send_private_msg(
|
||||
user_id=int(list(bot.config.superusers)[0]), message=f"自动获取真寻版本失败...."
|
||||
)
|
||||
return 999
|
||||
return 999, ''
|
||||
|
||||
|
||||
def _file_handle(latest_version: str):
|
||||
def _file_handle(latest_version: str) -> str:
|
||||
if not temp_dir.exists():
|
||||
temp_dir.mkdir(exist_ok=True, parents=True)
|
||||
if backup_dir.exists():
|
||||
shutil.rmtree(backup_dir)
|
||||
tf = None
|
||||
error = ''
|
||||
try:
|
||||
backup_dir.mkdir(exist_ok=True, parents=True)
|
||||
logger.info("开始解压真寻文件压缩包....")
|
||||
tf = tarfile.open(zhenxun_latest_tar_gz)
|
||||
@ -169,6 +174,8 @@ def _file_handle(latest_version: str):
|
||||
tmp += check_old_lines(old_lines, nl)
|
||||
with open(file, "w", encoding="utf8") as f:
|
||||
f.write(tmp)
|
||||
except Exception as e:
|
||||
error = f'{type(e)}:{e}'
|
||||
if tf:
|
||||
tf.close()
|
||||
if temp_dir.exists():
|
||||
@ -180,6 +187,7 @@ def _file_handle(latest_version: str):
|
||||
local_update_info_file.unlink()
|
||||
with open(_version_file, "w", encoding="utf8") as f:
|
||||
f.write(f"__version__: {latest_version}")
|
||||
return error
|
||||
|
||||
|
||||
# 获取最新版本号
|
||||
|
||||
Loading…
Reference in New Issue
Block a user