|
|
|
@ -2,9 +2,8 @@ from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
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 @@ T = TypeVar("T", bound=IBadgeRole)
|
|
|
|
|
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 @@ class BadgeRole(AbstractModel, Generic[T]):
|
|
|
|
|
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 @@ class PartialUser(AbstractModel, Generic[PU]):
|
|
|
|
|
@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 @@ class PartialUser(AbstractModel, Generic[PU]):
|
|
|
|
|
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 @@ class PartialUser(AbstractModel, Generic[PU]):
|
|
|
|
|
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:
|
|
|
|
|