mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-04-19 15:36:02 +00:00
Add BaseUser.banner for all subclasses to access new banners
This commit is contained in:
parent
fc51736b34
commit
b47133dfb2
@ -224,6 +224,17 @@ class Asset(AssetMixin):
|
||||
animated=False,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def _from_user_banner(cls, state, user_id: int, banner_hash: str) -> Asset:
|
||||
animated = banner_hash.startswith('a_')
|
||||
format = 'gif' if animated else 'png'
|
||||
return cls(
|
||||
state,
|
||||
url=f'{cls.BASE}/banners/{user_id}/{banner_hash}.{format}?size=512',
|
||||
key=banner_hash,
|
||||
animated=animated
|
||||
)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self._url
|
||||
|
||||
|
@ -41,8 +41,8 @@ class _UserTag:
|
||||
id: int
|
||||
|
||||
|
||||
class BaseUser(_UserTag):
|
||||
__slots__ = ('name', 'id', 'discriminator', '_avatar', 'bot', 'system', '_public_flags', '_state')
|
||||
class BaseUser(_BaseUser):
|
||||
__slots__ = ('name', 'id', 'discriminator', '_avatar', '_banner', '_accent_colour', 'bot', 'system', '_public_flags', '_state')
|
||||
|
||||
if TYPE_CHECKING:
|
||||
name: str
|
||||
@ -78,6 +78,8 @@ class BaseUser(_UserTag):
|
||||
self.id = int(data['id'])
|
||||
self.discriminator = data['discriminator']
|
||||
self._avatar = data['avatar']
|
||||
self._banner = data.get('banner', None)
|
||||
self._accent_colour = data.get('accent_color', None)
|
||||
self._public_flags = data.get('public_flags', 0)
|
||||
self.bot = data.get('bot', False)
|
||||
self.system = data.get('system', False)
|
||||
@ -90,6 +92,8 @@ class BaseUser(_UserTag):
|
||||
self.id = user.id
|
||||
self.discriminator = user.discriminator
|
||||
self._avatar = user._avatar
|
||||
self._banner = user._banner
|
||||
self._accent_colour = user._accent_colour
|
||||
self.bot = user.bot
|
||||
self._state = user._state
|
||||
self._public_flags = user._public_flags
|
||||
@ -127,6 +131,50 @@ class BaseUser(_UserTag):
|
||||
""":class:`Asset`: Returns the default avatar for a given user. This is calculated by the user's discriminator."""
|
||||
return Asset._from_default_avatar(self._state, int(self.discriminator) % len(DefaultAvatar))
|
||||
|
||||
@property
|
||||
def banner(self) -> Optional[Asset]:
|
||||
"""Optional[:class:`Asset`]: Returns the user's banner asset, if available.
|
||||
|
||||
.. versionadded:: 2.0
|
||||
|
||||
|
||||
.. note::
|
||||
This information is only available via :meth:`Client.fetch_user`.
|
||||
"""
|
||||
if self._banner is None:
|
||||
return None
|
||||
return Asset._from_user_banner(self._state, self.id, self._banner)
|
||||
|
||||
@property
|
||||
def accent_colour(self) -> Optional[Colour]:
|
||||
"""Optional[:class:`Colour`]: Returns the user's accent colour, if applicable.
|
||||
|
||||
There is an alias for this named :attr:`accent_color`.
|
||||
|
||||
.. versionadded:: 2.0
|
||||
|
||||
.. note::
|
||||
|
||||
This information is only available via :meth:`Client.fetch_user`.
|
||||
"""
|
||||
if self._accent_color is None:
|
||||
return None
|
||||
return Colour(self._accent_color)
|
||||
|
||||
@property
|
||||
def accent_color(self) -> Optional[Colour]:
|
||||
"""Optional[:class:`Colour`]: Returns the user's accent color, if applicable.
|
||||
|
||||
There is an alias for this named :attr:`accent_colour`.
|
||||
|
||||
.. versionadded:: 2.0
|
||||
|
||||
.. note::
|
||||
|
||||
This information is only available via :meth:`Client.fetch_user`.
|
||||
"""
|
||||
return self.accent_colour
|
||||
|
||||
@property
|
||||
def colour(self):
|
||||
""":class:`Colour`: A property that returns a colour denoting the rendered colour
|
||||
|
Loading…
x
Reference in New Issue
Block a user