diff --git a/simnet/client/components/chronicle/base.py b/simnet/client/components/chronicle/base.py index 779304f..5a2932c 100644 --- a/simnet/client/components/chronicle/base.py +++ b/simnet/client/components/chronicle/base.py @@ -1,6 +1,8 @@ -from typing import Optional, Any +from typing import Optional, Any, List from simnet.client.base import BaseClient from simnet.client.routes import RECORD_URL +from simnet.errors import DataNotPublic +from simnet.models.lab.record import RecordCard from simnet.utils.enum_ import Region, Game from simnet.utils.types import QueryParamTypes @@ -92,3 +94,33 @@ class BaseChronicleClient(BaseClient): "card/wapi/changeDataSwitch", data=dict(switch_id=switch_id, is_public=on, game_id=game_id), ) + + async def get_record_cards( + self, + account_id: Optional[int] = None, + *, + lang: Optional[str] = None, + ) -> List[RecordCard]: + """Get a user's 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: + A list of RecordCard objects. + + Raises: + DataNotPublic: If data is empty. + """ + account_id = account_id or self.account_id + + data = await self.request_game_record( + "card/wapi/getGameRecordCard", + lang=lang, + params=dict(uid=account_id), + ) + if not data["list"]: + raise DataNotPublic({"retcode": 10102}) + + return [RecordCard(**card) for card in data["list"]] diff --git a/simnet/models/lab/record.py b/simnet/models/lab/record.py index 70ff857..45d3b2a 100644 --- a/simnet/models/lab/record.py +++ b/simnet/models/lab/record.py @@ -403,20 +403,23 @@ class RecordCard(BaseRecordCard): """ def __new__(cls, **kwargs: Any) -> BaseRecordCard: - """Creates the appropriate record card. + """Creates an appropriate record card instance based on the provided game ID. Args: **kwargs: The arguments passed in to create the record card. Returns: - BaseRecordCard: The record card object. + BaseRecordCard: An instance of a subclass of `BaseRecordCard` based on the provided game ID. + + Raises: + ValueError: If the provided game ID is invalid. """ game_id = kwargs.get("game_id", 0) if game_id == 1: - cls = HonkaiRecordCard # skipcq: PYL-W0642 - elif game_id == 2: - cls = GenshinRecordCard # skipcq: PYL-W0642 - elif game_id == 6: - cls = StarRailRecodeCard # skipcq: PYL-W0642 + return HonkaiRecordCard(**kwargs) + if game_id == 2: + return GenshinRecordCard(**kwargs) + if game_id == 6: + return StarRailRecodeCard(**kwargs) - return super().__new__(cls) # skipcq: PYL-E1120 + raise ValueError(f"Invalid game ID provided: {game_id}")