Skip to content

Commit

Permalink
Fix request_game_record method not working (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
seriaati authored Jul 11, 2024
1 parent 06d19c0 commit d35d283
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
18 changes: 15 additions & 3 deletions genshin/client/components/chronicle/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,20 @@ async def request_game_record(
*,
lang: typing.Optional[str] = None,
region: typing.Optional[types.Region] = None,
game: typing.Optional[types.Game] = None,
is_card_wapi: bool = False,
**kwargs: typing.Any,
) -> typing.Mapping[str, typing.Any]:
"""Make a request towards the game record endpoint."""
base_url = routes.RECORD_URL.get_url(region or self.region)
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)
if not is_card_wapi
else routes.CARD_WAPI_URL.get_url(region or self.region)
)
url = base_url / endpoint

mi18n_task = asyncio.create_task(self._fetch_mi18n("bbs", lang=lang or self.lang))
Expand Down Expand Up @@ -74,9 +84,10 @@ async def get_record_cards(
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(
"card/wapi/getGameRecordCard",
"getGameRecordCard",
lang=lang,
params=dict(uid=hoyolab_id),
is_card_wapi=True,
)

if data["list"]:
Expand Down Expand Up @@ -124,9 +135,10 @@ async def update_settings(
game_id = {types.Game.HONKAI: 1, types.Game.GENSHIN: 2, types.Game.STARRAIL: 6, types.Game.ZZZ: 8}[game]

await self.request_game_record(
"card/wapi/changeDataSwitch",
"changeDataSwitch",
method="POST",
data=dict(switch_id=int(setting), is_public=on, game_id=game_id),
is_card_wapi=True,
)

@deprecation.deprecated("update_settings")
Expand Down
24 changes: 21 additions & 3 deletions genshin/client/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"BBS_REFERER_URL",
"BBS_URL",
"CALCULATOR_URL",
"CARD_WAPI_URL",
"CHECK_QRCODE_URL",
"CN_WEB_LOGIN_URL",
"COMMUNITY_URL",
Expand Down Expand Up @@ -134,9 +135,23 @@ def get_url(self, region: types.Region, game: types.Game) -> yarl.URL:
overseas="https://bbs-api-os.hoyolab.com/community/",
chinese="https://api-takumi-record.mihoyo.com/community/",
)
RECORD_URL = InternationalRoute(
overseas="https://bbs-api-os.hoyolab.com/game_record/",
chinese="https://api-takumi-record.mihoyo.com/game_record/app/",
RECORD_URL = GameRoute(
overseas=dict(
genshin="https://bbs-api-os.hoyolab.com/game_record/genshin/api",
hkrpg="https://bbs-api-os.hoyolab.com/game_record/hkrpg/api",
honkai3rd="https://bbs-api-os.hoyolab.com/game_record/honkai3rd/api",
nap="https://sg-act-nap-api.hoyolab.com/event/game_record_zzz/api/zzz",
),
chinese=dict(
genshin="https://api-takumi-record.mihoyo.com/game_record/app/genshin/api",
hkrpg="https://api-takumi-record.mihoyo.com/game_record/app/hkrpg/api",
honkai3rd="https://api-takumi-record.mihoyo.com/game_record/app/honkai3rd/api",
nap="https://api-takumi-record.mihoyo.com/event/game_record_zzz/api/zzz",
),
)
CARD_WAPI_URL = InternationalRoute(
overseas="https://bbs-api-os.hoyolab.com/game_record/card/wapi",
chinese="https://api-takumi-record.mihoyo.com/game_record/app/card/wapi",
)
LINEUP_URL = InternationalRoute(
overseas="https://sg-public-api.hoyoverse.com/event/simulatoros/",
Expand Down Expand Up @@ -184,18 +199,21 @@ def get_url(self, region: types.Region, game: types.Game) -> yarl.URL:
genshin="https://sg-hk4e-api.hoyolab.com/event/sol?act_id=e202102251931481",
honkai3rd="https://sg-public-api.hoyolab.com/event/mani?act_id=e202110291205111",
hkrpg="https://sg-public-api.hoyolab.com/event/luna/os?act_id=e202303301540311",
nap="https://sg-act-nap-api.hoyolab.com/event/luna/zzz/os?act_id=e202406031448091",
),
chinese=dict(
genshin="https://api-takumi.mihoyo.com/event/luna/?act_id=e202311201442471",
honkai3rd="https://api-takumi.mihoyo.com/event/luna/?act_id=e202306201626331",
hkrpg="https://api-takumi.mihoyo.com/event/luna/?act_id=e202304121516551",
nap="https://act-nap-api.mihoyo.com/event/luna/zzz/?act_id=e202406242138391",
),
)

CODE_URL = GameRoute(
overseas=dict(
genshin="https://sg-hk4e-api.hoyoverse.com/common/apicdkey/api/webExchangeCdkey",
hkrpg="https://sg-hkrpg-api.hoyoverse.com/common/apicdkey/api/webExchangeCdkey",
nap="https://public-operation-nap.hoyoverse.com/common/apicdkey/api/webExchangeCdkey",
),
chinese=dict(),
)
Expand Down

0 comments on commit d35d283

Please sign in to comment.