From ce9a91f1115b9dfb876989136f813a64234d4666 Mon Sep 17 00:00:00 2001 From: yupix Date: Mon, 4 Dec 2023 17:41:59 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20AvatarDecoration=20=E3=83=A2=E3=83=87?= =?UTF-8?q?=E3=83=AB=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit chore: DocStringを追加 chore: 型を修正 --- mipac/models/lite/user.py | 109 ++++++++++++++++++++++++++++++++------ 1 file changed, 94 insertions(+), 15 deletions(-) diff --git a/mipac/models/lite/user.py b/mipac/models/lite/user.py index 96e792f6..d07cca77 100644 --- a/mipac/models/lite/user.py +++ b/mipac/models/lite/user.py @@ -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: @@ -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 @@ -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 @@ -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 @@ -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: @@ -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: