Skip to content
Merged
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
23 changes: 23 additions & 0 deletions discord/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
'AuditLogAction',
'AuditLogActionCategory',
'UserFlags',
'NameFont',
'NameEffect',
'ActivityType',
'NotificationLevel',
'HighlightLevel',
Expand Down Expand Up @@ -694,6 +696,27 @@ class UserFlags(Enum):
collaborator = 1125899906842624
restricted_collaborator = 2251799813685248

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

class ActivityType(Enum):
unknown = -1
Expand Down
9 changes: 9 additions & 0 deletions discord/types/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class PartialUser(TypedDict):
system: NotRequired[bool]
global_name: Optional[str]
primary_guild: NotRequired[Optional[PrimaryGuild]]
display_name_styles: Optional[DisplayNameStyle]


ConnectionType = Literal[
Expand Down Expand Up @@ -70,6 +71,8 @@ class PartialUser(TypedDict):
]
ConnectionVisibilty = Literal[0, 1]
PremiumType = Literal[0, 1, 2, 3]
DisplayNameFont = Literal[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
DisplayNameEffect = Literal[1, 2, 3, 4, 5, 6]


class APIUser(PartialUser):
Expand All @@ -96,6 +99,12 @@ class User(APIUser, total=False):
mobile: bool


class DisplayNameStyle(TypedDict):
font_id: DisplayNameFont
effect_id: DisplayNameEffect
colors: List[int] # 1-2


class UserWithToken(User):
token: str

Expand Down
43 changes: 43 additions & 0 deletions discord/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
PremiumType,
RelationshipAction,
RelationshipType,
NameEffect,
NameFont,
try_enum,
)
from .errors import NotFound
Expand Down Expand Up @@ -73,6 +75,7 @@
UserAvatar as UserAvatarPayload,
AvatarDecorationData,
PrimaryGuild as PrimaryGuildPayload,
DisplayNameStyle as DisplayNameStylePayload
)
from .types.snowflake import Snowflake

Expand All @@ -81,13 +84,35 @@
'User',
'ClientUser',
'RecentAvatar',
'DisplayNameStyle',
)


class _UserTag:
__slots__ = ()
id: int

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

.. versionadded:: 2.1

Attributes
-----------
font: :class:`NameFont`
The font used for the display name.
effect: :class:`NameEffect`
The visual effect applied to the display name.
colors: List[:class:`Colour`]
The list of colours applied to the display name.
"""
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 BaseUser(_UserTag):
__slots__ = (
Expand All @@ -105,6 +130,7 @@ class BaseUser(_UserTag):
'premium_type',
'_state',
'_primary_guild',
'_display_name_style',
)

if TYPE_CHECKING:
Expand All @@ -121,6 +147,7 @@ class BaseUser(_UserTag):
_accent_colour: Optional[int]
_public_flags: int
_primary_guild: Optional[PrimaryGuildPayload]
_display_name_style: Optional[DisplayNameStylePayload]

def __init__(self, *, state: ConnectionState, data: Union[UserPayload, PartialUserPayload]) -> None:
self._state = state
Expand Down Expand Up @@ -159,6 +186,7 @@ def _update(self, data: Union[UserPayload, PartialUserPayload]) -> None:
self.bot = data.get('bot', False)
self.system = data.get('system', False)
self._primary_guild = data.get('primary_guild', None)
self._display_name_style = data.get('display_name_styles', None) or None

@classmethod
def _copy(cls, user: Self) -> Self:
Expand All @@ -177,6 +205,7 @@ def _copy(cls, user: Self) -> Self:
self.system = user.system
self._state = user._state
self._primary_guild = user._primary_guild
self._display_name_style = user._display_name_style

return self

Expand All @@ -194,6 +223,7 @@ def _to_minimal_user_json(self) -> APIUserPayload:
'banner': self._banner,
'accent_color': self._accent_colour,
'primary_guild': self._primary_guild,
'display_name_styles': self._display_name_style,
}
return user

Expand Down Expand Up @@ -383,6 +413,16 @@ def primary_guild(self) -> PrimaryGuild:
return PrimaryGuild(state=self._state, data=self._primary_guild)
return PrimaryGuild._default(self._state)

@property
def display_name_style(self) -> Optional[DisplayNameStyle]:
""":class:`DisplayNameStyle`: Returns the user's display name style.

.. versionadded:: 2.1
"""
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 Expand Up @@ -1021,6 +1061,7 @@ def _update_self(self, user: Union[PartialUserPayload, Tuple[()]]) -> Optional[T
self._avatar_decoration_data,
self.global_name,
self._primary_guild,
self._display_name_style,
)
modified = (
user['username'],
Expand All @@ -1030,6 +1071,7 @@ def _update_self(self, user: Union[PartialUserPayload, Tuple[()]]) -> Optional[T
user.get('avatar_decoration_data'),
user.get('global_name'),
user.get('primary_guild'),
user.get('display_name_styles'),
)
if original != modified:
to_return = User._copy(self)
Expand All @@ -1041,6 +1083,7 @@ def _update_self(self, user: Union[PartialUserPayload, Tuple[()]]) -> Optional[T
self._avatar_decoration_data,
self.global_name,
self._primary_guild,
self._display_name_style,
) = modified
# Signal to dispatch user_update
return to_return, self
Expand Down
85 changes: 85 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2179,6 +2179,86 @@ of :class:`enum.Enum`.

.. versionadded:: 2.1

.. class:: NameFont

Specifies the font of :class:`DisplayNameStyle`.

.. attribute:: default

The default font.

.. attribute:: bangers

"Bangers" font.

.. attribute:: bio_rhyme

"BioRhyme" font.

.. attribute:: cherry_bomb

"Cherry Bomb One" font.

.. attribute:: chicle

"Chicle" font.

.. attribute:: compagnon

"Compagnon" font.

.. attribute:: museo_moderno

"MuseoModerno" font.

.. attribute:: neo_castel

"Néo-Castel" font.

.. attribute:: pixelify

"Pixelify Sans" font.

.. attribute:: ribes

"Ribes" font.

.. attribute:: sinistre

"Sinistre" font.

.. attribute:: zilla_slab

"Zilla Slab" font.

.. class:: NameEffect

Specifies the effect of :class:`DisplayNameStyle`.

.. attribute:: solid

Displays the first color provided.

.. attribute:: gradient

Two color gradient.

.. attribute:: neon

Glow around the name.

.. attribute:: toon

Subtle vertical gradient and stroke.

.. attribute:: pop

Colored dropshadow.

.. attribute:: glow

Alternate gradient style.

.. class:: ActivityType

Specifies the type of :class:`Activity`. This is used to check how to
Expand Down Expand Up @@ -7301,6 +7381,11 @@ User
.. autoclass:: PrimaryGuild()
:members:

.. attributetable:: DisplayNameStyle

.. autoclass:: DisplayNameStyle()
:members:

Affinity
~~~~~~~~~

Expand Down
Loading