diff --git a/genshin/client/components/chronicle/starrail.py b/genshin/client/components/chronicle/starrail.py index 576ce05f..b9d45396 100644 --- a/genshin/client/components/chronicle/starrail.py +++ b/genshin/client/components/chronicle/starrail.py @@ -138,6 +138,19 @@ async def get_starrail_pure_fiction( """Get starrail pure fiction runs.""" payload = dict(schedule_type=2 if previous else 1, need_all="true") data = await self._request_starrail_record("challenge_story", uid, lang=lang, payload=payload) + + # In "groups", it contains time data from both the current season and previous season. + data = dict(data) + time = data["groups"][0] + if previous is True and len(data["groups"]) > 1: + time = data["groups"][1] + + # Extract the time data. + data["season_id"] = time["schedule_id"] + data["begin_time"] = time["begin_time"] + data["end_time"] = time["end_time"] + data["name"] = time["name_mi18n"] + return models.StarRailPureFiction(**data) async def get_starrail_apc_shadow( diff --git a/genshin/models/starrail/chronicle/challenge.py b/genshin/models/starrail/chronicle/challenge.py index a13b4b67..062c8761 100644 --- a/genshin/models/starrail/chronicle/challenge.py +++ b/genshin/models/starrail/chronicle/challenge.py @@ -70,7 +70,6 @@ class StarRailChallengeSeason(APIModel): class StarRailChallenge(APIModel): """Memory of chaos challenge in a season.""" - name: str season: int = Aliased("schedule_id") begin_time: PartialTime end_time: PartialTime @@ -81,16 +80,6 @@ class StarRailChallenge(APIModel): has_data: bool floors: List[StarRailFloor] = Aliased("all_floor_detail") - seasons: List[StarRailChallengeSeason] = Aliased("groups") - - @pydantic.root_validator(pre=True) - def __extract_name(cls, values: Dict[str, Any]) -> Dict[str, Any]: - if "seasons" in values and isinstance(values["seasons"], List): - seasons: List[Dict[str, Any]] = values["seasons"] - if len(seasons) > 0 and "name_mi18n" in seasons[0]: - values["name"] = seasons[0]["name_mi18n"] - - return values class ChallengeBuff(APIModel): @@ -125,10 +114,10 @@ def score(self) -> int: class StarRailPureFiction(APIModel): """Pure Fiction challenge in a season.""" - name: str = pydantic.Field(deprecated="Use `season_id` together with `seasons instead`.") - season_id: int = pydantic.Field(deprecated="Use `season_id` together with `seasons instead`.") - begin_time: PartialTime = pydantic.Field(deprecated="Use `season_id` together with `seasons instead`.") - end_time: PartialTime = pydantic.Field(deprecated="Use `season_id` together with `seasons instead`.") + name: str + season_id: int + begin_time: PartialTime + end_time: PartialTime total_stars: int = Aliased("star_num") max_floor: str @@ -136,25 +125,8 @@ class StarRailPureFiction(APIModel): has_data: bool floors: List[FictionFloor] = Aliased("all_floor_detail") - seasons: List[StarRailChallengeSeason] = Aliased("groups") max_floor_id: int - @pydantic.root_validator(pre=True) - def __unnest_groups(cls, values: Dict[str, Any]) -> Dict[str, Any]: - if "seasons" in values and isinstance(values["seasons"], List): - seasons: List[Dict[str, Any]] = values["seasons"] - if len(seasons) > 0: - if "name_mi18n" in seasons[0]: - values["name"] = seasons[0]["name_mi18n"] - if "schedule_id" in seasons[0]: - values["season_id"] = seasons[0]["schedule_id"] - if "begin_time" in seasons[0]: - values["begin_time"] = seasons[0]["begin_time"] - if "end_time" in seasons[0]: - values["end_time"] = seasons[0]["end_time"] - - return values - class APCShadowFloorNode(FloorNode): """Node for a apocalyptic shadow floor."""