2022-07-05 08:46:47 +00:00
|
|
|
import logging
|
|
|
|
|
2022-07-05 06:39:17 +00:00
|
|
|
from pydantic import BaseModel, Field
|
2022-07-29 05:26:48 +00:00
|
|
|
from typing import List, Any, Union
|
2022-07-05 06:39:17 +00:00
|
|
|
|
2022-08-14 09:44:47 +00:00
|
|
|
from .utils import IconAsset
|
|
|
|
|
2022-07-16 19:36:26 +00:00
|
|
|
from ..assets import Assets
|
2022-08-03 07:50:15 +00:00
|
|
|
from ..enum import ElementType
|
2022-06-22 06:14:31 +00:00
|
|
|
|
2022-07-05 08:46:47 +00:00
|
|
|
LOGGER = logging.getLogger(__name__)
|
2022-07-29 04:31:21 +00:00
|
|
|
|
2022-08-17 04:54:16 +00:00
|
|
|
__all__ = (
|
|
|
|
'ProfilePicture',
|
|
|
|
'showAvatar',
|
|
|
|
'Namecard',
|
|
|
|
'PlayerInfo'
|
|
|
|
)
|
2022-07-29 04:31:21 +00:00
|
|
|
|
2022-06-22 06:14:31 +00:00
|
|
|
class ProfilePicture(BaseModel):
|
2022-07-05 06:39:17 +00:00
|
|
|
"""
|
|
|
|
API Response data
|
|
|
|
"""
|
|
|
|
id: int = Field(0, alias="avatarId")
|
|
|
|
|
|
|
|
"""
|
|
|
|
Custom add data
|
|
|
|
"""
|
2022-11-19 08:48:08 +00:00
|
|
|
icon: IconAsset = None
|
2022-07-05 06:39:17 +00:00
|
|
|
|
2022-08-17 04:54:16 +00:00
|
|
|
def __init__(self, **data: Any) -> None:
|
2022-07-05 06:39:17 +00:00
|
|
|
super().__init__(**data)
|
|
|
|
|
|
|
|
# Get character
|
2022-07-29 04:31:21 +00:00
|
|
|
LOGGER.debug("=== Avatar ===")
|
2022-07-29 05:26:48 +00:00
|
|
|
if "avatarId" in data:
|
2022-08-03 07:50:15 +00:00
|
|
|
if "costumeId" in data:
|
|
|
|
_data = Assets.character_costume(str(data["costumeId"]))
|
|
|
|
icon = _data.images if _data is not None else _data
|
|
|
|
else:
|
|
|
|
icon = Assets.character_icon(str(data["avatarId"]))
|
2022-07-16 19:36:26 +00:00
|
|
|
|
2022-07-29 05:26:48 +00:00
|
|
|
if not icon:
|
|
|
|
return
|
2022-07-29 04:31:21 +00:00
|
|
|
|
2022-11-19 08:48:08 +00:00
|
|
|
self.icon = icon.icon
|
2022-06-22 06:14:31 +00:00
|
|
|
|
2022-07-29 04:31:21 +00:00
|
|
|
|
2022-06-22 06:14:31 +00:00
|
|
|
class showAvatar(BaseModel):
|
2022-07-05 06:39:17 +00:00
|
|
|
"""
|
|
|
|
API Response data
|
|
|
|
"""
|
|
|
|
id: str = Field(0, alias="avatarId")
|
|
|
|
level: int = 1
|
|
|
|
|
|
|
|
"""
|
|
|
|
Custom data
|
|
|
|
"""
|
|
|
|
name: str = ""
|
2022-08-15 20:17:52 +00:00
|
|
|
icon: IconAsset = None
|
2022-08-03 07:50:15 +00:00
|
|
|
element: ElementType = ElementType.Unknown
|
2022-07-05 06:39:17 +00:00
|
|
|
|
2022-08-17 04:54:16 +00:00
|
|
|
def __init__(self, **data: Any) -> None:
|
2022-07-05 06:39:17 +00:00
|
|
|
super().__init__(**data)
|
|
|
|
|
|
|
|
# Get character
|
2022-07-29 04:31:21 +00:00
|
|
|
LOGGER.debug("=== Character preview ===")
|
2022-08-03 07:50:15 +00:00
|
|
|
|
2022-08-17 04:54:16 +00:00
|
|
|
# Find traveler
|
2022-07-16 19:36:26 +00:00
|
|
|
character_preview = Assets.character(str(data["avatarId"]))
|
2022-07-05 08:46:47 +00:00
|
|
|
|
|
|
|
if not character_preview:
|
|
|
|
return
|
|
|
|
|
2022-08-17 04:54:16 +00:00
|
|
|
self.element = character_preview.element
|
2022-08-03 07:50:15 +00:00
|
|
|
|
|
|
|
if "costumeId" in data:
|
|
|
|
_data = Assets.character_costume(str(data["costumeId"]))
|
|
|
|
if _data:
|
2022-08-17 04:54:16 +00:00
|
|
|
self.icon = _data.images.icon
|
2022-08-03 07:50:15 +00:00
|
|
|
else:
|
2022-08-17 04:54:16 +00:00
|
|
|
self.icon = character_preview.images.icon
|
2022-07-05 08:46:47 +00:00
|
|
|
|
|
|
|
# Get name hash map
|
2022-07-16 19:36:26 +00:00
|
|
|
_name = Assets.get_hash_map(str(character_preview.hash_id))
|
2022-07-05 06:39:17 +00:00
|
|
|
|
2022-07-05 08:46:47 +00:00
|
|
|
if _name is None:
|
2022-07-29 04:31:21 +00:00
|
|
|
return
|
2022-07-05 08:46:47 +00:00
|
|
|
|
2022-08-17 04:54:16 +00:00
|
|
|
self.name = _name
|
2022-07-29 04:31:21 +00:00
|
|
|
|
2022-07-05 06:39:17 +00:00
|
|
|
|
|
|
|
class Namecard(BaseModel):
|
|
|
|
id: int = 0
|
|
|
|
name: str = ""
|
2022-08-14 09:44:47 +00:00
|
|
|
icon: IconAsset = None
|
|
|
|
banner: IconAsset = None
|
|
|
|
navbar: IconAsset = None
|
2022-07-05 06:39:17 +00:00
|
|
|
|
2022-08-17 04:54:16 +00:00
|
|
|
def __init__(self, **data: Any) -> None:
|
2022-07-05 06:39:17 +00:00
|
|
|
super().__init__(**data)
|
|
|
|
|
2022-08-17 04:54:16 +00:00
|
|
|
if self.id > 0:
|
2022-07-29 04:31:21 +00:00
|
|
|
LOGGER.debug("=== Namecard ===")
|
2022-07-05 06:39:17 +00:00
|
|
|
# Get name card
|
2022-08-17 04:54:16 +00:00
|
|
|
namecard = Assets.namecards(str(self.id))
|
2022-07-05 06:39:17 +00:00
|
|
|
|
2022-07-05 08:46:47 +00:00
|
|
|
if not namecard:
|
|
|
|
return
|
|
|
|
|
2022-08-17 04:54:16 +00:00
|
|
|
self.icon = namecard.icon
|
|
|
|
self.banner = namecard.banner
|
|
|
|
self.navbar = namecard.navbar
|
2022-07-05 08:46:47 +00:00
|
|
|
|
2022-07-16 19:36:26 +00:00
|
|
|
_name = Assets.get_hash_map(str(namecard.hash_id))
|
2022-07-05 08:46:47 +00:00
|
|
|
if _name is None:
|
2022-07-29 04:31:21 +00:00
|
|
|
return
|
2022-07-05 08:46:47 +00:00
|
|
|
|
2022-08-17 04:54:16 +00:00
|
|
|
self.name = _name
|
2022-06-22 06:14:31 +00:00
|
|
|
|
2022-07-29 04:31:21 +00:00
|
|
|
|
2022-06-22 06:14:31 +00:00
|
|
|
class PlayerInfo(BaseModel):
|
2022-07-05 06:39:17 +00:00
|
|
|
"""
|
|
|
|
API Response data
|
|
|
|
"""
|
2022-06-22 06:14:31 +00:00
|
|
|
# Profile info
|
2022-07-05 06:39:17 +00:00
|
|
|
achievement: int = Field(0, alias="finishAchievementNum")
|
|
|
|
level: int = 0
|
|
|
|
nickname: str = ""
|
|
|
|
signature: str = ""
|
|
|
|
world_level: int = Field(1, alias="worldLevel")
|
2022-11-19 08:48:08 +00:00
|
|
|
avatar: ProfilePicture = Field(None, alias="profilePicture")
|
2022-06-22 06:14:31 +00:00
|
|
|
# Avatars
|
2022-08-15 20:17:52 +00:00
|
|
|
characters_preview: List[showAvatar] = Field([], alias="showAvatarInfoList")
|
2022-06-22 06:14:31 +00:00
|
|
|
# Abyss floor
|
2022-07-05 06:39:17 +00:00
|
|
|
abyss_floor: int = Field(0, alias="towerFloorIndex")
|
|
|
|
abyss_room: int = Field(0, alias="towerLevelIndex")
|
|
|
|
|
|
|
|
"""
|
|
|
|
Custom data
|
|
|
|
"""
|
2022-08-17 04:54:16 +00:00
|
|
|
namecard: Namecard = Namecard() # Profile name-card
|
|
|
|
namecards: List[Namecard] = [] # List name-card preview in profile
|
2022-07-05 06:39:17 +00:00
|
|
|
|
2022-08-17 04:54:16 +00:00
|
|
|
def __init__(self, **data: Any) -> None:
|
2022-07-05 06:39:17 +00:00
|
|
|
super().__init__(**data)
|
2022-07-29 04:31:21 +00:00
|
|
|
|
2022-08-17 04:54:16 +00:00
|
|
|
self.namecard = Namecard(id=data["nameCardId"])
|
|
|
|
self.namecards = [Namecard(id=namecard) for namecard in (data["showNameCardIdList"])] if "showNameCardIdList" in data else [] # noqa: E501
|