mirror of
https://github.com/PaiGramTeam/SIMNet.git
synced 2024-11-21 21:58:05 +00:00
✨ Support hoyolab redeem code
This commit is contained in:
parent
f789d40bcc
commit
9f6d35fc60
@ -3,12 +3,12 @@ from typing import Optional, List, Dict, Any
|
|||||||
|
|
||||||
from simnet.client.base import BaseClient
|
from simnet.client.base import BaseClient
|
||||||
from simnet.client.headers import Headers
|
from simnet.client.headers import Headers
|
||||||
from simnet.client.routes import TAKUMI_URL, HK4E_URL, CODE_URL
|
from simnet.client.routes import TAKUMI_URL, HK4E_URL, CODE_URL, CODE_HOYOLAB_URL
|
||||||
from simnet.models.lab.announcement import Announcement
|
from simnet.models.lab.announcement import Announcement
|
||||||
from simnet.models.lab.record import PartialUser, FullUser, Account
|
from simnet.models.lab.record import PartialUser, FullUser, Account
|
||||||
from simnet.utils.enum_ import Region, Game
|
from simnet.utils.enum_ import Region, Game
|
||||||
from simnet.utils.lang import create_short_lang_code
|
from simnet.utils.lang import create_short_lang_code
|
||||||
from simnet.utils.player import recognize_genshin_server
|
from simnet.utils.player import recognize_genshin_server, recognize_server, recognize_game_biz
|
||||||
from simnet.utils.types import HeaderTypes
|
from simnet.utils.types import HeaderTypes
|
||||||
|
|
||||||
__all__ = ("LabClient",)
|
__all__ = ("LabClient",)
|
||||||
@ -207,6 +207,31 @@ class LabClient(BaseClient):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
async def redeem_code_by_hoyolab(
|
||||||
|
self,
|
||||||
|
code: str,
|
||||||
|
player_id: Optional[int] = None,
|
||||||
|
*,
|
||||||
|
lang: Optional[str] = None,
|
||||||
|
) -> None:
|
||||||
|
"""Redeems a gift code for the current or specified user.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
code (str): The gift code to redeem.
|
||||||
|
player_id (int, optional): The player ID to redeem the code for. Defaults to None.
|
||||||
|
lang (str, optional): The language code used for the request. Defaults to None.
|
||||||
|
"""
|
||||||
|
player_id = self.player_id or player_id
|
||||||
|
url = CODE_HOYOLAB_URL.get_url(self.region, self.game)
|
||||||
|
params = dict(
|
||||||
|
uid=player_id,
|
||||||
|
region=recognize_server(player_id, self.game),
|
||||||
|
cdkey=code,
|
||||||
|
game_biz=recognize_game_biz(player_id, self.game),
|
||||||
|
lang=create_short_lang_code(lang or self.lang),
|
||||||
|
)
|
||||||
|
await self.request_bbs(url, params=params)
|
||||||
|
|
||||||
async def get_game_accounts(self, *, lang: Optional[str] = None) -> List[Account]:
|
async def get_game_accounts(self, *, lang: Optional[str] = None) -> List[Account]:
|
||||||
"""Get the game accounts of the currently logged-in user.
|
"""Get the game accounts of the currently logged-in user.
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ __all__ = (
|
|||||||
"INFO_LEDGER_URL",
|
"INFO_LEDGER_URL",
|
||||||
"HK4E_URL",
|
"HK4E_URL",
|
||||||
"CODE_URL",
|
"CODE_URL",
|
||||||
|
"CODE_HOYOLAB_URL",
|
||||||
"YSULOG_URL",
|
"YSULOG_URL",
|
||||||
"QRCODE_URL",
|
"QRCODE_URL",
|
||||||
)
|
)
|
||||||
@ -307,5 +308,12 @@ YSULOG_URL = InternationalRoute(
|
|||||||
HK4E_URL = Route("https://sg-hk4e-api.hoyoverse.com/common/hk4e_global/")
|
HK4E_URL = Route("https://sg-hk4e-api.hoyoverse.com/common/hk4e_global/")
|
||||||
|
|
||||||
CODE_URL = Route("https://sg-hk4e-api.hoyoverse.com/common/apicdkey/api/webExchangeCdkey")
|
CODE_URL = Route("https://sg-hk4e-api.hoyoverse.com/common/apicdkey/api/webExchangeCdkey")
|
||||||
|
CODE_HOYOLAB_URL = GameRoute(
|
||||||
|
overseas=dict(
|
||||||
|
genshin="https://sg-hk4e-api.hoyolab.com/common/apicdkey/api/webExchangeCdkeyHyl",
|
||||||
|
hkrpg="https://sg-hkrpg-api.hoyolab.com/common/apicdkey/api/webExchangeCdkeyHyl",
|
||||||
|
),
|
||||||
|
chinese=dict(),
|
||||||
|
)
|
||||||
|
|
||||||
QRCODE_URL = Route("https://hk4e-sdk.mihoyo.com/hk4e_cn/combo/panda/qrcode")
|
QRCODE_URL = Route("https://hk4e-sdk.mihoyo.com/hk4e_cn/combo/panda/qrcode")
|
||||||
|
Loading…
Reference in New Issue
Block a user