Module genshin.client.components.chronicle.honkai

Honkai battle chronicle component.

Classes

class HonkaiBattleChronicleClient (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)

Honkai battle chronicle component.

Expand source code
class HonkaiBattleChronicleClient(base.BaseBattleChronicleClient):
    """Honkai battle chronicle component."""

    async def _request_honkai_record(
        self,
        endpoint: str,
        uid: typing.Optional[int] = None,
        *,
        lang: typing.Optional[str] = None,
        cache: bool = False,
    ) -> typing.Mapping[str, typing.Any]:
        """Get an arbitrary honkai object."""
        uid = uid or await self._get_uid(types.Game.HONKAI)

        cache_key: typing.Optional[base.ChronicleCacheKey] = None
        if cache:
            cache_key = base.ChronicleCacheKey(
                types.Game.HONKAI,
                endpoint,
                uid,
                lang=lang or self.lang,
            )

        account = await self._get_account(types.Game.HONKAI)
        return await self.request_game_record(
            endpoint,
            lang=lang,
            game=types.Game.HONKAI,
            region=self.region,
            params=dict(server=account.server, role_id=uid),
            cache=cache_key,
        )

    async def get_honkai_user(
        self,
        uid: int,
        *,
        lang: typing.Optional[str] = None,
    ) -> models.HonkaiUserStats:
        """Get honkai user stats."""
        data = await self._request_honkai_record("index", uid, lang=lang)
        return models.HonkaiUserStats(**data)

    async def get_honkai_battlesuits(
        self,
        uid: int,
        *,
        lang: typing.Optional[str] = None,
    ) -> typing.Sequence[models.FullBattlesuit]:
        """Get honkai battlesuits."""
        data = await self._request_honkai_record("characters", uid, lang=lang)
        return [models.FullBattlesuit(**char["character"]) for char in data["characters"]]

    async def get_honkai_old_abyss(
        self,
        uid: int,
        *,
        lang: typing.Optional[str] = None,
    ) -> typing.Sequence[models.OldAbyss]:
        """Get honkai old abyss.

        Only for level > 80.
        """
        data = await self._request_honkai_record("latestOldAbyssReport", uid, lang=lang)
        return [models.OldAbyss(**x) for x in data["reports"]]

    async def get_honkai_superstring_abyss(
        self,
        uid: int,
        *,
        lang: typing.Optional[str] = None,
    ) -> typing.Sequence[models.SuperstringAbyss]:
        """Get honkai superstring abyss.

        Only for level <= 80.
        """
        data = await self._request_honkai_record("newAbyssReport", uid, lang=lang)
        return [models.SuperstringAbyss(**x) for x in data["reports"]]

    async def get_honkai_abyss(
        self,
        uid: int,
        *,
        lang: typing.Optional[str] = None,
    ) -> typing.Sequence[typing.Union[models.SuperstringAbyss, models.OldAbyss]]:
        """Get honkai abyss."""
        possible = await asyncio.gather(
            self.get_honkai_old_abyss(uid, lang=lang),
            self.get_honkai_superstring_abyss(uid, lang=lang),
            return_exceptions=True,
        )
        for abyss in possible:
            if not isinstance(abyss, BaseException):
                return abyss
            if not isinstance(abyss, errors.InternalDatabaseError):
                raise abyss from None

        return []

    async def get_honkai_elysian_realm(
        self,
        uid: int,
        *,
        lang: typing.Optional[str] = None,
    ) -> typing.Sequence[models.ElysianRealm]:
        """Get honkai elysian realm."""
        data = await self._request_honkai_record("godWar", uid, lang=lang)
        return [models.ElysianRealm(**x) for x in data["records"]]

    async def get_honkai_memorial_arena(
        self,
        uid: int,
        *,
        lang: typing.Optional[str] = None,
    ) -> typing.Sequence[models.MemorialArena]:
        """Get honkai memorial arena."""
        data = await self._request_honkai_record("battleFieldReport", uid, lang=lang)
        return [models.MemorialArena(**x) for x in data["reports"]]

    async def get_honkai_notes(
        self,
        uid: int,
        *,
        lang: typing.Optional[str] = None,
    ) -> models.HonkaiNotes:
        """Get honkai memorial arena."""
        data = await self._request_honkai_record("note", uid, lang=lang)
        return models.HonkaiNotes(**data)

    async def get_full_honkai_user(
        self,
        uid: int,
        *,
        lang: typing.Optional[str] = None,
    ) -> models.FullHonkaiUserStats:
        """Get a full honkai user."""
        user, battlesuits, abyss, mr, er = await asyncio.gather(
            self.get_honkai_user(uid, lang=lang),
            self.get_honkai_battlesuits(uid, lang=lang),
            self.get_honkai_abyss(uid, lang=lang),
            self.get_honkai_memorial_arena(uid, lang=lang),
            self.get_honkai_elysian_realm(uid, lang=lang),
        )

        return models.FullHonkaiUserStats(
            **user.model_dump(by_alias=True),
            battlesuits=battlesuits,
            abyss=abyss,
            memorial_arena=mr,
            elysian_realm=er,
        )

    get_old_abyss = get_honkai_old_abyss
    get_superstring_abyss = get_honkai_superstring_abyss
    get_elysian_realm = get_honkai_elysian_realm
    get_memorial_arena = get_honkai_memorial_arena

Ancestors

Subclasses

Class variables

var logger : logging.Logger

Instance variables

var authkeys : dict[Game, str]
var cacheBaseCache
var cookie_managerBaseCookieManager
var custom_headers : multidict._multidict.CIMultiDict[str]
var uids : dict[Game, int]

Methods

async def get_elysian_realm(self, uid: int, *, lang: Optional[str] = None) ‑> Sequence[ElysianRealm]

Get honkai elysian realm.

async def get_full_honkai_user(self, uid: int, *, lang: Optional[str] = None) ‑> FullHonkaiUserStats

Get a full honkai user.

async def get_honkai_abyss(self, uid: int, *, lang: Optional[str] = None) ‑> Sequence[Union[SuperstringAbyssOldAbyss]]

Get honkai abyss.

async def get_honkai_battlesuits(self, uid: int, *, lang: Optional[str] = None) ‑> Sequence[FullBattlesuit]

Get honkai battlesuits.

async def get_honkai_elysian_realm(self, uid: int, *, lang: Optional[str] = None) ‑> Sequence[ElysianRealm]

Get honkai elysian realm.

async def get_honkai_memorial_arena(self, uid: int, *, lang: Optional[str] = None) ‑> Sequence[MemorialArena]

Get honkai memorial arena.

async def get_honkai_notes(self, uid: int, *, lang: Optional[str] = None) ‑> HonkaiNotes

Get honkai memorial arena.

async def get_honkai_old_abyss(self, uid: int, *, lang: Optional[str] = None) ‑> Sequence[OldAbyss]

Get honkai old abyss.

Only for level > 80.

async def get_honkai_superstring_abyss(self, uid: int, *, lang: Optional[str] = None) ‑> Sequence[SuperstringAbyss]

Get honkai superstring abyss.

Only for level <= 80.

async def get_honkai_user(self, uid: int, *, lang: Optional[str] = None) ‑> HonkaiUserStats

Get honkai user stats.

async def get_memorial_arena(self, uid: int, *, lang: Optional[str] = None) ‑> Sequence[MemorialArena]

Get honkai memorial arena.

async def get_old_abyss(self, uid: int, *, lang: Optional[str] = None) ‑> Sequence[OldAbyss]

Get honkai old abyss.

Only for level > 80.

async def get_superstring_abyss(self, uid: int, *, lang: Optional[str] = None) ‑> Sequence[SuperstringAbyss]

Get honkai superstring abyss.

Only for level <= 80.

Inherited members