Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
22 changes: 22 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,26 @@ 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

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_style: 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]


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
22 changes: 22 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 @@ -88,6 +91,14 @@ class _UserTag:
__slots__ = ()
id: int

class DisplayNameStyle:
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 +116,7 @@ class BaseUser(_UserTag):
'premium_type',
'_state',
'_primary_guild',
'_display_name_style',
)

if TYPE_CHECKING:
Expand All @@ -121,6 +133,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 +172,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 +191,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 +209,7 @@ def _to_minimal_user_json(self) -> APIUserPayload:
'banner': self._banner,
'accent_color': self._accent_colour,
'primary_guild': self._primary_guild,
'display_name_style': self._display_name_style,
}
return user

Expand Down Expand Up @@ -383,6 +399,12 @@ 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]:
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
Loading