diff --git a/discord/enums.py b/discord/enums.py index 202ce46f3d6b..67360913cbaf 100644 --- a/discord/enums.py +++ b/discord/enums.py @@ -40,6 +40,8 @@ 'AuditLogAction', 'AuditLogActionCategory', 'UserFlags', + 'NameFont', + 'NameEffect', 'ActivityType', 'NotificationLevel', 'HighlightLevel', @@ -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 diff --git a/discord/types/user.py b/discord/types/user.py index ae8ca1ef7d8a..d0cf33cbbced 100644 --- a/discord/types/user.py +++ b/discord/types/user.py @@ -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[ @@ -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): @@ -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 diff --git a/discord/user.py b/discord/user.py index 0803482ab411..83d89ce455c7 100644 --- a/discord/user.py +++ b/discord/user.py @@ -35,6 +35,8 @@ PremiumType, RelationshipAction, RelationshipType, + NameEffect, + NameFont, try_enum, ) from .errors import NotFound @@ -73,6 +75,7 @@ UserAvatar as UserAvatarPayload, AvatarDecorationData, PrimaryGuild as PrimaryGuildPayload, + DisplayNameStyle as DisplayNameStylePayload ) from .types.snowflake import Snowflake @@ -81,6 +84,7 @@ 'User', 'ClientUser', 'RecentAvatar', + 'DisplayNameStyle', ) @@ -88,6 +92,27 @@ 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'' class BaseUser(_UserTag): __slots__ = ( @@ -105,6 +130,7 @@ class BaseUser(_UserTag): 'premium_type', '_state', '_primary_guild', + '_display_name_style', ) if TYPE_CHECKING: @@ -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 @@ -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: @@ -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 @@ -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 @@ -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. @@ -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'], @@ -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) @@ -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 diff --git a/docs/api.rst b/docs/api.rst index 0d13f40d32c2..31114428537a 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -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 @@ -7301,6 +7381,11 @@ User .. autoclass:: PrimaryGuild() :members: +.. attributetable:: DisplayNameStyle + +.. autoclass:: DisplayNameStyle() + :members: + Affinity ~~~~~~~~~