Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: pomelo #2042

Merged
merged 23 commits into from
May 18, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
199c1b6
Preparation for username#discrim changes
Lulalaby May 3, 2023
2367fe8
feat: global_name
Lulalaby May 10, 2023
36cd9c0
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 10, 2023
6172d1c
Merge branch 'master' into pomelo
Lulalaby May 10, 2023
510489e
i hate this shit :^)
Lulalaby May 10, 2023
78eb6be
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 10, 2023
85188d3
send help
Lulalaby May 10, 2023
e5ed358
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 10, 2023
29fdf48
:^)
Lulalaby May 10, 2023
043d781
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 10, 2023
022e06b
not sure if i found all places
Lulalaby May 10, 2023
a13c609
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 10, 2023
cf02897
retrigger ci
Lulalaby May 10, 2023
0ee8007
Merge branch 'master' into pomelo
Lulalaby May 10, 2023
175ce0b
Merge branch 'master' into pomelo
Lulalaby May 12, 2023
878c5f0
chore: documentation and spacing consistency
Dorukyum May 14, 2023
691c05b
refactor: fix and optimize multiple chunks
Dorukyum May 14, 2023
36a96ad
refactor: fix and optimize more chunks
Dorukyum May 14, 2023
11022f6
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 14, 2023
f602411
refactor: clean comparisons
Dorukyum May 14, 2023
3072085
fix: add missing global_name comparison
Dorukyum May 14, 2023
6ff41b9
fix: miscellaneous pomelo updates (#2076)
NeloBlivion May 17, 2023
c508f35
Merge branch 'master' into pomelo
Lulalaby May 17, 2023
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
7 changes: 6 additions & 1 deletion discord/member.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ class Member(discord.abc.Messageable, _UserTag):
name: str
id: int
discriminator: str
global_name: str | None
bot: bool
system: bool
created_at: datetime.datetime
Expand Down Expand Up @@ -540,7 +541,11 @@ def display_name(self) -> str:
if they have a guild specific nickname then that
is returned instead.
"""
return self.nick or self.name
return (
self.nick or self.global_name
if self._user.is_migrated
else self.name or self.name
)

@property
def display_avatar(self) -> Asset:
Expand Down
24 changes: 20 additions & 4 deletions discord/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ class TeamMember(BaseUser):
The team member's unique ID.
discriminator: :class:`str`
The team member's discriminator. This is given when the username has conflicts.
global_name: :class: `str`
The team member's global name.

.. versionadded:: 2.5

avatar: Optional[:class:`str`]
The avatar hash the team member has. Could be ``None``.
bot: :class:`bool`
Expand All @@ -141,7 +146,18 @@ def __init__(self, team: Team, state: ConnectionState, data: TeamMemberPayload):
super().__init__(state=state, data=data["user"])

def __repr__(self) -> str:
return (
f"<{self.__class__.__name__} id={self.id} name={self.name!r} "
f"discriminator={self.discriminator!r} membership_state={self.membership_state!r}>"
)
if self.is_migrated and self.global_name is not None:
return (
f"<{self.__class__.__name__} id={self.id} username={self.name!r} "
f"global_name={self.global_name!r} membership_state={self.membership_state!r}>"
)
elif self.is_migrated:
return (
f"<{self.__class__.__name__} id={self.id} username={self.name!r} "
f"membership_state={self.membership_state!r}>"
)
else:
return (
f"<{self.__class__.__name__} id={self.id} name={self.name!r} "
f"discriminator={self.discriminator!r} membership_state={self.membership_state!r}>"
)
3 changes: 2 additions & 1 deletion discord/types/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ class PartialUser(TypedDict):
id: Snowflake
username: str
discriminator: str
global_name: str | None
avatar: str | None


PremiumType = Literal[0, 1, 2]
PremiumType = Literal[0, 1, 2, 3]


class User(PartialUser, total=False):
Expand Down
85 changes: 71 additions & 14 deletions discord/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class BaseUser(_UserTag):
"name",
"id",
"discriminator",
"global_name",
"_avatar",
"_banner",
"_accent_colour",
Expand All @@ -77,6 +78,7 @@ class BaseUser(_UserTag):
name: str
id: int
discriminator: str
global_name: str | None
bot: bool
system: bool
_state: ConnectionState
Expand All @@ -90,11 +92,24 @@ def __init__(self, *, state: ConnectionState, data: UserPayload) -> None:
self._update(data)

def __repr__(self) -> str:
return (
"<BaseUser"
f" id={self.id} name={self.name!r} discriminator={self.discriminator!r}"
f" bot={self.bot} system={self.system}>"
)
if self.is_migrated and self.global_name is not None:
return (
"<BaseUser"
f" id={self.id} username={self.name!r} global_name={self.global_name!r}"
f" bot={self.bot} system={self.system}>"
)
elif self.is_migrated:
return (
"<BaseUser"
f" id={self.id} username={self.name!r}"
f" bot={self.bot} system={self.system}>"
)
else:
return (
"<BaseUser"
f" id={self.id} name={self.name!r} discriminator={self.discriminator!r}"
f" bot={self.bot} system={self.system}>"
)

def __str__(self) -> str:
return f"{self.name}#{self.discriminator}"
Expand All @@ -112,6 +127,7 @@ def _update(self, data: UserPayload) -> None:
self.name = data["username"]
self.id = int(data["id"])
self.discriminator = data["discriminator"]
self.global_name = data.get("global_name", None)
self._avatar = data["avatar"]
self._banner = data.get("banner", None)
self._accent_colour = data.get("accent_color", None)
Expand All @@ -126,6 +142,7 @@ def _copy(cls: type[BU], user: BU) -> BU:
self.name = user.name
self.id = user.id
self.discriminator = user.discriminator
self.global_name = user.global_name
self._avatar = user._avatar
self._banner = user._banner
self._accent_colour = user._accent_colour
Expand All @@ -141,6 +158,7 @@ def _to_minimal_user_json(self) -> dict[str, Any]:
"id": self.id,
"avatar": self._avatar,
"discriminator": self.discriminator,
"global_name": self.global_name,
"bot": self.bot,
}

Expand Down Expand Up @@ -290,6 +308,12 @@ def mentioned_in(self, message: Message) -> bool:

return any(user.id == self.id for user in message.mentions)

@property
def is_migrated(self) -> bool:
"""Checks whether the user is already migrated to global name"""

return self.discriminator == "0"


class ClientUser(BaseUser):
"""Represents your Discord user.
Expand Down Expand Up @@ -320,6 +344,11 @@ class ClientUser(BaseUser):
The user's unique ID.
discriminator: :class:`str`
The user's discriminator. This is given when the username has conflicts.
global_name: :class: `str`
The user's global name.

.. versionadded:: 2.5

bot: :class:`bool`
Specifies if the user is a bot account.
system: :class:`bool`
Expand Down Expand Up @@ -347,11 +376,24 @@ def __init__(self, *, state: ConnectionState, data: UserPayload) -> None:
super().__init__(state=state, data=data)

def __repr__(self) -> str:
return (
"<ClientUser"
f" id={self.id} name={self.name!r} discriminator={self.discriminator!r}"
f" bot={self.bot} verified={self.verified} mfa_enabled={self.mfa_enabled}>"
)
if self.is_migrated and self.global_name is not None:
return (
"<ClientUser"
f" id={self.id} username={self.name!r} global_name={self.global_name!r}"
f" bot={self.bot} verified={self.verified} mfa_enabled={self.mfa_enabled}>"
)
elif self.is_migrated:
return (
"<ClientUser"
f" id={self.id} username={self.name!r}"
f" bot={self.bot} verified={self.verified} mfa_enabled={self.mfa_enabled}>"
)
else:
return (
"<ClientUser"
f" id={self.id} name={self.name!r} discriminator={self.discriminator!r}"
f" bot={self.bot} verified={self.verified} mfa_enabled={self.mfa_enabled}>"
)

def _update(self, data: UserPayload) -> None:
super()._update(data)
Expand All @@ -361,6 +403,7 @@ def _update(self, data: UserPayload) -> None:
self._flags = data.get("flags", 0)
self.mfa_enabled = data.get("mfa_enabled", False)

# TODO: Username might not be able to edit anymore.
async def edit(
self, *, username: str = MISSING, avatar: bytes = MISSING
) -> ClientUser:
Expand Down Expand Up @@ -442,6 +485,12 @@ class User(BaseUser, discord.abc.Messageable):
The user's unique ID.
discriminator: :class:`str`
The user's discriminator. This is given when the username has conflicts.

global_name: :class: `str`
The user's global name.

.. versionadded:: 2.5

bot: :class:`bool`
Specifies if the user is a bot account.
system: :class:`bool`
Expand All @@ -455,10 +504,18 @@ def __init__(self, *, state: ConnectionState, data: UserPayload) -> None:
self._stored: bool = False

def __repr__(self) -> str:
return (
"<User"
f" id={self.id} name={self.name!r} discriminator={self.discriminator!r} bot={self.bot}>"
)
if self.is_migrated and self.global_name is not None:
return (
"<User"
f" id={self.id} username={self.name!r} global_name={self.global_name!r} bot={self.bot}>"
)
elif self.is_migrated:
return "<User" f" id={self.id} username={self.name!r} bot={self.bot}>"
else:
return (
"<User"
f" id={self.id} name={self.name!r} discriminator={self.discriminator!r} bot={self.bot}>"
)

def __del__(self) -> None:
try:
Expand Down