From 60b7219bfda9c85f68a890363fedc46891b4c7c7 Mon Sep 17 00:00:00 2001 From: CMHopeSunshine <277073121@qq.com> Date: Thu, 22 Dec 2022 19:54:34 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20`=E6=8A=BD=E5=8D=A1=E8=AE=B0?= =?UTF-8?q?=E5=BD=95`=E5=A2=9E=E5=8A=A0=E6=8A=BD=E5=8D=A1=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LittlePaimon/plugins/Paimon_Bind/__init__.py | 73 ++++++++++++------- .../plugins/Paimon_Gacha_Log/__init__.py | 2 +- LittlePaimon/plugins/Paimon_Gacha_Log/draw.py | 11 ++- .../plugins/Paimon_Gacha_Log/models.py | 8 ++ 4 files changed, 66 insertions(+), 28 deletions(-) diff --git a/LittlePaimon/plugins/Paimon_Bind/__init__.py b/LittlePaimon/plugins/Paimon_Bind/__init__.py index 495c742..dc8817f 100644 --- a/LittlePaimon/plugins/Paimon_Bind/__init__.py +++ b/LittlePaimon/plugins/Paimon_Bind/__init__.py @@ -15,6 +15,12 @@ from LittlePaimon.database import LastQuery, PrivateCookie, PublicCookie, Charac from LittlePaimon.utils import logger, NICKNAME from LittlePaimon.utils.api import get_bind_game_info, get_stoken_by_login_ticket, get_cookie_token_by_stoken +try: + from .get_cookie import * +except ImportError: + bind_tips = '获取cookie的教程:\ndocs.qq.com/doc/DQ3JLWk1vQVllZ2Z1\n获取后,使用[ysb cookie]指令绑定' + bind_tips_web = '获取cookie的教程:\ndocs.qq.com/doc/DQ3JLWk1vQVllZ2Z1\n获取后,使用[ysb cookie]指令绑定或前往{cookie_web_url}网页添加绑定' + __plugin_meta__ = PluginMetadata( name='原神绑定', description='原神绑定信息', @@ -44,13 +50,15 @@ delete_ck = on_command('删除ck', aliases={'删除cookie'}, priority=1, block=T 'pm_usage': '删除ck[uid|全部]', 'pm_priority': 3 }) -ysbca = on_command('校验所有ck', aliases={'校验所有cookie', '校验所有绑定'}, priority=1, block=True, permission=SUPERUSER, state={ - 'pm_name': '校验所有ck', - 'pm_description': '校验所有cookie情况,仅超级管理员可用', - 'pm_usage': '校验所有ck', - 'pm_priority': 4 -}) -pck = on_command('添加公共cookie', aliases={'添加pck', '添加公共ck', 'add_pck'}, permission=SUPERUSER, block=True, priority=1, +ysbca = on_command('校验所有ck', aliases={'校验所有cookie', '校验所有绑定'}, priority=1, block=True, + permission=SUPERUSER, state={ + 'pm_name': '校验所有ck', + 'pm_description': '校验所有cookie情况,仅超级管理员可用', + 'pm_usage': '校验所有ck', + 'pm_priority': 4 + }) +pck = on_command('添加公共cookie', aliases={'添加pck', '添加公共ck', 'add_pck'}, permission=SUPERUSER, block=True, + priority=1, state={ 'pm_name': '添加公共ck', 'pm_description': '添加公共cookie,仅超级管理员可用', @@ -77,12 +85,14 @@ async def _(event: MessageEvent, msg: Message = CommandArg()): at_sender=True) if msg: if msg in {'cookie', 'Cookie', 'ck', 'CK'}: - await ysb.finish(f'你在和{NICKNAME}开玩笑嘛?请看教程获取Cookie:\ndocs.qq.com/doc/DQ3JLWk1vQVllZ2Z1', at_sender=True) + await ysb.finish(f'你在和{NICKNAME}开玩笑嘛?请看教程获取Cookie:\ndocs.qq.com/doc/DQ3JLWk1vQVllZ2Z1', + at_sender=True) if mys_id := re.search(r'(?:(?:login_uid|account_mid|account_id|stmid|ltmid|stuid|ltuid)(?:_v2)?)=(\d+)', msg): mys_id = mys_id[1] else: - await ysb.finish('Cookie无效,缺少account_id、login_uid或stuid字段\n获取cookie的教程:\ndocs.qq.com/doc/DQ3JLWk1vQVllZ2Z1', - at_sender=True) + await ysb.finish( + 'Cookie无效,缺少account_id、login_uid或stuid字段\n获取cookie的教程:\ndocs.qq.com/doc/DQ3JLWk1vQVllZ2Z1', + at_sender=True) cookie_token_match = re.search(r'(?:cookie_token|cookie_token_v2)=([0-9a-zA-Z]+)', msg) cookie_token = cookie_token_match[1] if cookie_token_match else None login_ticket_match = re.search(r'(?:login_ticket|login_ticket_v2)=([0-9a-zA-Z]+)', msg) @@ -96,30 +106,37 @@ async def _(event: MessageEvent, msg: Message = CommandArg()): # 如果有stoken但没有cookie_token,就通过stoken获取cookie_token cookie_token = await get_cookie_token_by_stoken(stoken, mys_id) if not cookie_token: - await ysb.finish('Cookie无效,缺少cookie_token或login_ticket字段\n获取cookie的教程:\ndocs.qq.com/doc/DQ3JLWk1vQVllZ2Z1', at_sender=True) + await ysb.finish( + 'Cookie无效,缺少cookie_token或login_ticket字段\n获取cookie的教程:\ndocs.qq.com/doc/DQ3JLWk1vQVllZ2Z1', + at_sender=True) if game_info := await get_bind_game_info(f'account_id={mys_id};cookie_token={cookie_token}', mys_id): if not game_info['list']: await ysb.finish('该账号尚未绑定任何游戏,请确认账号无误~', at_sender=True) - if not (genshin_games := [{'uid': game['game_role_id'], 'nickname': game['nickname']} for game in game_info['list'] if game['game_id'] == 2]): + if not ( + genshin_games := [{'uid': game['game_role_id'], 'nickname': game['nickname']} for game in game_info['list'] + if game['game_id'] == 2]): await ysb.finish('该账号尚未绑定原神,请确认账号无误~', at_sender=True) await LastQuery.update_or_create(user_id=str(event.user_id), - defaults={'uid': genshin_games[0]['uid'], 'last_time': datetime.datetime.now()}) + defaults={'uid': genshin_games[0]['uid'], + 'last_time': datetime.datetime.now()}) send_msg = '' for info in genshin_games: send_msg += f'{info["nickname"]}({info["uid"]}) ' await PrivateCookie.update_or_create(user_id=str(event.user_id), uid=info['uid'], mys_id=mys_id, - defaults={'cookie': f'account_id={mys_id};cookie_token={cookie_token}', - 'stoken': f'stuid={mys_id};stoken={stoken};' if stoken else None}) - await ysb.finish(f'玩家{send_msg.strip()}绑定Cookie{"和Stoken" if stoken else ""}成功{"" if stoken else "当未能绑定Stoken"}' - f'{",当前非私聊对话建议将Cookie撤回哦" if not isinstance(event, PrivateMessageEvent) else ""}', at_sender=True) + defaults={ + 'cookie': f'account_id={mys_id};cookie_token={cookie_token}', + 'stoken': f'stuid={mys_id};stoken={stoken};' if stoken else None}) + await ysb.finish( + f'玩家{send_msg.strip()}绑定Cookie{"和Stoken" if stoken else ""}成功{"" if stoken else "当未能绑定Stoken"}{"" if isinstance(event, PrivateMessageEvent) else ",当前非私聊对话建议将Cookie撤回哦"}', + at_sender=True, + ) else: await ysb.finish( 'Cookie无效,请确认是否已过期\n获取cookie的教程:\ndocs.qq.com/doc/DQ3JLWk1vQVllZ2Z1', at_sender=True) elif config.CookieWeb_enable: await ysb.finish( - f'获取cookie的教程:\ndocs.qq.com/doc/DQ3JLWk1vQVllZ2Z1\n获取后,使用[ysb cookie]指令绑定或前往{config.CookieWeb_url}网页添加绑定', - at_sender=True) + bind_tips.format(cookie_web_url=config.CookieWeb_url), at_sender=True) else: await ysb.finish('获取cookie的教程:\ndocs.qq.com/doc/DQ3JLWk1vQVllZ2Z1\n获取后,使用[ysb cookie]指令绑定', at_sender=True) @@ -142,7 +159,8 @@ async def _(event: MessageEvent): await ysbc.finish(msg.strip(), at_sender=True) elif uid: - await ysbc.finish(f'{event.sender.card or event.sender.nickname}当前已绑定uid{uid.uid},但未绑定cookie', at_sender=True) + await ysbc.finish(f'{event.sender.card or event.sender.nickname}当前已绑定uid{uid.uid},但未绑定cookie', + at_sender=True) else: await ysbc.finish(f'{event.sender.card or event.sender.nickname}当前无绑定信息', at_sender=True) @@ -191,7 +209,8 @@ async def _(event: MessageEvent): await cookie.delete() await sleep(1) for cookie in public_cookies: - if mys_id := re.search(r'(?:(?:login_uid|account_mid|account_id|stmid|ltmid|stuid|ltuid)(?:_v2)?)=(\d+)', cookie.cookie): + if mys_id := re.search(r'(?:(?:login_uid|account_mid|account_id|stmid|ltmid|stuid|ltuid)(?:_v2)?)=(\d+)', + cookie.cookie): mys_id = mys_id[1] if not await get_bind_game_info(cookie.cookie, mys_id): useless_public.append(str(cookie.id)) @@ -217,8 +236,9 @@ async def _(event: MessageEvent, msg: Message = CommandArg()): if mys_id := re.search(r'(?:(?:login_uid|account_mid|account_id|stmid|ltmid|stuid|ltuid)(?:_v2)?)=(\d+)', msg): mys_id = mys_id[1] else: - await pck.finish('Cookie无效,缺少account_id、login_uid或stuid字段\n获取cookie的教程:\ndocs.qq.com/doc/DQ3JLWk1vQVllZ2Z1', - at_sender=True) + await pck.finish( + 'Cookie无效,缺少account_id、login_uid或stuid字段\n获取cookie的教程:\ndocs.qq.com/doc/DQ3JLWk1vQVllZ2Z1', + at_sender=True) cookie_token_match = re.search(r'(?:cookie_token|cookie_token_v2)=([0-9a-zA-Z]+)', msg) cookie_token = cookie_token_match[1] if cookie_token_match else None login_ticket_match = re.search(r'(?:login_ticket|login_ticket_v2)=([0-9a-zA-Z]+)', msg) @@ -232,14 +252,17 @@ async def _(event: MessageEvent, msg: Message = CommandArg()): # 如果有stoken但没有cookie_token,就通过stoken获取cookie_token cookie_token = await get_cookie_token_by_stoken(stoken, mys_id) if not cookie_token: - await pck.finish('Cookie无效,缺少cookie_token或login_ticket字段\n获取cookie的教程:\ndocs.qq.com/doc/DQ3JLWk1vQVllZ2Z1', at_sender=True) + await pck.finish( + 'Cookie无效,缺少cookie_token或login_ticket字段\n获取cookie的教程:\ndocs.qq.com/doc/DQ3JLWk1vQVllZ2Z1', + at_sender=True) if await get_bind_game_info(f'account_id={mys_id};cookie_token={cookie_token}', mys_id): ck = await PublicCookie.create(cookie=f'account_id={mys_id};cookie_token={cookie_token}') logger.info('原神Cookie', f'{ck.id}号公共cookie', None, '添加成功', True) await pck.finish(f'成功添加{ck.id}号公共cookie', at_sender=True) else: logger.info('原神Cookie', '公共cookie', None, '添加失败,cookie已失效', True) - await pck.finish('Cookie无效,请确认是否已过期\n获取cookie的教程:\ndocs.qq.com/doc/DQ3JLWk1vQVllZ2Z1', at_sender=True) + await pck.finish('Cookie无效,请确认是否已过期\n获取cookie的教程:\ndocs.qq.com/doc/DQ3JLWk1vQVllZ2Z1', + at_sender=True) else: await pck.finish('获取cookie的教程:\ndocs.qq.com/doc/DQ3JLWk1vQVllZ2Z1\n获取到后,用[添加公共ck cookie]指令添加', at_sender=True) diff --git a/LittlePaimon/plugins/Paimon_Gacha_Log/__init__.py b/LittlePaimon/plugins/Paimon_Gacha_Log/__init__.py index 45d5eaa..1fb4e51 100644 --- a/LittlePaimon/plugins/Paimon_Gacha_Log/__init__.py +++ b/LittlePaimon/plugins/Paimon_Gacha_Log/__init__.py @@ -58,7 +58,7 @@ async def _(event: MessageEvent, player=CommandPlayer(1)): await update_log.send(f'开始为UID{player[0].uid}更新抽卡记录,请稍候...') try: result = await get_gacha_log_data(player[0].user_id, player[0].uid) - await update_log.send(result, at_sender=True) + await update_log.send(result or 'Stoken已失效,请重新绑定之后再更新', at_sender=True) except Exception as e: logger.info('原神抽卡记录', f'➤➤更新抽卡记录时出现错误:{e}') await update_log.send(f'更新抽卡记录时出现错误:{e}') diff --git a/LittlePaimon/plugins/Paimon_Gacha_Log/draw.py b/LittlePaimon/plugins/Paimon_Gacha_Log/draw.py index ab8fe39..32bcb74 100644 --- a/LittlePaimon/plugins/Paimon_Gacha_Log/draw.py +++ b/LittlePaimon/plugins/Paimon_Gacha_Log/draw.py @@ -78,7 +78,11 @@ async def detail_avatar(info: FiveStarItem): return bg -async def draw_pool_detail(pool_name: str, data: List[FiveStarItem], total_count: int, not_out: int) -> Optional[ +async def draw_pool_detail(pool_name: str, + data: List[FiveStarItem], + total_count: int, + not_out: int, + record_time: Tuple[datetime.datetime, datetime.datetime]) -> Optional[ PMImage]: if not data: return None @@ -88,6 +92,8 @@ async def draw_pool_detail(pool_name: str, data: List[FiveStarItem], total_count await img.paste(await load_image(RESOURCE_BASE_PATH / 'general' / 'line.png'), (0, 0)) pool_type = pool_name[:2] await img.text(f'{pool_type}卡池', 25, 11, fm.get('hywh', 30), 'white') + await img.text(f'{record_time[0].strftime("%Y-%m-%d %H:%M")}~{record_time[1].strftime("%Y-%m-%d %H:%M")}', 990, 15, + fm.get('bahnschrift_regular', 30), '#252525', 'right') # 数据 await img.text('平均出货', 174, 137, fm.get('hywh', 24), (24, 24, 24, 102)) ave = round((total_count - not_out) / len(data), 2) @@ -180,6 +186,7 @@ async def draw_gacha_log(user_id: str, uid: str, nickname: Optional[str], signat await img.text(f'UID{uid}', 165, 103, fm.get('bahnschrift_regular', 48, 'Regular'), '#252525') data5, data4, data_not = gacha_log.get_statistics() + record_time = gacha_log.get_record_time() # 数据总览 await img.paste(line, (36, 181)) await img.text('数据总览', 60, 192, fm.get('hywh', 30), 'white') @@ -218,7 +225,7 @@ async def draw_gacha_log(user_id: str, uid: str, nickname: Optional[str], signat now_height = 525 for pool_name, data in data5.items(): pool_detail_img = await draw_pool_detail(pool_name, data, len(gacha_log.item_list[pool_name]), - data_not[pool_name]) + data_not[pool_name], record_time[pool_name]) if pool_detail_img: await img.paste(pool_detail_img, (36, now_height)) now_height += pool_detail_img.height diff --git a/LittlePaimon/plugins/Paimon_Gacha_Log/models.py b/LittlePaimon/plugins/Paimon_Gacha_Log/models.py index f2f4177..8492048 100644 --- a/LittlePaimon/plugins/Paimon_Gacha_Log/models.py +++ b/LittlePaimon/plugins/Paimon_Gacha_Log/models.py @@ -46,6 +46,14 @@ class GachaLogInfo(BaseModel): '新手祈愿': [], } + def get_record_time(self) -> Dict[str, Tuple[datetime.datetime, datetime.datetime]]: + return { + '角色祈愿': (self.item_list['角色祈愿'][0].time, self.item_list['角色祈愿'][-1].time) if self.item_list['角色祈愿'] else (None, None), + '武器祈愿': (self.item_list['武器祈愿'][0].time, self.item_list['武器祈愿'][-1].time) if self.item_list['武器祈愿'] else (None, None), + '常驻祈愿': (self.item_list['常驻祈愿'][0].time, self.item_list['常驻祈愿'][-1].time) if self.item_list['常驻祈愿'] else (None, None), + '新手祈愿': (self.item_list['新手祈愿'][0].time, self.item_list['新手祈愿'][-1].time) if self.item_list['新手祈愿'] else (None, None) + } + def get_statistics(self) -> Tuple[Dict[str, List[FiveStarItem]], Dict[str, FourStarItem], Dict[str, int]]: gacha_data_five: Dict[str, List[FiveStarItem]] = { '角色祈愿': [],