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 all 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions discord/abc.py
Expand Up @@ -215,6 +215,14 @@ class User(Snowflake, Protocol):
The user's username.
discriminator: :class:`str`
The user's discriminator.

.. note::

If the user has migrated to the new username system, this will always be "0".
global_name: :class:`str`
The user's global name.

.. versionadded:: 2.5
avatar: :class:`~discord.Asset`
The avatar asset the user has.
bot: :class:`bool`
Expand All @@ -225,6 +233,7 @@ class User(Snowflake, Protocol):

name: str
discriminator: str
global_name: str | None
avatar: Asset
bot: bool

Expand Down
15 changes: 0 additions & 15 deletions discord/enums.py
Expand Up @@ -37,7 +37,6 @@
"VerificationLevel",
"ContentFilter",
"Status",
"DefaultAvatar",
"AuditLogAction",
"AuditLogActionCategory",
"UserFlags",
Expand Down Expand Up @@ -354,20 +353,6 @@ def __str__(self):
return self.value


class DefaultAvatar(Enum):
"""Default avatar"""

blurple = 0
grey = 1
gray = 1
green = 2
orange = 3
red = 4

def __str__(self):
return self.name


class NotificationLevel(Enum, comparable=True):
"""Notification level"""

Expand Down
12 changes: 6 additions & 6 deletions discord/ext/commands/converter.py
Expand Up @@ -199,11 +199,11 @@ async def query_member_named(self, guild, argument):
return discord.utils.get(
members, name=username, discriminator=discriminator
)
else:
members = await guild.query_members(argument, limit=100, cache=cache)
return discord.utils.find(
lambda m: m.name == argument or m.nick == argument, members
)
members = await guild.query_members(argument, limit=100, cache=cache)
return discord.utils.find(
lambda m: argument in (m.nick, m.name, m.global_name),
members,
)

async def query_member_by_id(self, bot, guild, user_id):
ws = bot._get_websocket(shard_id=guild.shard_id)
Expand Down Expand Up @@ -320,7 +320,7 @@ async def convert(self, ctx: Context, argument: str) -> discord.User:
if result is not None:
return result

predicate = lambda u: u.name == arg
predicate = lambda u: arg in (u.name, u.global_name)
result = discord.utils.find(predicate, state._users.values())

if result is None:
Expand Down
5 changes: 1 addition & 4 deletions discord/guild.py
Expand Up @@ -1068,10 +1068,7 @@
if result is not None:
return result

def pred(m: Member) -> bool:
return m.nick == name or m.name == name

return utils.find(pred, members)
return utils.find(lambda m: name in (m.nick, m.name, m.global_name), members)

Check warning on line 1071 in discord/guild.py

View check run for this annotation

Codecov / codecov/patch

discord/guild.py#L1071

Added line #L1071 was not covered by tests

def _create_channel(
self,
Expand Down
38 changes: 30 additions & 8 deletions discord/member.py
Expand Up @@ -230,7 +230,7 @@

.. describe:: str(x)

Returns the member's name with the discriminator.
Returns the member's name with the discriminator or global_name.

Attributes
----------
Expand Down Expand Up @@ -322,6 +322,19 @@
return str(self._user)

def __repr__(self) -> str:
if self._user.is_migrated:
if self.global_name is not None:
return (

Check warning on line 327 in discord/member.py

View check run for this annotation

Codecov / codecov/patch

discord/member.py#L325-L327

Added lines #L325 - L327 were not covered by tests
"<Member"
f" id={self._user.id} name={self._user.name!r} global_name={self.global_name!r}"
f" bot={self._user.bot} nick={self.nick!r} guild={self.guild!r}>"
)
else:
return (

Check warning on line 333 in discord/member.py

View check run for this annotation

Codecov / codecov/patch

discord/member.py#L333

Added line #L333 was not covered by tests
"<Member"
f" id={self._user.id} name={self._user.name!r}"
f" bot={self._user.bot} nick={self.nick!r} guild={self.guild!r}>"
)
return (
"<Member"
f" id={self._user.id} name={self._user.name!r} discriminator={self._user.discriminator!r}"
Expand Down Expand Up @@ -427,17 +440,24 @@

def _update_inner_user(self, user: UserPayload) -> tuple[User, User] | None:
u = self._user
original = (u.name, u._avatar, u.discriminator, u._public_flags)
original = (u.name, u._avatar, u.discriminator, u.global_name, u._public_flags)

Check warning on line 443 in discord/member.py

View check run for this annotation

Codecov / codecov/patch

discord/member.py#L443

Added line #L443 was not covered by tests
# These keys seem to always be available
modified = (
user["username"],
user["avatar"],
user["discriminator"],
user.get("global_name", None) or None,
user.get("public_flags", 0),
)
if original != modified:
to_return = User._copy(self._user)
u.name, u._avatar, u.discriminator, u._public_flags = modified
(

Check warning on line 454 in discord/member.py

View check run for this annotation

Codecov / codecov/patch

discord/member.py#L454

Added line #L454 was not covered by tests
u.name,
u._avatar,
u.discriminator,
u.global_name,
u._public_flags,
) = modified
# Signal to dispatch on_user_update
return to_return, u

Expand Down Expand Up @@ -476,6 +496,11 @@
"""The member's status on the web client, if applicable."""
return try_enum(Status, self._client_status.get("web", "offline"))

@property
def global_name(self) -> str | None:
"""The member's global name, if applicable."""
return self._user.global_name

Check warning on line 502 in discord/member.py

View check run for this annotation

Codecov / codecov/patch

discord/member.py#L502

Added line #L502 was not covered by tests

def is_on_mobile(self) -> bool:
"""A helper function that determines if a member is active on a mobile device."""
return "mobile" in self._client_status
Expand Down Expand Up @@ -535,12 +560,9 @@
@property
def display_name(self) -> str:
"""Returns the user's display name.

For regular users this is just their username, but
if they have a guild specific nickname then that
is returned instead.
This will either be their guild specific nickname, global name or username.
"""
return self.nick or self.name
return self.nick or self.global_name or self.name

Check warning on line 565 in discord/member.py

View check run for this annotation

Codecov / codecov/patch

discord/member.py#L565

Added line #L565 was not covered by tests

@property
def display_avatar(self) -> Asset:
Expand Down
20 changes: 19 additions & 1 deletion discord/team.py
Expand Up @@ -108,7 +108,7 @@

.. describe:: str(x)

Returns the team member's name with discriminator.
Returns the team member's name with discriminator or global_name.

.. versionadded:: 1.3

Expand All @@ -120,6 +120,14 @@
The team member's unique ID.
discriminator: :class:`str`
The team member's discriminator. This is given when the username has conflicts.

.. note::

If the user has migrated to the new username system, this will always be "0".
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,6 +149,16 @@
super().__init__(state=state, data=data["user"])

def __repr__(self) -> str:
if self.is_migrated:
if self.global_name is not None:
return (

Check warning on line 154 in discord/team.py

View check run for this annotation

Codecov / codecov/patch

discord/team.py#L152-L154

Added lines #L152 - L154 were not covered by tests
f"<{self.__class__.__name__} id={self.id} username={self.name!r} "
f"global_name={self.global_name!r} membership_state={self.membership_state!r}>"
)
return (

Check warning on line 158 in discord/team.py

View check run for this annotation

Codecov / codecov/patch

discord/team.py#L158

Added line #L158 was not covered by tests
f"<{self.__class__.__name__} id={self.id} username={self.name!r} "
f"membership_state={self.membership_state!r}>"
)
return (
f"<{self.__class__.__name__} id={self.id} name={self.name!r} "
f"discriminator={self.discriminator!r} membership_state={self.membership_state!r}>"
Expand Down
3 changes: 2 additions & 1 deletion discord/types/user.py
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