mirror of
https://github.com/PaiGramTeam/SIMNet.git
synced 2024-11-22 06:17:57 +00:00
✨ Add Get Record Cards
This commit is contained in:
parent
10a1a22f68
commit
5d2d3609bb
@ -1,6 +1,8 @@
|
|||||||
from typing import Optional, Any
|
from typing import Optional, Any, List
|
||||||
from simnet.client.base import BaseClient
|
from simnet.client.base import BaseClient
|
||||||
from simnet.client.routes import RECORD_URL
|
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.enum_ import Region, Game
|
||||||
from simnet.utils.types import QueryParamTypes
|
from simnet.utils.types import QueryParamTypes
|
||||||
|
|
||||||
@ -92,3 +94,33 @@ class BaseChronicleClient(BaseClient):
|
|||||||
"card/wapi/changeDataSwitch",
|
"card/wapi/changeDataSwitch",
|
||||||
data=dict(switch_id=switch_id, is_public=on, game_id=game_id),
|
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"]]
|
||||||
|
@ -403,20 +403,23 @@ class RecordCard(BaseRecordCard):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __new__(cls, **kwargs: Any) -> 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:
|
Args:
|
||||||
**kwargs: The arguments passed in to create the record card.
|
**kwargs: The arguments passed in to create the record card.
|
||||||
|
|
||||||
Returns:
|
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)
|
game_id = kwargs.get("game_id", 0)
|
||||||
if game_id == 1:
|
if game_id == 1:
|
||||||
cls = HonkaiRecordCard # skipcq: PYL-W0642
|
return HonkaiRecordCard(**kwargs)
|
||||||
elif game_id == 2:
|
if game_id == 2:
|
||||||
cls = GenshinRecordCard # skipcq: PYL-W0642
|
return GenshinRecordCard(**kwargs)
|
||||||
elif game_id == 6:
|
if game_id == 6:
|
||||||
cls = StarRailRecodeCard # skipcq: PYL-W0642
|
return StarRailRecodeCard(**kwargs)
|
||||||
|
|
||||||
return super().__new__(cls) # skipcq: PYL-E1120
|
raise ValueError(f"Invalid game ID provided: {game_id}")
|
||||||
|
Loading…
Reference in New Issue
Block a user