🎨 Update get_record_card

This commit is contained in:
luoshuijs 2023-05-28 17:32:21 +08:00 committed by 洛水居室
parent 842ad515cd
commit 1a8053ea6b
No known key found for this signature in database
GPG Key ID: C9DE87DA724B88FC
3 changed files with 62 additions and 3 deletions

View File

@ -1,4 +1,5 @@
from typing import Optional, Any, List
from simnet.client.base import BaseClient
from simnet.client.routes import RECORD_URL
from simnet.errors import DataNotPublic
@ -99,11 +100,11 @@ class BaseChronicleClient(BaseClient):
*,
lang: Optional[str] = None,
) -> List[RecordCard]:
"""Get a user's record cards.
"""Get a player record cards.
Args:
account_id: Optional[int], the user's account ID, defaults to None
lang: Optional[str], the language version of the request, defaults to None
account_id: (int, optional), the user's account ID, defaults to None
lang: (str, optional), the language version of the request, defaults to None
Returns:
A list of RecordCard objects.

View File

@ -11,6 +11,7 @@ from simnet.models.genshin.chronicle.stats import (
GenshinUserStats,
FullGenshinUserStats,
)
from simnet.models.lab.record import RecordCard
from simnet.utils.enum_ import Game
from simnet.utils.player import recognize_genshin_server, recognize_region
@ -229,3 +230,31 @@ class GenshinBattleChronicleClient(BaseChronicleClient):
Dict: The requested get_genshin_activities.
"""
return await self._request_genshin_record("activities", player_id, lang=lang)
async def get_record_card(
self,
account_id: Optional[int] = None,
*,
lang: Optional[str] = None,
) -> Optional[RecordCard]:
"""Get a genshin player record cards.
Args:
account_id: Optional[int], the user's account ID, defaults to None
lang: Optional[str], the language version of the request, defaults to None
Returns:
Genshin player record cards.
Returns:
Optional[RecordCard]: RecordCard objects.
"""
account_id = account_id or self.account_id
record_cards = await self.get_record_cards(account_id, lang=lang)
for record_card in record_cards:
if record_card.game == Game.GENSHIN:
return record_card
return None

View File

@ -3,6 +3,7 @@ from typing import Optional, Mapping, Dict, Any
from simnet.client.components.chronicle.base import BaseChronicleClient
from simnet.errors import BadRequest, DataNotPublic
from simnet.models.lab.record import RecordCard
from simnet.models.starrail.chronicle.characters import StarShipDetailCharacters
from simnet.models.starrail.chronicle.notes import StarRailNote
from simnet.models.starrail.chronicle.stats import StarRailUserStats
@ -142,3 +143,31 @@ class StarRailBattleChronicleClient(BaseChronicleClient):
payload = {"need_wiki": "true"}
data = await self._request_starrail_record("avatar/info", player_id, lang=lang, payload=payload)
return StarShipDetailCharacters(**data)
async def get_record_card(
self,
account_id: Optional[int] = None,
*,
lang: Optional[str] = None,
) -> Optional[RecordCard]:
"""Get a starrail player record cards.
Args:
account_id: Optional[int], the user's account ID, defaults to None
lang: Optional[str], the language version of the request, defaults to None
Returns:
Starrail user record cards.
Returns:
Optional[RecordCard]: RecordCard objects.
"""
account_id = account_id or self.account_id
record_cards = await self.get_record_cards(account_id, lang=lang)
for record_card in record_cards:
if record_card.game == Game.STARRAIL:
return record_card
return None