diff --git a/gsuid_core/bot.py b/gsuid_core/bot.py index e9ab512..d6eb3ec 100644 --- a/gsuid_core/bot.py +++ b/gsuid_core/bot.py @@ -128,9 +128,16 @@ class Bot: ] = None, unsuported_platform: bool = False, timeout: float = 60, + sep: str = ' / ', ): return await self.receive_resp( - reply, option_list, unsuported_platform, True, True, timeout + reply, + option_list, + unsuported_platform, + True, + True, + timeout, + sep=sep, ) async def send_option( @@ -142,9 +149,10 @@ class Bot: Union[List[str], List[Button], List[List[str]], List[List[Button]]] ] = None, unsuported_platform: bool = False, + sep: str = ' / ', ): return await self.receive_resp( - reply, option_list, unsuported_platform, False, False + reply, option_list, unsuported_platform, False, False, sep=sep ) async def receive_resp( @@ -159,6 +167,7 @@ class Bot: is_mutiply: bool = False, is_recive: bool = True, timeout: float = 60, + sep: str = ' / ', ) -> Optional[Event]: if option_list: if reply is None: @@ -200,7 +209,7 @@ class Bot: _reply.append( MessageSegment.text( - '\n请输入以下命令之一:\n' + ' / '.join(_options) + '\n请输入以下命令之一:\n' + sep.join(_options) ) ) await self.send(_reply) diff --git a/gsuid_core/plugins/core_command/user_login/__init__.py b/gsuid_core/plugins/core_command/user_login/__init__.py index f1b95fa..d99dea7 100644 --- a/gsuid_core/plugins/core_command/user_login/__init__.py +++ b/gsuid_core/plugins/core_command/user_login/__init__.py @@ -4,6 +4,7 @@ from typing import Dict from gsuid_core.sv import SV from gsuid_core.bot import Bot from gsuid_core.models import Event +from gsuid_core.message_models import Button from gsuid_core.utils.api.mys_api import mys_api from gsuid_core.utils.database.models import GsUser from gsuid_core.utils.cookie_manager.qrlogin import qrcode_login @@ -33,20 +34,46 @@ async def send_refresh_ck_msg(bot: Bot, ev: Event): await bot.send(im) +async def _send_help(bot: Bot, im): + p = Button('🔍查询信息', '查询') + q = Button('💠查询探索度', '查询探索') + r = Button('💠查询收集度', '查询收集') + t = Button('🌌查询深渊', '查询深渊') + s = Button('✨查询体力', '每日') + u = Button('🆚查询七圣', '七圣召唤') + v = Button('✉原石札记', '原石札记') + x = Button('⏱注册时间', '原神注册时间') + y = Button('💗抽卡记录', '抽卡记录') + await bot.send_option( + im, + [ + [p, q, r], + [t, s, u], + [v, x, y], + ], + ) + + @sv_core_user_qrcode_login.on_fullmatch(('扫码登陆', '扫码登录')) async def send_qrcode_login(bot: Bot, ev: Event): await bot.logger.info('开始执行[扫码登陆]') im = await qrcode_login(bot, ev, ev.user_id) if not im: return - im = await deal_ck(ev.bot_id, im, ev.user_id) - await bot.send(im) + im, status = await deal_ck(ev.bot_id, im, ev.user_id) + if status: + await _send_help(bot, im) + else: + await bot.send(im) @sv_core_user_addck.on_prefix(('添加')) async def send_add_ck_msg(bot: Bot, ev: Event): - im = await deal_ck(ev.bot_id, ev.text, ev.user_id) - await bot.send(im) + im, status = await deal_ck(ev.bot_id, ev.text, ev.user_id) + if status: + await _send_help(bot, im) + else: + await bot.send(im) @sv_core_user_addck.on_prefix(('mys设备登录')) diff --git a/gsuid_core/utils/cookie_manager/add_ck.py b/gsuid_core/utils/cookie_manager/add_ck.py index 90b9068..32f86a3 100644 --- a/gsuid_core/utils/cookie_manager/add_ck.py +++ b/gsuid_core/utils/cookie_manager/add_ck.py @@ -1,5 +1,5 @@ from pathlib import Path -from typing import Dict, List +from typing import Dict, List, Tuple from http.cookies import SimpleCookie from PIL import Image @@ -89,21 +89,26 @@ async def refresh_ck_by_uid_list(bot_id: str, uid_dict: Dict): async def deal_ck(bot_id: str, mes: str, user_id: str, mode: str = 'PIC'): im = await _deal_ck(bot_id, mes, user_id) + img, status = await _deal_ck_to_pic(im) if mode == 'PIC': - im = await _deal_ck_to_pic(im) - return im + return img, status + else: + return im, status -async def _deal_ck_to_pic(im: str) -> bytes: +async def _deal_ck_to_pic(im: str) -> Tuple[bytes, bool]: ok_num = im.count('成功') if ok_num < 1: status_pic = pic_path / 'ck_no.png' + status = False elif ok_num < 2: status_pic = pic_path / 'ck_ok.png' + status = False else: status_pic = pic_path / 'all_ok.png' + status = True img = Image.open(status_pic).convert('RGB') - return await convert_img(img) + return await convert_img(img), status async def get_account_id(simp_dict: SimpleCookie) -> str: diff --git a/gsuid_core/utils/error_reply.py b/gsuid_core/utils/error_reply.py index 6949a1d..8f0120f 100644 --- a/gsuid_core/utils/error_reply.py +++ b/gsuid_core/utils/error_reply.py @@ -66,9 +66,11 @@ def get_error_type(retcode: Union[int, str]) -> str: return 'Api错误' -async def get_error_img(retcode: Union[int, str]) -> Union[bytes, str]: +async def get_error_img( + retcode: Union[int, str], force_image: bool = False +) -> Union[bytes, str]: error_message = get_error(retcode) - if is_pic_error: + if is_pic_error or force_image: error_type = get_error_type(retcode) return await draw_error_img(retcode, error_message, error_type) else: diff --git a/gsuid_core/utils/image/image_tools.py b/gsuid_core/utils/image/image_tools.py index e8f6625..82243fa 100644 --- a/gsuid_core/utils/image/image_tools.py +++ b/gsuid_core/utils/image/image_tools.py @@ -14,6 +14,24 @@ TEXT_PATH = Path(__file__).parent / 'texture2d' BG_PATH = Path(__file__).parents[1] / 'default_bg' +async def shift_image_hue(img: Image.Image, angle: float = 30) -> Image.Image: + alpha = img.getchannel('A') + img = img.convert('HSV') + + pixels = img.load() + hue_shift = angle + + for y in range(img.height): + for x in range(img.width): + h, s, v = pixels[x, y] + h = (h + hue_shift) % 360 + pixels[x, y] = (h, s, v) + + img = img.convert('RGBA') + img.putalpha(alpha) + return img + + async def get_pic(url, size: Optional[Tuple[int, int]] = None) -> Image.Image: """ 从网络获取图片, 格式化为RGBA格式的指定尺寸