From 62009e0a0f0e16a09163412b9a7e3f2977622e63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wuyi=E6=97=A0=E7=96=91?= <444835641@qq.com> Date: Sun, 12 Mar 2023 14:25:09 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E6=96=B0=E5=A2=9E`gs=E5=85=A8?= =?UTF-8?q?=E9=83=A8=E6=9B=B4=E6=96=B0`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GenshinUID/genshinuid_resin/__init__.py | 31 ++++++++-------- GenshinUID/genshinuid_update/__init__.py | 8 +++- .../genshinuid_update/draw_update_log.py | 37 +++++++++++++++---- GenshinUID/utils/error_reply.py | 4 ++ 4 files changed, 56 insertions(+), 24 deletions(-) diff --git a/GenshinUID/genshinuid_resin/__init__.py b/GenshinUID/genshinuid_resin/__init__.py index feda2903..0e188762 100644 --- a/GenshinUID/genshinuid_resin/__init__.py +++ b/GenshinUID/genshinuid_resin/__init__.py @@ -34,21 +34,22 @@ async def notice_job(): # 执行私聊推送 for bot_id in result: - bot = gss.active_bot[bot_id] - for user_id in result[bot_id]['direct']: - msg = result[bot_id]['direct'][user_id] - await bot.target_send(msg, 'direct', user_id, bot_id) - await asyncio.sleep(0.5) - logger.info('[推送检查] 私聊推送完成') - for gid in result[bot_id]['group']: - msg_list = [] - for user_id in result[bot_id]['group'][gid]: - msg_list.append(MessageSegment.at(user_id)) - msg = result[bot_id]['group'][gid][user_id] - msg_list.append(MessageSegment.text(msg)) - await bot.target_send(msg_list, 'group', gid, bot_id) - await asyncio.sleep(0.5) - logger.info('[推送检查] 群聊推送完成') + for BOT_ID in gss.active_bot: + bot = gss.active_bot[BOT_ID] + for user_id in result[bot_id]['direct']: + msg = result[bot_id]['direct'][user_id] + await bot.target_send(msg, 'direct', user_id, bot_id, '') + await asyncio.sleep(0.5) + logger.info('[推送检查] 私聊推送完成') + for gid in result[bot_id]['group']: + msg_list = [] + for user_id in result[bot_id]['group'][gid]: + msg_list.append(MessageSegment.at(user_id)) + msg = result[bot_id]['group'][gid][user_id] + msg_list.append(MessageSegment.text(msg)) + await bot.target_send(msg_list, 'group', gid, bot_id, '') + await asyncio.sleep(0.5) + logger.info('[推送检查] 群聊推送完成') @SV('查询体力').on_fullmatch(('每日', 'mr', '实时便笺', '便笺', '便签')) diff --git a/GenshinUID/genshinuid_update/__init__.py b/GenshinUID/genshinuid_update/__init__.py index 35fc3b19..5ced1f6f 100644 --- a/GenshinUID/genshinuid_update/__init__.py +++ b/GenshinUID/genshinuid_update/__init__.py @@ -3,9 +3,10 @@ from gsuid_core.bot import Bot from gsuid_core.gss import gss from gsuid_core.models import Event from gsuid_core.logger import logger +from gsuid_core.segment import MessageSegment -from .draw_update_log import draw_update_log_img from .restart import restart_message, restart_genshinuid +from .draw_update_log import get_all_update_log, draw_update_log_img @gss.on_bot_connect @@ -50,10 +51,13 @@ async def send_updatelog_msg(bot: Bot, ev: Event): await bot.send(im) -@SV('Core管理', pm=1).on_fullmatch(('gs更新', 'gs强制更新', 'gs强行强制更新')) +@SV('Core管理', pm=1).on_fullmatch(('gs更新', 'gs强制更新', 'gs强行强制更新', 'gs全部更新')) async def send_update_msg(bot: Bot, ev: Event): await bot.logger.info('[gs更新] 正在执行 ...') level = 2 + if '全部' in ev.command: + im = await get_all_update_log() + return await bot.send(MessageSegment.node(im)) if '强制' not in ev.command: level -= 1 if '强行' not in ev.command: diff --git a/GenshinUID/genshinuid_update/draw_update_log.py b/GenshinUID/genshinuid_update/draw_update_log.py index 6fbfe07e..cc0a7930 100644 --- a/GenshinUID/genshinuid_update/draw_update_log.py +++ b/GenshinUID/genshinuid_update/draw_update_log.py @@ -1,9 +1,10 @@ from pathlib import Path -from typing import Union +from typing import List, Union from PIL import Image, ImageDraw from .update import update_from_git +from ..utils.error_reply import UPDATE_HINT from ..utils.image.convert import convert_img from ..utils.image.image_tools import get_color_bg from ..utils.fonts.genshin_fonts import genshin_font_origin @@ -22,6 +23,33 @@ log_config = { log_map = {'✨': 'feat', '🐛': 'bug', '🍱': 'bento', '⚡️': 'zap', '🎨': 'art'} +async def get_all_update_log() -> List: + v4_repo_path = Path(__file__).parents[2] + core_repo_path = Path(__file__).parents[5] + log_list1 = await update_from_git(0, v4_repo_path, log_config, True) + log_list2 = await update_from_git(0, core_repo_path, log_config, True) + im = [] + if len(log_list1) == 0: + im.append('gsuid_v4更新失败!更多消息请查看控制台...以下为记录:') + im.append(UPDATE_HINT) + else: + im.append('gsuid_v4更新成功!') + im.append('最近更新记录如下:') + im.append(log_list1[0]) + if len(log_list1) >= 2: + im.append(log_list1[1]) + + if len(log_list2) == 0: + im.append('gsuid_core更新失败!更多消息请查看控制台...') + else: + im.append('gsuid_core更新成功!') + im.append(log_list2[0]) + if len(log_list2) >= 2: + im.append(log_list2[1]) + + return im + + async def draw_update_log_img( level: int = 0, repo_path: Union[str, Path, None] = None, @@ -29,12 +57,7 @@ async def draw_update_log_img( ) -> Union[bytes, str]: log_list = await update_from_git(level, repo_path, log_config, is_update) if len(log_list) == 0: - return ( - '更新失败!更多错误信息请查看控制台...\n ' - '>> 可以尝试使用\n ' - '>> [gs强制更新](危险)\n ' - '>> [gs强行强制更新](超级危险)!' - ) + return UPDATE_HINT log_title = Image.open(TEXT_PATH / 'log_title.png') diff --git a/GenshinUID/utils/error_reply.py b/GenshinUID/utils/error_reply.py index e986320d..5d279cea 100644 --- a/GenshinUID/utils/error_reply.py +++ b/GenshinUID/utils/error_reply.py @@ -12,6 +12,10 @@ VERIFY_HINT = '''出现验证码! 如未绑定CK: 可联系管理员使用[gs清除缓存]命令 ''' SK_HINT = '你还没有绑定过Stoken或者Stoken已失效~\n请加好友私聊Bot\n [扫码登陆] 或 [添加]后跟SK格式 以绑定SK' +UPDATE_HINT = '''更新失败!更多错误信息请查看控制台... +>> 可以尝试使用 +>> [gs强制更新](危险) +>> [gs强行强制更新](超级危险)!''' def get_error(retcode: Union[int, str]) -> str: