From 008c06682818587faec781d266ce22d703d4093b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=A3=E8=90=BD?= <34079036+jiluoQAQ@users.noreply.github.com> Date: Thu, 18 May 2023 22:27:26 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E2=9C=A8=E6=B7=B1=E6=B8=8A=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E5=AE=8C=E5=96=84=20(#38)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 深渊查询完善 * 🚨 `pre-commit-ci`修复格式错误 * 深渊查询完善 --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- StarRailUID/starrailuid_abyss/__init__.py | 18 ++-- .../starrailuid_abyss/draw_abyss_card.py | 87 ++++++++----------- StarRailUID/utils/mys_api.py | 4 +- 3 files changed, 53 insertions(+), 56 deletions(-) diff --git a/StarRailUID/starrailuid_abyss/__init__.py b/StarRailUID/starrailuid_abyss/__init__.py index 229e5d8..384d71e 100644 --- a/StarRailUID/starrailuid_abyss/__init__.py +++ b/StarRailUID/starrailuid_abyss/__init__.py @@ -31,11 +31,17 @@ async def send_srabyss_info(bot: Bot, ev: Event): schedule_type = '1' await bot.logger.info('[sr查询深渊信息]深渊期数: {}'.format(schedule_type)) - if ev.text in ['九', '十', '十一', '十二']: + if ev.text in ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十']: floor = ( - ev.text.replace('九', '9') - .replace('十一', '11') - .replace('十二', '12') + ev.text.replace('一', '1') + .replace('二', '2') + .replace('三', '3') + .replace('四', '4') + .replace('五', '5') + .replace('六', '6') + .replace('七', '7') + .replace('八', '8') + .replace('九', '9') .replace('十', '10') ) else: @@ -44,10 +50,10 @@ async def send_srabyss_info(bot: Bot, ev: Event): floor = int(floor) else: floor = None - + # print(floor) await bot.logger.info('[sr查询深渊信息]深渊层数: {}'.format(floor)) # data = GsCookie() # raw_abyss_data = await data.get_spiral_abyss_data(uid, schedule_type) # print(raw_abyss_data) - im = await draw_abyss_img(ev.user_id, uid, schedule_type) + im = await draw_abyss_img(ev.user_id, uid, floor, schedule_type) await bot.send(im) diff --git a/StarRailUID/starrailuid_abyss/draw_abyss_card.py b/StarRailUID/starrailuid_abyss/draw_abyss_card.py index f8e1f4f..ef3e5cc 100644 --- a/StarRailUID/starrailuid_abyss/draw_abyss_card.py +++ b/StarRailUID/starrailuid_abyss/draw_abyss_card.py @@ -1,6 +1,5 @@ -import asyncio from pathlib import Path -from typing import Union +from typing import Union, Optional from PIL import Image, ImageDraw from gsuid_core.logger import logger @@ -10,8 +9,6 @@ from .utils import get_icon from ..utils.convert import GsCookie from ..utils.image.convert import convert_img from ..sruid_utils.api.mys.models import AbyssAvatar - -# ) from ..utils.image.image_tools import get_qq_avatar, draw_pic_with_ring from ..utils.fonts.starrail_fonts import ( sr_font_22, @@ -21,10 +18,18 @@ from ..utils.fonts.starrail_fonts import ( sr_font_42, ) -# from ..utils.resource.download_url import download_file -# from ..utils.resource.generate_char_card import create_single_char_card -# from ..utils.resource.RESOURCE_PATH import ( -# CHAR_ICON_PATH, +abyss_list = { + '1': '琥珀恩赐其一', + '2': '琥珀恩赐其二', + '3': '琥珀恩赐其三', + '4': '琥珀恩赐其四', + '5': '琥珀恩赐其五', + '6': '琥珀恩赐其六', + '7': '琥珀恩赐其七', + '8': '琥珀恩赐其八', + '9': '琥珀恩赐其九', + '10': '琥珀恩赐其十', +} TEXT_PATH = Path(__file__).parent / 'texture2D' white_color = (255, 255, 255) @@ -134,6 +139,7 @@ async def _draw_floor_card( async def draw_abyss_img( qid: Union[str, int], uid: str, + floor: Optional[int] = None, schedule_type: str = '1', ) -> Union[bytes, str]: # 获取Cookies @@ -156,30 +162,21 @@ async def draw_abyss_img( # char_temp = {} # 获取查询者数据 - # if floor: - # floor = floor - 9 - # if floor < 0: - # return '楼层不能小于9层!' - # if len(raw_abyss_data['floors']) >= floor + 1: - # floors_data = raw_abyss_data['floors'][floor] - # else: - # return '你还没有挑战该层!' - # else: - # if len(raw_abyss_data['floors']) == 0: - # return '你还没有挑战本期深渊!\n可以使用[上期深渊]命令查询上期~' - # floors_data = raw_abyss_data['floors'][-1] - if raw_abyss_data['max_floor'] == '': - return '你还没有挑战本期深渊!\n可以使用[sr上期深渊]命令查询上期~' - # if floors_data['levels'][-1]['battles']: - # is_unfull = False - # else: - # is_unfull = True + if floor: + floor_num = 1 + if floor > 10: + return '楼层不能大于10层!' + if len(raw_abyss_data['all_floor_detail']) < floor: + return '你还没有挑战该层!' + else: + if raw_abyss_data['max_floor'] == '': + return '你还没有挑战本期深渊!\n可以使用[sr上期深渊]命令查询上期~' + floor_num = len(raw_abyss_data['all_floor_detail']) # 获取背景图片各项参数 based_w = 900 - floor_num = len(raw_abyss_data['all_floor_detail']) if floor_num >= 3: - based_h = 1227 + based_h = 2367 else: based_h = 657 + 570 * floor_num img = img_bg.copy() @@ -233,7 +230,6 @@ async def draw_abyss_img( 'lm', ) - task = [] for index_floor, level in enumerate(raw_abyss_data['all_floor_detail']): if index_floor >= 3: break @@ -279,28 +275,21 @@ async def draw_abyss_img( # ) # char_temp[char["id"]] = talent_num # break - task.append( - _draw_abyss_card( - char, - 0, # type: ignore - floor_pic, - index_char, - index_part, - ) + await _draw_abyss_card( + char, + 0, # type: ignore + floor_pic, + index_char, + index_part, ) - await asyncio.gather(*task) - task.clear() - task.append( - _draw_floor_card( - level_star, - floor_pic, - img, - index_floor, - floor_name, - round_num, - ) + await _draw_floor_card( + level_star, + floor_pic, + img, + index_floor, + floor_name, + round_num, ) - await asyncio.gather(*task) # title_data = { # '最强一击!': damage_rank[0], diff --git a/StarRailUID/utils/mys_api.py b/StarRailUID/utils/mys_api.py index 6cc2a70..0f869b5 100644 --- a/StarRailUID/utils/mys_api.py +++ b/StarRailUID/utils/mys_api.py @@ -197,6 +197,8 @@ class MysApi(_MysApi): 'CHALLENGE_INFO_URL', uid, params={ + 'isPrev': 'true', + 'need_all': 'true', 'role_id': uid, 'schedule_type': schedule_type, 'server': server_id, @@ -204,7 +206,7 @@ class MysApi(_MysApi): cookie=ck, header=self._HEADER, ) - print(data) + # print(data) if isinstance(data, Dict): data = cast(AbyssData, data['data']) return data From b59f3d9b063a81e677ae09137e6191b7147d30a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=A3=E8=90=BD?= <34079036+jiluoQAQ@users.noreply.github.com> Date: Thu, 18 May 2023 22:44:15 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E6=B7=B1=E6=B8=8A=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E5=AE=8C=E5=96=84=20(#39)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- StarRailUID/starrailuid_abyss/draw_abyss_card.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/StarRailUID/starrailuid_abyss/draw_abyss_card.py b/StarRailUID/starrailuid_abyss/draw_abyss_card.py index ef3e5cc..e08bf63 100644 --- a/StarRailUID/starrailuid_abyss/draw_abyss_card.py +++ b/StarRailUID/starrailuid_abyss/draw_abyss_card.py @@ -231,8 +231,14 @@ async def draw_abyss_img( ) for index_floor, level in enumerate(raw_abyss_data['all_floor_detail']): - if index_floor >= 3: - break + if floor: + if abyss_list[str(floor)] == level['name']: + index_floor = 0 + else: + continue + else: + if index_floor >= 3: + break floor_pic = Image.open(TEXT_PATH / 'floor_bg.png') level_star = level['star_num'] floor_name = level['name'] From ab70f84a469ab9fc96b8c4541e1cc5c2e467fdfd Mon Sep 17 00:00:00 2001 From: lulu666lulu <69200009+lulu666lulu@users.noreply.github.com> Date: Thu, 18 May 2023 22:51:37 +0800 Subject: [PATCH 3/6] update header (#40) --- StarRailUID/utils/mys_api.py | 1 + 1 file changed, 1 insertion(+) diff --git a/StarRailUID/utils/mys_api.py b/StarRailUID/utils/mys_api.py index 0f869b5..03759e8 100644 --- a/StarRailUID/utils/mys_api.py +++ b/StarRailUID/utils/mys_api.py @@ -45,6 +45,7 @@ class MysApi(_MysApi): asyncio.run(self.get_fp()) self._HEADER['x-rpc-device_id'] = self.device_id self._HEADER['x-rpc-page'] = '3.1.3_#/rpg' + self._HEADER['x-rpc-challenge_game'] = '6' async def create_qrcode_url(self) -> Union[Dict, int]: device_id: str = ''.join(random.choices(ascii_letters + digits, k=64)) From f8428cd82dca289d87bb9dcda29d68cf04a8bf1f Mon Sep 17 00:00:00 2001 From: RBAmeto <46624927+RBAmeto@users.noreply.github.com> Date: Fri, 19 May 2023 09:31:50 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=E5=BE=AA=E7=8E=AF=E6=9C=AA=E5=85=B3=E9=97=AD=E9=97=AE=E9=A2=98?= =?UTF-8?q?=20(#41)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- StarRailUID/utils/mys_api.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/StarRailUID/utils/mys_api.py b/StarRailUID/utils/mys_api.py index 03759e8..2979f13 100644 --- a/StarRailUID/utils/mys_api.py +++ b/StarRailUID/utils/mys_api.py @@ -6,6 +6,7 @@ import asyncio from string import digits, ascii_letters from typing import Dict, Union, Optional, cast +from gsuid_core.logger import logger from gsuid_core.utils.api.mys_api import _MysApi from gsuid_core.utils.api.mys.models import MysSign, SignInfo, SignList from gsuid_core.utils.api.mys.tools import ( @@ -42,7 +43,14 @@ class MysApi(_MysApi): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - asyncio.run(self.get_fp()) + loop = asyncio.new_event_loop() + asyncio.set_event_loop(loop) + try: + device_fp = loop.run_until_complete(self.get_fp()) + self._HEADER['x-rpc-device_fp'] = device_fp + finally: + loop.run_until_complete(loop.shutdown_asyncgens()) + loop.close() self._HEADER['x-rpc-device_id'] = self.device_id self._HEADER['x-rpc-page'] = '3.1.3_#/rpg' self._HEADER['x-rpc-challenge_game'] = '6' @@ -316,16 +324,14 @@ class MysApi(_MysApi): header=HEADER, data=body, ) - if res["retcode"] != 0: - print("获取fp连接失败") - print(res) - self._HEADER['x-rpc-device_fp'] = random_hex(13).lower() + if not isinstance(res, Dict): + logger.error(f"获取fp连接失败{res}") + return random_hex(13).lower() elif res["data"]["code"] != 200: - print("获取fp参数不正确") - print(res["data"]["msg"]) - self._HEADER['x-rpc-device_fp'] = random_hex(13).lower() + logger.error(f"获取fp参数不正确{res['data']['msg']}") + return random_hex(13).lower() else: - self._HEADER['x-rpc-device_fp'] = res["data"]["device_fp"] + return res["data"]["device_fp"] mys_api = MysApi() From 3eea84650316558a9a30e89f57432ced68b68972 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98KimigaiiWuyi=E2=80=99?= <444835641@qq.com> Date: Fri, 19 May 2023 10:38:02 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=F0=9F=93=9D=20=E6=9B=B4=E6=96=B0Readme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7cc96c7..49fae0e 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,8 @@ > > **如果已经是最新版本的`gsuid_core`, 可以直接对bot发送`core安装插件starrail`,然后重启core以应用安装** > +> 如使用命令缺失素材可尝试使用命令`sr下载全部资源` +> > 支持NoneBot2 & HoshinoBot & ZeroBot的星穹铁道Bot插件 > > 🚧插件目前还在施工中,可以使用,功能快速迭代中...🚧 @@ -40,7 +42,11 @@

-以及自动签到 & 体力推送等.. +
查询深渊 - 命令: sr查询深渊 & sr深渊

+ +

+ +以及自动签到 & 体力推送 & WIKI & 攻略图等.. ## 丨其他 From cf740aa8acd2bbb124f8b0a00caa328a16e5d414 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98KimigaiiWuyi=E2=80=99?= <444835641@qq.com> Date: Fri, 19 May 2023 11:04:51 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=F0=9F=93=9D=20=E6=9B=B4=E6=96=B0=E6=94=AF?= =?UTF-8?q?=E6=8C=81Bot=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 49fae0e..5efd934 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ > > 如使用命令缺失素材可尝试使用命令`sr下载全部资源` > -> 支持NoneBot2 & HoshinoBot & ZeroBot的星穹铁道Bot插件 +> 支持NoneBot2 & HoshinoBot & ZeroBot & YunzaiBot的星穹铁道Bot插件 > > 🚧插件目前还在施工中,可以使用,功能快速迭代中...🚧