diff --git a/simnet/client/components/self_help/zzz.py b/simnet/client/components/self_help/zzz.py new file mode 100644 index 0000000..533d133 --- /dev/null +++ b/simnet/client/components/self_help/zzz.py @@ -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] diff --git a/simnet/client/routes.py b/simnet/client/routes.py index c47293f..3532490 100644 --- a/simnet/client/routes.py +++ b/simnet/client/routes.py @@ -352,5 +352,6 @@ SELF_HELP_URL = GameRoute( chinese=dict( genshin="https://hk4e-api.mihoyo.com/common/hk4e_self_help_query", hkrpg="https://api-takumi.mihoyo.com/common/hkrpg_self_help_inquiry", + nap="https://public-operation-nap.mihoyo.com/common/nap_self_help_query", ), ) diff --git a/simnet/client/zzz.py b/simnet/client/zzz.py index 2ca1d54..df3b871 100644 --- a/simnet/client/zzz.py +++ b/simnet/client/zzz.py @@ -4,6 +4,7 @@ from simnet.client.components.auth import AuthClient from simnet.client.components.chronicle.zzz import ZZZBattleChronicleClient from simnet.client.components.daily import DailyRewardClient 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.wish.zzz import ZZZWishClient from simnet.utils.enums import Game @@ -14,6 +15,7 @@ __all__ = ("ZZZClient",) class ZZZClient( ZZZBattleChronicleClient, ZZZWishClient, + ZZZSelfHelpClient, DailyRewardClient, AuthClient, LabClient, diff --git a/simnet/models/zzz/self_help.py b/simnet/models/zzz/self_help.py new file mode 100644 index 0000000..cef4ed0 --- /dev/null +++ b/simnet/models/zzz/self_help.py @@ -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