Add display_name and discriminator

This commit is contained in:
Zomatree
2023-06-13 03:10:45 +01:00
parent 4efaac40f6
commit 828b428f48
3 changed files with 17 additions and 4 deletions
+5
View File
@@ -82,6 +82,11 @@ class Member(User):
"""Optional[:class:`Asset`] The avatar the member is displaying, this includes guild avatars and masqueraded avatar"""
return self.masquerade_avatar or self.guild_avatar or self.original_avatar
@property
def name(self) -> str:
""":class:`str` The name the user is displaying, this includes (in order) their masqueraded name, display name and orginal name"""
return self.nickname or self.display_name or self.masquerade_name or self.original_name
@property
def mention(self) -> str:
""":class:`str`: Returns a string that allows you to mention the given member."""
+2
View File
@@ -32,6 +32,8 @@ class UserRelation(TypedDict):
class User(TypedDict):
_id: str
username: str
discriminator: str
display_name: NotRequired[str]
avatar: NotRequired[File]
relations: NotRequired[list[UserRelation]]
badges: NotRequired[int]
+10 -4
View File
@@ -43,7 +43,11 @@ class User(Messageable, Ulid):
Attributes
-----------
id: :class:`str`
The users id
The user's id
discriminator: :class:`str`
The user's discriminator
display_name: Optional[:class:`str`]
The user's display name if they have one
bot: :class:`bool`
Whether or not the user is a bot
owner_id: Optional[:class:`str`]
@@ -65,13 +69,15 @@ class User(Messageable, Ulid):
privileged: :class:`bool`
Whether the user is privileged
"""
__flattern_attributes__: tuple[str, ...] = ("id", "bot", "owner_id", "badges", "online", "flags", "relations", "relationship", "status", "masquerade_avatar", "masquerade_name", "original_name", "original_avatar", "profile", "dm_channel", "privileged")
__flattern_attributes__: tuple[str, ...] = ("id", "discriminator", "display_name", "bot", "owner_id", "badges", "online", "flags", "relations", "relationship", "status", "masquerade_avatar", "masquerade_name", "original_name", "original_avatar", "profile", "dm_channel", "privileged")
__slots__: tuple[str, ...] = (*__flattern_attributes__, "state", "_members")
def __init__(self, data: UserPayload, state: State):
self.state = state
self._members: WeakValueDictionary[str, Member] = WeakValueDictionary() # we store all member versions of this user to avoid having to check every guild when needing to update.
self.id: str = data["_id"]
self.discriminator = data["discriminator"]
self.display_name = data.get("display_name")
self.original_name: str = data["username"]
self.dm_channel: DMChannel | None = None
@@ -184,8 +190,8 @@ class User(Messageable, Ulid):
@property
def name(self) -> str:
""":class:`str` The name the user is displaying, this includes there orginal name and masqueraded name"""
return self.masquerade_name or self.original_name
""":class:`str` The name the user is displaying, this includes (in order) their masqueraded name, display name and orginal name"""
return self.display_name or self.masquerade_name or self.original_name
@property
def avatar(self) -> Union[Asset, PartialAsset, None]: