From 1a8053ea6ba30b2c55fea18b976a5036f7354e42 Mon Sep 17 00:00:00 2001 From: luoshuijs Date: Sun, 28 May 2023 17:32:21 +0800 Subject: [PATCH] :art: Update `get_record_card` --- simnet/client/components/chronicle/base.py | 7 +++-- simnet/client/components/chronicle/genshin.py | 29 +++++++++++++++++++ .../client/components/chronicle/starrail.py | 29 +++++++++++++++++++ 3 files changed, 62 insertions(+), 3 deletions(-) diff --git a/simnet/client/components/chronicle/base.py b/simnet/client/components/chronicle/base.py index a04a58b..28349a4 100644 --- a/simnet/client/components/chronicle/base.py +++ b/simnet/client/components/chronicle/base.py @@ -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. diff --git a/simnet/client/components/chronicle/genshin.py b/simnet/client/components/chronicle/genshin.py index 517debe..c3376ea 100644 --- a/simnet/client/components/chronicle/genshin.py +++ b/simnet/client/components/chronicle/genshin.py @@ -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 diff --git a/simnet/client/components/chronicle/starrail.py b/simnet/client/components/chronicle/starrail.py index d45bde0..8baf106 100644 --- a/simnet/client/components/chronicle/starrail.py +++ b/simnet/client/components/chronicle/starrail.py @@ -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