Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions discord/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@
'MediaItemLoadingState',
'CollectibleType',
'NameplatePalette',
'NameFont',
'NameEffect',
)


Expand Down Expand Up @@ -988,6 +990,30 @@ class NameplatePalette(Enum):
white = 'white'


class NameFont(Enum):
default = 11
bangers = 1
bio_rhyme = 2
cherry_bomb = 3
chicle = 4
compagnon = 5
museo_moderno = 6
neo_castel = 7
pixelify = 8
ribes = 9
sinistre = 10
zilla_slab = 12


class NameEffect(Enum):
solid = 1
gradient = 2
neon = 3
toon = 4
pop = 5
glow = 6


def create_unknown_value(cls: Type[E], val: Any) -> E:
value_cls = cls._enum_value_cls_ # type: ignore # This is narrowed below
name = f'unknown_{val}'
Expand Down
2 changes: 2 additions & 0 deletions discord/member.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
)
from .primary_guild import PrimaryGuild
from .collectible import Collectible
from .user import DisplayNameStyle

VocalGuildChannel = Union[VoiceChannel, StageChannel]

Expand Down Expand Up @@ -313,6 +314,7 @@ class Member(discord.abc.Messageable, _UserTag):
avatar_decoration_sku_id: Optional[int]
primary_guild: PrimaryGuild
collectibles: List[Collectible]
display_name_style: DisplayNameStyle

def __init__(self, *, data: MemberWithUserPayload, guild: Guild, state: ConnectionState):
self._state: ConnectionState = state
Expand Down
11 changes: 10 additions & 1 deletion discord/types/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@
"""

from .snowflake import Snowflake
from typing import Literal, Optional, TypedDict
from typing import Literal, Optional, TypedDict, List
from typing_extensions import NotRequired


PremiumType = Literal[0, 1, 2, 3]
NameplatePallete = Literal['crimson', 'berry', 'sky', 'teal', 'forest', 'bubble_gum', 'violet', 'cobalt', 'clover']
DisplayNameFont = Literal[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
DisplayNameEffect = Literal[1, 2, 3, 4, 5]


class _UserSKU(TypedDict):
Expand Down Expand Up @@ -70,6 +72,12 @@ class PartialUser(TypedDict):
collectibles: NotRequired[UserCollectibles]


class DisplayNameStyle(TypedDict):
font_id: DisplayNameFont
effect_id: DisplayNameEffect
colors: List[int]


class User(PartialUser, total=False):
bot: bool
system: bool
Expand All @@ -80,3 +88,4 @@ class User(PartialUser, total=False):
flags: int
premium_type: PremiumType
public_flags: int
display_name_styles: DisplayNameStyle
36 changes: 35 additions & 1 deletion discord/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import discord.abc
from .asset import Asset
from .colour import Colour
from .enums import DefaultAvatar
from .enums import DefaultAvatar, NameEffect, NameFont, try_enum
from .flags import PublicUserFlags
from .utils import snowflake_time, _bytes_to_base64_data, MISSING, _get_as_snowflake
from .primary_guild import PrimaryGuild
Expand All @@ -51,15 +51,39 @@
AvatarDecorationData,
PrimaryGuild as PrimaryGuildPayload,
UserCollectibles as UserCollectiblesPayload,
DisplayNameStyle as DisplayNameStylePayload,
)


__all__ = (
'User',
'ClientUser',
'DisplayNameStyle',
)


class DisplayNameStyle:
"""Represents a user's display name style.

Attributes
-----------
font: :class:`NameFont`
The font.
effect: :class:`NameEffect`
The applied effect.
colors: List[:class:`Colour`]
The colors used in the effect. Max of 2.
"""

def __init__(self, *, data: DisplayNameStylePayload) -> None:
self.font: NameFont = try_enum(NameFont, data['font_id'])
self.effect: NameEffect = try_enum(NameEffect, data['effect_id'])
self.colors: List[discord.Colour] = [discord.Colour(color) for color in data.get('colors', [])]

def __repr__(self) -> str:
return f'<DisplayNameStyle font={self.font} effect={self.effect} colors={self.colors}>'


class _UserTag:
__slots__ = ()
id: int
Expand All @@ -81,6 +105,7 @@ class BaseUser(_UserTag):
'_avatar_decoration_data',
'_primary_guild',
'_collectibles',
'_display_name_style',
)

if TYPE_CHECKING:
Expand All @@ -98,6 +123,7 @@ class BaseUser(_UserTag):
_avatar_decoration_data: Optional[AvatarDecorationData]
_primary_guild: Optional[PrimaryGuildPayload]
_collectibles: Optional[UserCollectiblesPayload]
_display_name_style: Optional[DisplayNameStylePayload]

def __init__(self, *, state: ConnectionState, data: Union[UserPayload, PartialUserPayload]) -> None:
self._state = state
Expand Down Expand Up @@ -137,6 +163,7 @@ def _update(self, data: Union[UserPayload, PartialUserPayload]) -> None:
self._avatar_decoration_data = data.get('avatar_decoration_data')
self._primary_guild = data.get('primary_guild', None)
self._collectibles = data.get('collectibles', None)
self._display_name_style = data.get('display_name_styles', None) or None

@classmethod
def _copy(cls, user: Self) -> Self:
Expand All @@ -155,6 +182,7 @@ def _copy(cls, user: Self) -> Self:
self._avatar_decoration_data = user._avatar_decoration_data
self._primary_guild = user._primary_guild
self._collectibles = user._collectibles
self._display_name_style = user._display_name_style

return self

Expand Down Expand Up @@ -340,6 +368,12 @@ def collectibles(self) -> List[Collectible]:
return []
return [Collectible(state=self._state, type=key, data=value) for key, value in self._collectibles.items() if value] # type: ignore

@property
def display_name_style(self) -> Optional[DisplayNameStyle]:
if self._display_name_style is None:
return None
return DisplayNameStyle(data=self._display_name_style)

def mentioned_in(self, message: Message) -> bool:
"""Checks if the user is mentioned in the specified message.

Expand Down
92 changes: 92 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4132,6 +4132,90 @@ of :class:`enum.Enum`.

The collectible nameplate palette is white.

.. class:: NameFont

Represents the available fonts for a user display name style.

.. versionadded:: 2.7

.. attribute:: default

The default font is used.

.. attribute:: bangers

The 'Bangers' font is used.

.. attribute:: bio_rhyme

The 'BioRhyme' font is used.

.. attribute:: cherry_bomb

The 'Cherry Bomb' font is used.

.. attribute:: chicle

The 'Chicle' font is used.

.. attribute:: compagnon

The 'Compagnon' font is used.

.. attribute:: museo_moderno

The 'Museo Moderno' font is used.

.. attribute:: neo_castel

The 'Neo Castel' font is used.

.. attribute:: pixelify

The 'Pixelify' font is used.

.. attribute:: ribes

The 'Ribes' font is used.

.. attribute:: sinistre

The 'Sinistre' font is used.

.. attribute:: zilla_slab

The 'Zilla Slab' font is used.

.. class:: NameEffect

Represents the available effects for a user display name style.

.. versionadded:: 2.7

.. attribute:: solid

The first color provided is used.

.. attribute:: gradient

There is a two colour gradient using both colors provided.

.. attribute:: neon

There is a neon glow around the name.

.. attribute:: toon

There is a subtle vertical gradient and stroke around the name.

.. attribute:: pop

A coloured dropshadow is shown.
.. attribute:: glow

An alternative for the gradient style is used.


.. _discord-api-audit-logs:

Audit Log Data
Expand Down Expand Up @@ -5836,6 +5920,14 @@ Collectible
.. autoclass:: Collectible()
:members:

DisplayNameStyle
~~~~~~~~~~~~~~~~~

.. attributetable:: DisplayNameStyle

.. autoclass:: DisplayNameStyle()
:members:

CallMessage
~~~~~~~~~~~~~~~~~~~

Expand Down
Loading