From 5801b6766d7ca723b6f3419ea81b1cc050b41521 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Wed, 6 Sep 2023 20:50:31 +0800 Subject: [PATCH] :sparkles: Support starrail resident --- .../client/components/chronicle/starrail.py | 22 ++++++ simnet/models/starrail/chronicle/activity.py | 2 +- simnet/models/starrail/chronicle/resident.py | 68 +++++++++++++++++++ 3 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 simnet/models/starrail/chronicle/resident.py diff --git a/simnet/client/components/chronicle/starrail.py b/simnet/client/components/chronicle/starrail.py index ac31d42..13d02d4 100644 --- a/simnet/client/components/chronicle/starrail.py +++ b/simnet/client/components/chronicle/starrail.py @@ -10,6 +10,7 @@ from simnet.models.starrail.chronicle.challenge import StarRailChallenge from simnet.models.starrail.chronicle.characters import StarRailDetailCharacters from simnet.models.starrail.chronicle.museum import StarRailMuseumBasic, StarRailMuseumDetail from simnet.models.starrail.chronicle.notes import StarRailNote, StarRailNoteWidget, StarRailNoteOverseaWidget +from simnet.models.starrail.chronicle.resident import StarRailResident from simnet.models.starrail.chronicle.rogue import StarRailRogue from simnet.models.starrail.chronicle.stats import StarRailUserStats, StarRailUserInfo from simnet.utils.enum_ import Game, Region @@ -291,6 +292,27 @@ class StarRailBattleChronicleClient(BaseChronicleClient): data = await self._request_starrail_record("activity", uid, lang=lang) return StarRailActivity(**data) + async def get_starrail_resident( + self, + uid: Optional[int] = None, + lang: Optional[str] = None, + ) -> StarRailResident: + """Get starrail resident info. + + Args: + uid (Optional[int], optional): The player ID. Defaults to None. + lang (Optional[str], optional): The language of the data. Defaults to None. + + Returns: + StarRailResident: The requested activity info. + + Raises: + BadRequest: If the request is invalid. + DataNotPublic: If the requested data is not public. + """ + data = await self._request_starrail_record("resident", uid, lang=lang) + return StarRailResident(**data) + async def get_starrail_notes_by_stoken( self, lang: Optional[str] = None, diff --git a/simnet/models/starrail/chronicle/activity.py b/simnet/models/starrail/chronicle/activity.py index c515875..8ec4d64 100644 --- a/simnet/models/starrail/chronicle/activity.py +++ b/simnet/models/starrail/chronicle/activity.py @@ -144,7 +144,7 @@ class StarRailActivity(APIModel): for activity in self.activities: if list(activity.keys())[0] == key: return activity[key] - raise ValueError("No star fight activity found.") + raise ValueError("No starrail activity found.") @property def fantastic_story(self) -> StarRailFantasticStory: diff --git a/simnet/models/starrail/chronicle/resident.py b/simnet/models/starrail/chronicle/resident.py new file mode 100644 index 0000000..53e95f1 --- /dev/null +++ b/simnet/models/starrail/chronicle/resident.py @@ -0,0 +1,68 @@ +from typing import List, Optional + +from simnet.models.base import APIModel + + +class StarRailResidentBase(APIModel): + """StarRailResident Base Model""" + + exists_data: bool = True + is_hot: bool + strategy_link: str = "" + + +class StarRailResidentBoxingListItem(APIModel): + """Resident Boxing List Item""" + + id: int + name: str + best: int + + +class StarRailResidentBoxing(APIModel): + """Resident Boxing""" + + base: StarRailResidentBase + list: List[StarRailResidentBoxingListItem] + + +class StarRailResidentMuseumInfo(APIModel): + """Resident Museum Info""" + + current_exp: int + max_exp: int + exhibition_num: int + total_exhibition: int + director_num: int + total_director: int + phase: str + + +class StarRailResidentMuseum(APIModel): + """Resident Museum""" + + base: StarRailResidentBase + museum: StarRailResidentMuseumInfo + + +class StarRailResident(APIModel): + """Starrail chronicle resident activity.""" + + residents: List + + def find_resident(self, key: str) -> Optional[dict]: + """Find a resident by key.""" + for resident in self.residents: + if list(resident.keys())[0] == key: + return resident[key] + raise ValueError("No starrail resident found.") + + @property + def museum(self) -> StarRailResidentMuseum: + """Get the museum resident.""" + return StarRailResidentMuseum(**self.find_resident("museum")) + + @property + def boxing(self) -> StarRailResidentBoxing: + """Get the boxing resident.""" + return StarRailResidentBoxing(**self.find_resident("boxing"))