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