From 7fd5394855c1868372bae658463a1af0a729357d Mon Sep 17 00:00:00 2001 From: CMHopeSunshine <277073121@qq.com> Date: Sat, 17 Sep 2022 18:11:31 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E4=BF=AE=E5=A4=8D`=E6=A3=80=E6=9F=A5?= =?UTF-8?q?=E6=9B=B4=E6=96=B0`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LittlePaimon/manager/bot_manager/handler.py | 28 ++++++++++----------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/LittlePaimon/manager/bot_manager/handler.py b/LittlePaimon/manager/bot_manager/handler.py index cbd9a1a..3f4a577 100644 --- a/LittlePaimon/manager/bot_manager/handler.py +++ b/LittlePaimon/manager/bot_manager/handler.py @@ -4,34 +4,32 @@ import git from nonebot.utils import run_sync from git.exc import GitCommandError, InvalidGitRepositoryError from LittlePaimon import __version__, NICKNAME +from LittlePaimon.utils import aiorequests -def time_str(timestamp: int) -> str: - time_local = time.localtime(timestamp) - return time.strftime("%m-%d %H:%M:%S", time_local) - - -@run_sync -def check_update(): +async def check_update(): + resp = await aiorequests.get('https://api.github.com/repos/CMHopeSunshine/LittlePaimon/commits') + data = resp.json() + if not isinstance(data, list): + return '检查更新失败,可能是网络问题,请稍后再试' try: repo = git.Repo(Path().absolute()) except InvalidGitRepositoryError: return '没有发现git仓库,无法通过git检查更新' local_commit = repo.head.commit remote_commit = [] - for commit in repo.iter_commits(max_count=15): - if local_commit == commit: + for commit in data: + if local_commit.binsha == commit['sha']: break remote_commit.append(commit) if not remote_commit: return f'当前已是最新版本:{__version__}' - i = 1 result = '检查到更新,日志如下:\n' - for commit in remote_commit: - if isinstance(commit.message, str): - result += f'{i}.{time_str(commit.committed_date)}\n' + commit.message.replace(':bug:', '🐛').replace( - ':sparkles:', '✨').replace(':memo:', '📝') + '\n' - i += 1 + for i, commit in enumerate(remote_commit, start=1): + result += f'{i}.{commit["commit"]["committer"]["date"].replace("T", " ").replace("Z", "")}\n' + commit['commit']['message'].replace(':bug:', '🐛').replace( + ':sparkles:', '✨').replace(':memo:', '📝') + '\n' + if i >= 5: + break return result