Support starrail user base info

This commit is contained in:
omg-xtao 2023-05-17 16:06:52 +08:00 committed by GitHub
parent 88466950fe
commit dea36a405f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 2 deletions

View File

@ -1,3 +1,4 @@
import asyncio
from typing import Optional, Mapping, Dict, Any from typing import Optional, Mapping, Dict, Any
from simnet.client.components.chronicle.base import BaseChronicleClient from simnet.client.components.chronicle.base import BaseChronicleClient
@ -113,8 +114,12 @@ class StarRailBattleChronicleClient(BaseChronicleClient):
BadRequest: If the request is invalid. BadRequest: If the request is invalid.
DataNotPublic: If the requested data is not public. DataNotPublic: If the requested data is not public.
""" """
data = await self._request_starrail_record("index", player_id, lang=lang) index_data, basic_info = await asyncio.gather(
return StarRailUserStats(**data) self._request_starrail_record("index", player_id, lang=lang),
self._request_starrail_record("role/basicInfo", player_id, lang=lang),
)
index_data["info"] = basic_info
return StarRailUserStats(**index_data)
async def get_starrail_characters( async def get_starrail_characters(
self, self,

View File

@ -36,5 +36,24 @@ class PartialStarRailUserStats(APIModel):
characters: List[PartialCharacter] = Field(alias="avatar_list") characters: List[PartialCharacter] = Field(alias="avatar_list")
class StarRailUserInfo(APIModel):
"""
Information of StarRail user.
Attributes:
nickname (str): User's nickname.
server (str): User's server.
level (int): User's level.
avatar (str): User's avatar url.
"""
nickname: str
server: str = Field(alias="region")
level: int
avatar: str
class StarRailUserStats(PartialStarRailUserStats): class StarRailUserStats(PartialStarRailUserStats):
"""Complete data of StarRail user, containing statistics and character information.""" """Complete data of StarRail user, containing statistics and character information."""
info: StarRailUserInfo