Skip to content

Commit

Permalink
feat: AvatarDecoration モデルを追加
Browse files Browse the repository at this point in the history
chore: DocStringを追加
chore: 型を修正
  • Loading branch information
yupix committed Dec 4, 2023
1 parent 957b181 commit ce9a91f
Showing 1 changed file with 94 additions and 15 deletions.
109 changes: 94 additions & 15 deletions mipac/models/lite/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

from typing import TYPE_CHECKING, Generic, TypeVar

from mipac.abstract.model import AbstractModel
from mipac.models.lite.instance import LiteInstance
from mipac.types.user import IBadgeRole, IPartialUser, IUserOnlineStatus
from mipac.types.user import IBadgeRole, IPartialUser, IUserOnlineStatus, IAvatarDecoration
from mipac.utils.util import deprecated

if TYPE_CHECKING:
Expand All @@ -15,7 +14,7 @@
PU = TypeVar("PU", bound=IPartialUser)


class BadgeRole(AbstractModel, Generic[T]):
class BadgeRole(Generic[T]):
def __init__(self, data: T, *, client: ClientManager) -> None:
self._data: T = data
self._client = client
Expand All @@ -36,7 +35,57 @@ def display_order(self) -> int:
return self._data["display_order"]


class PartialUser(AbstractModel, Generic[PU]):
class AvatarDecoration:
def __init__(self, raw_avatar_decoration: IAvatarDecoration, *, client: ClientManager) -> None:
self.__raw_avatar_decoration: IAvatarDecoration = raw_avatar_decoration
self.__client: ClientManager = client

@property
def id(self) -> str:
"""Returns the id of the avatar decoration.
Returns
-------
str
The id of the avatar decoration.
"""
return self.__raw_avatar_decoration["id"]

@property
def angle(self) -> int:
"""Returns the angle of the avatar decoration.
Returns
-------
int
The angle of the avatar decoration.
"""
return self.__raw_avatar_decoration["angle"]

@property
def flip_h(self) -> bool:
"""Returns whether the avatar decoration is flipped horizontally.
Returns
-------
bool
Whether the avatar decoration is flipped horizontally.
"""
return self.__raw_avatar_decoration["flip_h"]

@property
def url(self) -> str:
"""Returns the url of the avatar decoration.
Returns
-------
str
The url of the avatar decoration.
"""
return self.__raw_avatar_decoration["url"]


class PartialUser(Generic[PU]):
def __init__(self, raw_user: PU, *, client: ClientManager) -> None:
self._raw_user: PU = raw_user
self._client: ClientManager = client
Expand All @@ -49,7 +98,27 @@ def id(self) -> str:
@deprecated
@property
def nickname(self) -> str | None:
"""Returns the nickname of the user."""
"""Returns the nickname of the user.
.. deprecated:: 0.6.0
Use :meth:`mipac.models.lite.user.PartialUser.name` instead.
Returns
-------
str | None
The nickname of the user.
"""
return self._raw_user["name"]

@property
def name(self) -> str | None:
"""Returns the nickname of the user.
Returns
-------
str | None
The nickname of the user.
"""
return self._raw_user["name"]

@property
Expand All @@ -63,24 +132,32 @@ def host(self) -> str | None:
return self._raw_user["host"]

@property
def avatar_url(self) -> str:
def avatar_url(self) -> str | None:
"""Returns the avatar url of the user."""
return self._raw_user["avatar_url"]

@property
def avatar_blurhash(self) -> str:
def avatar_blurhash(self) -> str | None:
"""Returns the avatar blurhash of the user."""
return self._raw_user["avatar_blurhash"]

@property
def is_bot(self) -> bool:
def avatar_decoration(self) -> list[AvatarDecoration]:
"""Returns the avatar decoration of the user."""
return [
AvatarDecoration(data, client=self._client)
for data in self._raw_user["avatar_decoration"]
]

@property
def is_bot(self) -> bool | None:
"""Returns whether the user is a bot."""
return self._raw_user["is_bot"]
return self._raw_user.get("is_bot")

@property
def is_cat(self) -> bool:
def is_cat(self) -> bool | None:
"""Returns whether the user is a cat."""
return self._raw_user["is_cat"]
return self._raw_user.get("is_cat")

@property
def instance(self) -> LiteInstance | None:
Expand All @@ -99,11 +176,13 @@ def online_status(self) -> IUserOnlineStatus:
return self._raw_user["online_status"]

@property
def badge_roles(self) -> list[BadgeRole]:
def badge_roles(self) -> list[BadgeRole] | None:
"""Returns the badge roles of the user."""
return [
BadgeRole(data, client=self._client) for data in self._raw_user.get("badge_roles", [])
]
return (
[BadgeRole(data, client=self._client) for data in self._raw_user["badge_roles"]]
if self._raw_user.get("badge_roles")
else None
)

@property
def api(self) -> UserManager:
Expand Down

0 comments on commit ce9a91f

Please sign in to comment.