Support zzz self-help

This commit is contained in:
xtaodada 2024-07-06 13:13:17 +08:00
parent 185733af85
commit 9839a06bb8
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
4 changed files with 94 additions and 0 deletions

View File

@ -0,0 +1,48 @@
from functools import partial
from typing import Optional, List
from simnet.client.components.self_help.base import BaseSelfHelpClient
from simnet.models.zzz.self_help import ZZZSelfHelpActionLog
from simnet.utils.enums import Game
from simnet.utils.paginator import WishPaginator
class ZZZSelfHelpClient(BaseSelfHelpClient):
"""ZZZ self-help component."""
async def get_zzz_action_log(
self,
authkey: str,
limit: Optional[int] = None,
end_id: int = 0,
*,
lang: Optional[str] = None,
) -> List[ZZZSelfHelpActionLog]:
"""
Get the action log for a starrail user.
Args:
authkey: The authkey for the user.
limit: The number of logs to get.
end_id: The end ID for the logs.
lang: The language to get the logs in.
Returns:
List[ZZZSelfHelpActionLog]: The action logs.
"""
paginator = WishPaginator(
end_id,
partial(
self.request_self_help,
endpoint="LoginRecord/GetList",
game=Game.ZZZ,
lang=lang,
params={
"authkey": authkey,
"size": 100,
"page_id": 0,
},
),
)
items = await paginator.get(limit)
return [ZZZSelfHelpActionLog(**i) for i in items]

View File

@ -352,5 +352,6 @@ SELF_HELP_URL = GameRoute(
chinese=dict( chinese=dict(
genshin="https://hk4e-api.mihoyo.com/common/hk4e_self_help_query", genshin="https://hk4e-api.mihoyo.com/common/hk4e_self_help_query",
hkrpg="https://api-takumi.mihoyo.com/common/hkrpg_self_help_inquiry", hkrpg="https://api-takumi.mihoyo.com/common/hkrpg_self_help_inquiry",
nap="https://public-operation-nap.mihoyo.com/common/nap_self_help_query",
), ),
) )

View File

@ -4,6 +4,7 @@ from simnet.client.components.auth import AuthClient
from simnet.client.components.chronicle.zzz import ZZZBattleChronicleClient from simnet.client.components.chronicle.zzz import ZZZBattleChronicleClient
from simnet.client.components.daily import DailyRewardClient from simnet.client.components.daily import DailyRewardClient
from simnet.client.components.lab import LabClient from simnet.client.components.lab import LabClient
from simnet.client.components.self_help.zzz import ZZZSelfHelpClient
from simnet.client.components.verify import VerifyClient from simnet.client.components.verify import VerifyClient
from simnet.client.components.wish.zzz import ZZZWishClient from simnet.client.components.wish.zzz import ZZZWishClient
from simnet.utils.enums import Game from simnet.utils.enums import Game
@ -14,6 +15,7 @@ __all__ = ("ZZZClient",)
class ZZZClient( class ZZZClient(
ZZZBattleChronicleClient, ZZZBattleChronicleClient,
ZZZWishClient, ZZZWishClient,
ZZZSelfHelpClient,
DailyRewardClient, DailyRewardClient,
AuthClient, AuthClient,
LabClient, LabClient,

View File

@ -0,0 +1,43 @@
from datetime import datetime
from enum import Enum
from typing import Optional
from pydantic import Field
from simnet.models.base import APIModel
class ZZZSelfHelpActionLogReason(str, Enum):
"""
Possible reasons for a ZZZ self-help action log.
Attributes:
LOG_OUT: Log out.
LOG_IN: Log in.
"""
LOG_OUT = "登出"
LOG_IN = "登录"
class ZZZSelfHelpActionLog(APIModel):
"""
ZZZ self-help action log.
Attributes:
id: The log ID.
uid: The user ID.
time: The time of the log.
reason: The reason for the log.
client_ip: The client IP address.
"""
id: int
uid: int
time: datetime = Field(alias="datetime")
reason: ZZZSelfHelpActionLogReason = Field(alias="action_name")
client_ip: Optional[str] = ""
@property
def status(self) -> int:
return 1 if self.reason == ZZZSelfHelpActionLogReason.LOG_IN else 0