Module genshin.client.components.chronicle.base
Base battle chronicle component.
Classes
class BaseBattleChronicleClient (cookies: Union[ForwardRef('http.cookies.BaseCookie[Any]'), Mapping[Any, Any], str, Sequence[Union[ForwardRef('http.cookies.BaseCookie[Any]'), Mapping[Any, Any], str]], ForwardRef(None)] = None, *, authkey: Optional[str] = None, lang: str = 'en-us', region: Region = Region.OVERSEAS, proxy: Optional[str] = None, game: Optional[Game] = None, uid: Optional[int] = None, hoyolab_id: Optional[int] = None, device_id: Optional[str] = None, device_fp: Optional[str] = None, headers: Union[Mapping[str, str], Mapping[multidict._multidict.istr, str], multidict._multidict.CIMultiDict, multidict._multidict.CIMultiDictProxy, Iterable[Tuple[Union[str, multidict._multidict.istr], str]], ForwardRef(None)] = None, cache: Optional[BaseCache] = None, debug: bool = False)
-
Base battle chronicle component.
Expand source code
class BaseBattleChronicleClient(base.BaseClient): """Base battle chronicle component.""" async def request_game_record( self, endpoint: str, *, lang: typing.Optional[str] = None, region: typing.Optional[types.Region] = None, game: typing.Optional[types.Game] = None, is_card_wapi: bool = False, is_nap_ledger: bool = False, **kwargs: typing.Any, ) -> typing.Mapping[str, typing.Any]: """Make a request towards the game record endpoint.""" if is_card_wapi: base_url = routes.CARD_WAPI_URL.get_url(region or self.region) elif is_nap_ledger: base_url = routes.NAP_LEDGER_URL.get_url() else: game = game or self.default_game if game is None: raise RuntimeError("No default game set.") base_url = routes.RECORD_URL.get_url(region or self.region, game) url = base_url / endpoint update_task = asyncio.create_task(utility.update_characters_any(lang or self.lang, lenient=True)) data = await self.request_hoyolab(url, lang=lang, region=region, **kwargs) try: await update_task except Exception as e: warnings.warn(f"Failed to update characters: {e!r}") return data async def get_record_cards( self, hoyolab_id: typing.Optional[int] = None, *, lang: typing.Optional[str] = None ) -> list[models.hoyolab.RecordCard]: """Get a user's record cards.""" hoyolab_id = hoyolab_id or self._get_hoyolab_id() cache_key = cache.cache_key("records", hoyolab_id=hoyolab_id, lang=lang or self.lang) if not (data := await self.cache.get(cache_key)): data = await self.request_game_record( "getGameRecordCard", lang=lang, params=dict(uid=hoyolab_id), is_card_wapi=True ) if data["list"]: await self.cache.set(cache_key, data) else: raise errors.DataNotPublic({"retcode": 10102}) return [models.hoyolab.RecordCard(**card) for card in data["list"]] @deprecation.deprecated("get_record_cards") async def get_record_card( self, hoyolab_id: typing.Optional[int] = None, *, lang: typing.Optional[str] = None ) -> models.hoyolab.RecordCard: """Get a user's record card.""" cards = await self.get_record_cards(hoyolab_id, lang=lang) return cards[0] @managers.no_multi async def update_settings( self, setting: types.IDOr[hoyolab_models.RecordCardSetting], on: bool, *, game: typing.Optional[types.Game] = None, ) -> None: """Update user settings. Setting IDs: 1: Show your Battle Chronicle on your profile. 2: Show your Character Details in the Battle Chronicle. 3: Enable your Real-Time Notes. (only for Genshin Impact) """ if game is None and int(setting) == 3: game = types.Game.GENSHIN if game is None: if self.default_game is None: raise RuntimeError("No default game set.") game = self.default_game game_id = {types.Game.HONKAI: 1, types.Game.GENSHIN: 2, types.Game.STARRAIL: 6, types.Game.ZZZ: 8}[game] await self.request_game_record( "changeDataSwitch", method="POST", data=dict(switch_id=int(setting), is_public=on, game_id=game_id), is_card_wapi=True, ) @deprecation.deprecated("update_settings") async def set_visibility(self, public: bool, *, game: typing.Optional[types.Game] = None) -> None: """Set your data to public or private.""" await self.update_settings(1, public, game=game)
Ancestors
- BaseClient
- abc.ABC
Subclasses
- GenshinBattleChronicleClient
- HonkaiBattleChronicleClient
- StarRailBattleChronicleClient
- ZZZBattleChronicleClient
Class variables
var logger : logging.Logger
Instance variables
var authkeys : dict[Game, str]
var cache : BaseCache
var custom_headers : multidict._multidict.CIMultiDict[str]
var uids : dict[Game, int]
Methods
async def get_record_card(self, hoyolab_id: Optional[int] = None, *, lang: Optional[str] = None) ‑> RecordCard
-
Get a user's record card.
Warning
This function is deprecated and will be removed in the following version. You can use
get_record_cards
instead. async def get_record_cards(self, hoyolab_id: Optional[int] = None, *, lang: Optional[str] = None) ‑> list[RecordCard]
-
Get a user's record cards.
async def request_game_record(self, endpoint: str, *, lang: Optional[str] = None, region: Optional[Region] = None, game: Optional[Game] = None, is_card_wapi: bool = False, is_nap_ledger: bool = False, **kwargs: Any) ‑> Mapping[str, Any]
-
Make a request towards the game record endpoint.
async def set_visibility(self, public: bool, *, game: Optional[Game] = None) ‑> None
-
Set your data to public or private.
Warning
This function is deprecated and will be removed in the following version. You can use
update_settings
instead. async def update_settings(self, setting: Union[int, RecordCardSetting], on: bool, *, game: Optional[Game] = None) ‑> None
-
Update user settings.
Setting IDs: 1: Show your Battle Chronicle on your profile. 2: Show your Character Details in the Battle Chronicle. 3: Enable your Real-Time Notes. (only for Genshin Impact)
Inherited members