Skip to content

Commit

Permalink
ba总力战支持查看部分难度挑战人数
Browse files Browse the repository at this point in the history
  • Loading branch information
KimigaiiWuyi committed Apr 22, 2024
1 parent 954e0e5 commit 54830d5
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
14 changes: 14 additions & 0 deletions BlueArchiveUID/bauid_raid/get_rank_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions BlueArchiveUID/utils/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
13 changes: 13 additions & 0 deletions BlueArchiveUID/utils/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
36 changes: 34 additions & 2 deletions BlueArchiveUID/utils/api/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -15,6 +15,7 @@
XTZX_RAID_CHART,
XTZX_FRIEND_DATA,
XTZX_FRIEND_RANK,
XTZX_RAID_RANK_PERSON,
XTZX_RAID_CHART_PERSON,
)

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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

0 comments on commit 54830d5

Please sign in to comment.