From 54830d5f99ac2544eb4cca542da062333541747c Mon Sep 17 00:00:00 2001 From: KimigaiiWuyi <444835641@qq.com> Date: Tue, 23 Apr 2024 03:28:42 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20`ba=E6=80=BB=E5=8A=9B=E6=88=98`?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=9F=A5=E7=9C=8B=E9=83=A8=E5=88=86=E9=9A=BE?= =?UTF-8?q?=E5=BA=A6=E6=8C=91=E6=88=98=E4=BA=BA=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BlueArchiveUID/bauid_raid/get_rank_data.py | 14 +++++++++ BlueArchiveUID/utils/api/api.py | 1 + BlueArchiveUID/utils/api/models.py | 13 ++++++++ BlueArchiveUID/utils/api/request.py | 36 ++++++++++++++++++++-- 4 files changed, 62 insertions(+), 2 deletions(-) diff --git a/BlueArchiveUID/bauid_raid/get_rank_data.py b/BlueArchiveUID/bauid_raid/get_rank_data.py index 5ac23ba..92dca8a 100644 --- a/BlueArchiveUID/bauid_raid/get_rank_data.py +++ b/BlueArchiveUID/bauid_raid/get_rank_data.py @@ -27,6 +27,20 @@ async def get_ranking_from_xtzx( im_list.append(f'【{SERVER_MAP[server_id]}数据】:') data = await xtzx_api.get_xtzx_raid_chart(season, server_id) top_data = await xtzx_api.get_xtzx_raid_top(season, server_id) + person_data = await xtzx_api.get_xtzx_raid_chart_person(season, server_id) + person_rank_data = await xtzx_api.get_xtzx_raid_person(season, server_id) + + if person_data is not None: + person_num = person_data['value'][-1] + im_list.append(f'参与总人数: {person_num:,}') + + if person_rank_data is not None: + if len(person_rank_data) >= 1: + for i in person_rank_data[:2]: + im_list.append(f'{i["hard"]}人数: {i["rank"]}') + + im_list.append('\n') + if top_data is not None: for ix, i in enumerate(['🥇', '🥈', '🥉']): if len(top_data) > ix: diff --git a/BlueArchiveUID/utils/api/api.py b/BlueArchiveUID/utils/api/api.py index c026c67..09a641b 100644 --- a/BlueArchiveUID/utils/api/api.py +++ b/BlueArchiveUID/utils/api/api.py @@ -14,6 +14,7 @@ XTZX_RAID_TOP = XTZX_API + '/api/v2/rank/list_top' XTZX_RAID_CHART_PERSON = XTZX_API + '/api/v2/rank/season/lastRank/charts' XTZX_RAID_CHART = XTZX_API + '/raid/new/charts/{}?s={}' +XTZX_RAID_RANK_PERSON = XTZX_API + '/api/v2/rank/list_by_last_rank' XTZX_FRIEND_DATA = XTZX_API + '/api/friends/find' XTZX_FRIEND_REFRESH = XTZX_API + '/api/friends/refresh' XTZX_ASSIST = XTZX_API + '/api/friends/assist_query' diff --git a/BlueArchiveUID/utils/api/models.py b/BlueArchiveUID/utils/api/models.py index 342953d..b063136 100644 --- a/BlueArchiveUID/utils/api/models.py +++ b/BlueArchiveUID/utils/api/models.py @@ -104,3 +104,16 @@ class RankResp(TypedDict): totalData: int records: List[Record] lastPage: bool + + +class LabelInfo(TypedDict): + dataType: int + tryNumber: int + + +class DataItem(TypedDict): + rank: int + bestRankingPoint: int + hard: str + battleTime: str + labelInfo: List[LabelInfo] diff --git a/BlueArchiveUID/utils/api/request.py b/BlueArchiveUID/utils/api/request.py index 79ec22b..91cf0e0 100644 --- a/BlueArchiveUID/utils/api/request.py +++ b/BlueArchiveUID/utils/api/request.py @@ -4,7 +4,7 @@ from aiohttp import FormData, TCPConnector, ClientSession, ContentTypeError from ..ba_config import ba_config -from .models import RankResp, FriendData +from .models import DataItem, RankResp, FriendData from .api import ( ARONA_URL, BATTLE_URL, @@ -15,6 +15,7 @@ XTZX_RAID_CHART, XTZX_FRIEND_DATA, XTZX_FRIEND_RANK, + XTZX_RAID_RANK_PERSON, XTZX_RAID_CHART_PERSON, ) @@ -179,6 +180,31 @@ async def get_xtzx_raid_ranking( if isinstance(data, Dict) and 'code' in data and data['code'] == 200: return data + async def get_xtzx_raid_person( + self, + season: Union[str, int, None] = None, + server_id: Union[str, int] = 1, + data_type: int = 0, + try_number: int = 0, + ): + if season is None: + now_season = await self.get_now_season_data() + if now_season is None: + return None + season = int(now_season['season']) + data = await self._ba_request( + XTZX_RAID_RANK_PERSON, + 'POST', + json={ + 'server': int(server_id), + 'season': int(season), + "dataType": data_type, + "tryNumber": try_number, + }, + ) + if isinstance(data, Dict) and 'code' in data and data['code'] == 200: + return cast(List[DataItem], data['data']) + async def get_xtzx_friend_data( self, friend_code: str, @@ -268,6 +294,12 @@ async def _ba_request( raw_data = await resp.json() except ContentTypeError: _raw_data = await resp.text() - raw_data = {'retcode': -999, 'data': _raw_data} + raw_data = {'code': -999, 'data': _raw_data} logger.debug(raw_data) + if 'code' in raw_data: + if raw_data['code'] != 0 and raw_data['code'] != 200: + logger.error( + f'[BaUID] 访问 {url} 失败, 错误码: {raw_data["retcode"]}' + f', 错误返回: {raw_data}' + ) return raw_data