mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-09-04 08:56:19 +00:00
Support for avatar decorations
Co-authored-by: Danny <1695103+Rapptz@users.noreply.github.com> Co-authored-by: owocado <24418520+owocado@users.noreply.github.com>
This commit is contained in:
@ -31,7 +31,7 @@ from .asset import Asset
|
||||
from .colour import Colour
|
||||
from .enums import DefaultAvatar
|
||||
from .flags import PublicUserFlags
|
||||
from .utils import snowflake_time, _bytes_to_base64_data, MISSING
|
||||
from .utils import snowflake_time, _bytes_to_base64_data, MISSING, _get_as_snowflake
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from typing_extensions import Self
|
||||
@ -43,10 +43,7 @@ if TYPE_CHECKING:
|
||||
from .message import Message
|
||||
from .state import ConnectionState
|
||||
from .types.channel import DMChannel as DMChannelPayload
|
||||
from .types.user import (
|
||||
PartialUser as PartialUserPayload,
|
||||
User as UserPayload,
|
||||
)
|
||||
from .types.user import PartialUser as PartialUserPayload, User as UserPayload, AvatarDecorationData
|
||||
|
||||
|
||||
__all__ = (
|
||||
@ -73,6 +70,7 @@ class BaseUser(_UserTag):
|
||||
'system',
|
||||
'_public_flags',
|
||||
'_state',
|
||||
'_avatar_decoration_data',
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@ -87,6 +85,7 @@ class BaseUser(_UserTag):
|
||||
_banner: Optional[str]
|
||||
_accent_colour: Optional[int]
|
||||
_public_flags: int
|
||||
_avatar_decoration_data: Optional[AvatarDecorationData]
|
||||
|
||||
def __init__(self, *, state: ConnectionState, data: Union[UserPayload, PartialUserPayload]) -> None:
|
||||
self._state = state
|
||||
@ -123,6 +122,7 @@ class BaseUser(_UserTag):
|
||||
self._public_flags = data.get('public_flags', 0)
|
||||
self.bot = data.get('bot', False)
|
||||
self.system = data.get('system', False)
|
||||
self._avatar_decoration_data = data.get('avatar_decoration_data')
|
||||
|
||||
@classmethod
|
||||
def _copy(cls, user: Self) -> Self:
|
||||
@ -138,6 +138,7 @@ class BaseUser(_UserTag):
|
||||
self.bot = user.bot
|
||||
self._state = user._state
|
||||
self._public_flags = user._public_flags
|
||||
self._avatar_decoration_data = user._avatar_decoration_data
|
||||
|
||||
return self
|
||||
|
||||
@ -187,6 +188,30 @@ class BaseUser(_UserTag):
|
||||
"""
|
||||
return self.avatar or self.default_avatar
|
||||
|
||||
@property
|
||||
def avatar_decoration(self) -> Optional[Asset]:
|
||||
"""Optional[:class:`Asset`]: Returns an :class:`Asset` for the avatar decoration the user has.
|
||||
|
||||
If the user has not set an avatar decoration, ``None`` is returned.
|
||||
|
||||
.. versionadded:: 2.4
|
||||
"""
|
||||
if self._avatar_decoration_data is not None:
|
||||
return Asset._from_avatar_decoration(self._state, self._avatar_decoration_data['asset'])
|
||||
return None
|
||||
|
||||
@property
|
||||
def avatar_decoration_sku_id(self) -> Optional[int]:
|
||||
"""Optional[:class:`int`]: Returns the SKU ID of the avatar decoration the user has.
|
||||
|
||||
If the user has not set an avatar decoration, ``None`` is returned.
|
||||
|
||||
.. versionadded:: 2.4
|
||||
"""
|
||||
if self._avatar_decoration_data is not None:
|
||||
return _get_as_snowflake(self._avatar_decoration_data, 'sku_id')
|
||||
return None
|
||||
|
||||
@property
|
||||
def banner(self) -> Optional[Asset]:
|
||||
"""Optional[:class:`Asset`]: Returns the user's banner asset, if available.
|
||||
|
Reference in New Issue
Block a user