Support starrail activity - FantasticStory

This commit is contained in:
omg-xtao 2023-07-21 17:11:30 +08:00 committed by GitHub
parent 63ce8a249e
commit 2e50bf2081
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 59 additions and 7 deletions

View File

@ -31,7 +31,7 @@ class RogueCharacter(StarRailBaseCharacter):
level: int level: int
class StarFightCharacter(StarRailBaseCharacter): class ActivityCharacter(StarRailBaseCharacter):
"""Combat character model.""" """Combat character model."""
level: int level: int

View File

@ -2,7 +2,7 @@
from typing import List, Optional from typing import List, Optional
from simnet.models.base import APIModel from simnet.models.base import APIModel
from simnet.models.starrail.character import StarFightCharacter from simnet.models.starrail.character import ActivityCharacter
from .base import PartialTime from .base import PartialTime
@ -25,7 +25,7 @@ class StarRailStarFightRecord(APIModel):
round: int round: int
stage_id: int stage_id: int
time: Optional[PartialTime] time: Optional[PartialTime]
lineup: List[StarFightCharacter] lineup: List[ActivityCharacter]
@property @property
def time_str(self) -> str: def time_str(self) -> str:
@ -42,16 +42,66 @@ class StarRailStarFight(StarRailActivityBase):
records: List[StarRailStarFightRecord] records: List[StarRailStarFightRecord]
class StarRailFantasticStoryBuff(APIModel):
"""Fantastic Story Buff"""
id: int
name: str
desc: str
icon: str
class StarRailFantasticStoryRecord(APIModel):
"""Fantastic Story Record"""
name: str
score: int
score_rank: int
stage_id: int
finish_time: Optional[PartialTime]
avatars: List[ActivityCharacter]
buffs: List[StarRailFantasticStoryBuff]
@property
def time_str(self) -> str:
"""Get the time as a string."""
if self.finish_time is None:
return "N/A"
return self.finish_time.datetime.strftime("%Y.%m.%d %H:%M")
class StarRailFantasticStory(StarRailActivityBase):
"""Fantastic Story"""
records: List[StarRailFantasticStoryRecord]
class StarRailActivity(APIModel): class StarRailActivity(APIModel):
"""Starrail chronicle activity.""" """Starrail chronicle activity."""
activities: List activities: List
def find_activity(self, key: str) -> Optional[dict]:
"""Find an activity by key."""
for activity in self.activities:
if list(activity.keys())[0] == key:
return activity
return None
@property @property
def star_fight(self) -> StarRailStarFight: def star_fight(self) -> StarRailStarFight:
"""Get the star fight activity.""" """Get the star fight activity."""
for activity in self.activities: if data := self.find_activity("star_fight"):
if list(activity.keys())[0] == "star_fight": return StarRailStarFight(**data["star_fight"])
return StarRailStarFight(**activity["star_fight"])
raise ValueError("No star fight activity found.") raise ValueError("No star fight activity found.")
@property
def fantastic_story(self) -> StarRailFantasticStory:
"""Get the fantastic story activity."""
if data := self.find_activity("fantastic_story"):
return StarRailFantasticStory(**data["fantastic_story"])
raise ValueError("No fantastic story activity found.")

View File

@ -1,5 +1,6 @@
"""Starrail Chronicle Base Model.""" """Starrail Chronicle Base Model."""
import datetime import datetime
from typing import Optional
from simnet.models.base import APIModel from simnet.models.base import APIModel
@ -12,7 +13,8 @@ class PartialTime(APIModel):
day: int day: int
hour: int hour: int
minute: int minute: int
second: Optional[int] = None
@property @property
def datetime(self) -> datetime.datetime: def datetime(self) -> datetime.datetime:
return datetime.datetime(self.year, self.month, self.day, self.hour, self.minute) return datetime.datetime(self.year, self.month, self.day, self.hour, self.minute, self.second or 0)