mirror of
https://github.com/PaiGramTeam/SIMNet.git
synced 2024-11-16 12:02:17 +00:00
✨ Support genshin and starrail achievement info
This commit is contained in:
parent
f47d7693c0
commit
4ee5e5d801
@ -1,10 +1,10 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
from typing import Optional, Any, List, Dict, Union
|
from typing import Optional, Any, List, Dict, Union
|
||||||
|
|
||||||
from simnet.client.components.chronicle.base import BaseChronicleClient
|
from simnet.client.components.chronicle.base import BaseChronicleClient
|
||||||
from simnet.client.routes import RECORD_URL
|
from simnet.client.routes import RECORD_URL
|
||||||
from simnet.errors import DataNotPublic, BadRequest
|
from simnet.errors import DataNotPublic, BadRequest
|
||||||
from simnet.models.genshin.chronicle.abyss import SpiralAbyss, SpiralAbyssPair
|
from simnet.models.genshin.chronicle.abyss import SpiralAbyss, SpiralAbyssPair
|
||||||
|
from simnet.models.genshin.chronicle.achievement import GenshinAchievementInfo
|
||||||
from simnet.models.genshin.chronicle.character_detail import GenshinCharacterListInfo, GenshinDetailCharacters
|
from simnet.models.genshin.chronicle.character_detail import GenshinCharacterListInfo, GenshinDetailCharacters
|
||||||
from simnet.models.genshin.chronicle.characters import Character
|
from simnet.models.genshin.chronicle.characters import Character
|
||||||
from simnet.models.genshin.chronicle.img_theater import ImgTheater
|
from simnet.models.genshin.chronicle.img_theater import ImgTheater
|
||||||
@ -368,3 +368,18 @@ class GenshinBattleChronicleClient(BaseChronicleClient):
|
|||||||
"character/detail", player_id, method="POST", lang=lang, payload=payload
|
"character/detail", player_id, method="POST", lang=lang, payload=payload
|
||||||
)
|
)
|
||||||
return GenshinDetailCharacters(**data)
|
return GenshinDetailCharacters(**data)
|
||||||
|
|
||||||
|
async def get_genshin_achievement_info(
|
||||||
|
self, player_id: Optional[int] = None, *, lang: Optional[str] = None
|
||||||
|
) -> GenshinAchievementInfo:
|
||||||
|
"""Get genshin achievement info.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
player_id (Optional[int], optional): The player ID. Defaults to None.
|
||||||
|
lang (Optional[str], optional): The language of the data. Defaults to None.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
GenshinAchievementInfo: The requested achievement info.
|
||||||
|
"""
|
||||||
|
data = await self._request_genshin_record("achievement", player_id, method="POST", lang=lang)
|
||||||
|
return GenshinAchievementInfo(**data)
|
||||||
|
@ -5,6 +5,7 @@ from simnet.client.components.chronicle.base import BaseChronicleClient
|
|||||||
from simnet.client.routes import RECORD_URL
|
from simnet.client.routes import RECORD_URL
|
||||||
from simnet.errors import BadRequest, DataNotPublic
|
from simnet.errors import BadRequest, DataNotPublic
|
||||||
from simnet.models.lab.record import RecordCard
|
from simnet.models.lab.record import RecordCard
|
||||||
|
from simnet.models.starrail.chronicle.achievement import StarRailAchievementInfo
|
||||||
from simnet.models.starrail.chronicle.act_calendar import StarRailActCalendar
|
from simnet.models.starrail.chronicle.act_calendar import StarRailActCalendar
|
||||||
from simnet.models.starrail.chronicle.activity import StarRailActivity
|
from simnet.models.starrail.chronicle.activity import StarRailActivity
|
||||||
from simnet.models.starrail.chronicle.challenge import StarRailChallenge
|
from simnet.models.starrail.chronicle.challenge import StarRailChallenge
|
||||||
@ -482,3 +483,24 @@ class StarRailBattleChronicleClient(BaseChronicleClient):
|
|||||||
"""
|
"""
|
||||||
data = await self._request_starrail_record("get_ledger_month_info", uid, lang=lang)
|
data = await self._request_starrail_record("get_ledger_month_info", uid, lang=lang)
|
||||||
return StarRailLedgerMonthInfo(**data)
|
return StarRailLedgerMonthInfo(**data)
|
||||||
|
|
||||||
|
async def get_starrail_achievement_info(
|
||||||
|
self,
|
||||||
|
uid: Optional[int] = None,
|
||||||
|
lang: Optional[str] = None,
|
||||||
|
) -> StarRailAchievementInfo:
|
||||||
|
"""Get StarRail achievement 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:
|
||||||
|
StarRailAchievementInfo: The requested achievement info.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
BadRequest: If the request is invalid.
|
||||||
|
DataNotPublic: If the requested data is not public.
|
||||||
|
"""
|
||||||
|
data = await self._request_starrail_record("achievement_info", uid, lang=lang)
|
||||||
|
return StarRailAchievementInfo(**data)
|
||||||
|
47
simnet/models/genshin/chronicle/achievement.py
Normal file
47
simnet/models/genshin/chronicle/achievement.py
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
from typing import List
|
||||||
|
|
||||||
|
from simnet.models.base import APIModel
|
||||||
|
|
||||||
|
|
||||||
|
class GenshinAchievementInfoList(APIModel):
|
||||||
|
"""
|
||||||
|
Represents a list of achievement information for Genshin.
|
||||||
|
|
||||||
|
Attributes:
|
||||||
|
id (int): The unique identifier of the achievement.
|
||||||
|
name (str): The name of the achievement.
|
||||||
|
icon (str): The URL or path to the icon representing the achievement.
|
||||||
|
finish_num (int): The number of times the achievement has been completed.
|
||||||
|
percentage (int): The completion percentage of the achievement.
|
||||||
|
show_percent (bool): Indicates whether the percentage should be displayed.
|
||||||
|
"""
|
||||||
|
|
||||||
|
id: int
|
||||||
|
name: str
|
||||||
|
icon: str
|
||||||
|
finish_num: int
|
||||||
|
percentage: int
|
||||||
|
show_percent: bool
|
||||||
|
|
||||||
|
@property
|
||||||
|
def max(self) -> int:
|
||||||
|
"""
|
||||||
|
Calculates the maximum number of times the achievement can be completed.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
int: The maximum completion value if `show_percent` is True, otherwise 0.
|
||||||
|
"""
|
||||||
|
return int(self.finish_num / (self.percentage / 100.0)) if self.percentage else 0
|
||||||
|
|
||||||
|
|
||||||
|
class GenshinAchievementInfo(APIModel):
|
||||||
|
"""
|
||||||
|
Represents the achievement information for Genshin.
|
||||||
|
|
||||||
|
Attributes:
|
||||||
|
achievement_num (int): The number of owned achievements.
|
||||||
|
list (List[StarRailAchievementInfoList]): A list of achievement info objects.
|
||||||
|
"""
|
||||||
|
|
||||||
|
achievement_num: int
|
||||||
|
list: List[GenshinAchievementInfoList]
|
51
simnet/models/starrail/chronicle/achievement.py
Normal file
51
simnet/models/starrail/chronicle/achievement.py
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
from typing import List
|
||||||
|
|
||||||
|
from simnet.models.base import APIModel
|
||||||
|
|
||||||
|
|
||||||
|
class StarRailAchievementInfoList(APIModel):
|
||||||
|
"""
|
||||||
|
Represents a list of achievement information for Star Rail.
|
||||||
|
|
||||||
|
Attributes:
|
||||||
|
series_id (int): The ID of the achievement series.
|
||||||
|
name (str): The name of the achievement.
|
||||||
|
icon (str): The icon representing the achievement.
|
||||||
|
cur (int): The current progress of the achievement.
|
||||||
|
max (int): The maximum progress required for the achievement.
|
||||||
|
"""
|
||||||
|
|
||||||
|
series_id: int
|
||||||
|
name: str
|
||||||
|
icon: str
|
||||||
|
cur: int
|
||||||
|
max: int
|
||||||
|
|
||||||
|
@property
|
||||||
|
def percentage(self) -> float:
|
||||||
|
"""
|
||||||
|
Calculates the completion percentage of the achievement.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
float: The completion percentage of the achievement.
|
||||||
|
"""
|
||||||
|
return round(self.cur * 1.00 / self.max * 100, 2)
|
||||||
|
|
||||||
|
|
||||||
|
class StarRailAchievementInfo(APIModel):
|
||||||
|
"""
|
||||||
|
Represents the achievement information for Star Rail.
|
||||||
|
|
||||||
|
Attributes:
|
||||||
|
gold_num (int): The number of gold achievements.
|
||||||
|
silver_num (int): The number of silver achievements.
|
||||||
|
copper_num (int): The number of copper achievements.
|
||||||
|
list (List[StarRailAchievementInfoList]): A list of achievement info objects.
|
||||||
|
strategy_url (str): The URL for the achievement strategy.
|
||||||
|
"""
|
||||||
|
|
||||||
|
gold_num: int
|
||||||
|
silver_num: int
|
||||||
|
copper_num: int
|
||||||
|
list: List[StarRailAchievementInfoList]
|
||||||
|
strategy_url: str
|
Loading…
Reference in New Issue
Block a user