From 31e3e99c2b131a72d8822aa80ef5802d3869b335 Mon Sep 17 00:00:00 2001 From: Arthur Jovart Date: Sun, 29 Aug 2021 00:59:29 +0200 Subject: [PATCH 1/6] Add __int__ special method to User and Member --- discord/member.py | 7 +++++++ discord/user.py | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/discord/member.py b/discord/member.py index a8c868d8..49b7e3ab 100644 --- a/discord/member.py +++ b/discord/member.py @@ -226,6 +226,10 @@ class Member(discord.abc.Messageable, _UserTag): Returns the member's name with the discriminator. + .. describe:: int(x) + + Returns the user's ID. + Attributes ---------- joined_at: Optional[:class:`datetime.datetime`] @@ -300,6 +304,9 @@ class Member(discord.abc.Messageable, _UserTag): def __str__(self) -> str: return str(self._user) + def __int__(self) -> int: + return self.id + def __repr__(self) -> str: return ( f' str: return f'{self.name}#{self.discriminator}' + def __int__(self) -> int: + return self.id + def __eq__(self, other: Any) -> bool: return isinstance(other, _UserTag) and other.id == self.id @@ -415,6 +418,10 @@ class User(BaseUser, discord.abc.Messageable): Returns the user's name with discriminator. + .. describe:: int(x) + + Returns the user's ID. + Attributes ----------- name: :class:`str` -- 2.47.2 From 3ce86f6cde2126ee180703ec0499f685ab8a9114 Mon Sep 17 00:00:00 2001 From: Arthur Jovart Date: Sun, 29 Aug 2021 01:05:28 +0200 Subject: [PATCH 2/6] Add int() support to Emoji --- discord/emoji.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/discord/emoji.py b/discord/emoji.py index 8b51d0fd..39fa0218 100644 --- a/discord/emoji.py +++ b/discord/emoji.py @@ -72,6 +72,10 @@ class Emoji(_EmojiTag, AssetMixin): Returns the emoji rendered for discord. + .. describe:: int(x) + + Returns the emoji ID. + Attributes ----------- name: :class:`str` @@ -137,6 +141,9 @@ class Emoji(_EmojiTag, AssetMixin): return f'' return f'<:{self.name}:{self.id}>' + def __int__(self) -> int: + return self.id + def __repr__(self) -> str: return f'' -- 2.47.2 From 9d1df65af37204f635d26d559e1d12b37d51716f Mon Sep 17 00:00:00 2001 From: Arthur Jovart Date: Sun, 29 Aug 2021 01:06:18 +0200 Subject: [PATCH 3/6] Add int() support to Role --- discord/role.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/discord/role.py b/discord/role.py index 0427ddc3..ee9ec1be 100644 --- a/discord/role.py +++ b/discord/role.py @@ -141,6 +141,10 @@ class Role(Hashable): Returns the role's name. + .. describe:: str(x) + + Returns the role's ID. + Attributes ---------- id: :class:`int` @@ -195,6 +199,9 @@ class Role(Hashable): def __str__(self) -> str: return self.name + def __int__(self) -> int: + return self.id + def __repr__(self) -> str: return f'' -- 2.47.2 From fa7f8efc8ed8aa83b04d357c0ad79412e4a42259 Mon Sep 17 00:00:00 2001 From: Arthur Jovart Date: Sun, 29 Aug 2021 01:07:26 +0200 Subject: [PATCH 4/6] Add int() support to Guild --- discord/guild.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/discord/guild.py b/discord/guild.py index 9ab81276..ba911c06 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -140,6 +140,10 @@ class Guild(Hashable): Returns the guild's name. + .. describe:: int(x) + + Returns the guild's ID. + Attributes ---------- name: :class:`str` @@ -335,6 +339,9 @@ class Guild(Hashable): def __str__(self) -> str: return self.name or '' + def __int__(self) -> int: + return self.id + def __repr__(self) -> str: attrs = ( ('id', self.id), -- 2.47.2 From 22de755059ae9a039c71091b92aed1645202224d Mon Sep 17 00:00:00 2001 From: Arthur Jovart Date: Sun, 29 Aug 2021 01:09:05 +0200 Subject: [PATCH 5/6] Add int() and str() support to Message --- discord/message.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/discord/message.py b/discord/message.py index 304c807d..8c78a3d2 100644 --- a/discord/message.py +++ b/discord/message.py @@ -503,6 +503,14 @@ class Message(Hashable): Returns the message's hash. + .. describe:: str(x) + + Returns the message's content. + + .. describe:: int(x) + + Returns the message's ID. + Attributes ----------- tts: :class:`bool` @@ -712,6 +720,12 @@ class Message(Hashable): f'<{name} id={self.id} channel={self.channel!r} type={self.type!r} author={self.author!r} flags={self.flags!r}>' ) + def __int__(self) -> int: + return self.id + + def __str__(self) -> Optional[str]: + return self.content + def _try_patch(self, data, key, transform=None) -> None: try: value = data[key] -- 2.47.2 From 64ee79239106fcb507aab31f10db4aabb1b40f38 Mon Sep 17 00:00:00 2001 From: Arthur Jovart Date: Sun, 29 Aug 2021 01:21:20 +0200 Subject: [PATCH 6/6] Add int() support to Hashable, making it available across the board for AuditLogEntry, *Channel, Guild, Object, Message, ... --- discord/audit_logs.py | 4 ++++ discord/channel.py | 24 ++++++++++++++++++++++++ discord/guild.py | 3 --- discord/invite.py | 4 ++++ discord/message.py | 10 ++++++++-- discord/mixins.py | 3 +++ discord/object.py | 4 ++++ discord/role.py | 4 ++++ discord/stage_instance.py | 4 ++++ discord/sticker.py | 8 ++++++++ discord/threads.py | 8 ++++++++ discord/webhook/async_.py | 4 ++++ discord/webhook/sync.py | 4 ++++ 13 files changed, 79 insertions(+), 5 deletions(-) diff --git a/discord/audit_logs.py b/discord/audit_logs.py index 1870620f..b74bbfef 100644 --- a/discord/audit_logs.py +++ b/discord/audit_logs.py @@ -330,6 +330,10 @@ class AuditLogEntry(Hashable): Returns the entry's hash. + .. describe:: int(x) + + Returns the entry's ID. + .. versionchanged:: 1.7 Audit log entries are now comparable and hashable. diff --git a/discord/channel.py b/discord/channel.py index be3315cf..dc3967c4 100644 --- a/discord/channel.py +++ b/discord/channel.py @@ -115,6 +115,10 @@ class TextChannel(discord.abc.Messageable, discord.abc.GuildChannel, Hashable): Returns the channel's name. + .. describe:: int(x) + + Returns the channel's ID. + Attributes ----------- name: :class:`str` @@ -1334,6 +1338,10 @@ class CategoryChannel(discord.abc.GuildChannel, Hashable): Returns the category's name. + .. describe:: int(x) + + Returns the category's ID. + Attributes ----------- name: :class:`str` @@ -1556,6 +1564,10 @@ class StoreChannel(discord.abc.GuildChannel, Hashable): Returns the channel's name. + .. describe:: int(x) + + Returns the channel's ID. + Attributes ----------- name: :class:`str` @@ -1728,6 +1740,10 @@ class DMChannel(discord.abc.Messageable, Hashable): Returns a string representation of the channel + .. describe:: int(x) + + Returns the channel's ID. + Attributes ---------- recipient: Optional[:class:`User`] @@ -1854,6 +1870,10 @@ class GroupChannel(discord.abc.Messageable, Hashable): Returns a string representation of the channel + .. describe:: int(x) + + Returns the channel's ID. + Attributes ---------- recipients: List[:class:`User`] @@ -2000,6 +2020,10 @@ class PartialMessageable(discord.abc.Messageable, Hashable): Returns the partial messageable's hash. + .. describe:: int(x) + + Returns the messageable's ID. + Attributes ----------- id: :class:`int` diff --git a/discord/guild.py b/discord/guild.py index ba911c06..efb7a118 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -339,9 +339,6 @@ class Guild(Hashable): def __str__(self) -> str: return self.name or '' - def __int__(self) -> int: - return self.id - def __repr__(self) -> str: attrs = ( ('id', self.id), diff --git a/discord/invite.py b/discord/invite.py index d02fa680..050d2b83 100644 --- a/discord/invite.py +++ b/discord/invite.py @@ -230,6 +230,7 @@ class Invite(Hashable): Returns the invite URL. + The following table illustrates what methods will obtain the attributes: +------------------------------------+------------------------------------------------------------+ @@ -433,6 +434,9 @@ class Invite(Hashable): def __str__(self) -> str: return self.url + def __int__(self) -> int: + return 0 # To keep the object compatible with the hashable abc. + def __repr__(self) -> str: return ( f'' ) - def __int__(self) -> int: - return self.id def __str__(self) -> Optional[str]: return self.content @@ -1639,6 +1641,10 @@ class PartialMessage(Hashable): Returns the partial message's hash. + .. describe:: int(x) + + Returns the partial message's ID. + Attributes ----------- channel: Union[:class:`TextChannel`, :class:`Thread`, :class:`DMChannel`] diff --git a/discord/mixins.py b/discord/mixins.py index 32ee222b..fdacf863 100644 --- a/discord/mixins.py +++ b/discord/mixins.py @@ -43,5 +43,8 @@ class EqualityComparable: class Hashable(EqualityComparable): __slots__ = () + def __int__(self) -> int: + return self.id + def __hash__(self) -> int: return self.id >> 22 diff --git a/discord/object.py b/discord/object.py index 3795425f..8061a8be 100644 --- a/discord/object.py +++ b/discord/object.py @@ -69,6 +69,10 @@ class Object(Hashable): Returns the object's hash. + .. describe:: int(x) + + Returns the object's ID. + Attributes ----------- id: :class:`int` diff --git a/discord/role.py b/discord/role.py index ee9ec1be..b690cbe4 100644 --- a/discord/role.py +++ b/discord/role.py @@ -145,6 +145,10 @@ class Role(Hashable): Returns the role's ID. + .. describe:: int(x) + + Returns the role's ID. + Attributes ---------- id: :class:`int` diff --git a/discord/stage_instance.py b/discord/stage_instance.py index 479e89f2..b538eec3 100644 --- a/discord/stage_instance.py +++ b/discord/stage_instance.py @@ -61,6 +61,10 @@ class StageInstance(Hashable): Returns the stage instance's hash. + .. describe:: int(x) + + Returns the stage instance's ID. + Attributes ----------- id: :class:`int` diff --git a/discord/sticker.py b/discord/sticker.py index b0b5c678..8ec2ad01 100644 --- a/discord/sticker.py +++ b/discord/sticker.py @@ -67,6 +67,14 @@ class StickerPack(Hashable): Returns the name of the sticker pack. + .. describe:: hash(x) + + Returns the hash of the sticker pack. + + .. describe:: int(x) + + Returns the ID of the sticker pack. + .. describe:: x == y Checks if the sticker pack is equal to another sticker pack. diff --git a/discord/threads.py b/discord/threads.py index 892910d9..6f8ffb00 100644 --- a/discord/threads.py +++ b/discord/threads.py @@ -74,6 +74,10 @@ class Thread(Messageable, Hashable): Returns the thread's hash. + .. describe:: int(x) + + Returns the thread's ID. + .. describe:: str(x) Returns the thread's name. @@ -748,6 +752,10 @@ class ThreadMember(Hashable): Returns the thread member's hash. + .. describe:: int(x) + + Returns the thread member's ID. + .. describe:: str(x) Returns the thread member's name. diff --git a/discord/webhook/async_.py b/discord/webhook/async_.py index d1ed1ade..1aec6544 100644 --- a/discord/webhook/async_.py +++ b/discord/webhook/async_.py @@ -886,6 +886,10 @@ class Webhook(BaseWebhook): Returns the webhooks's hash. + .. describe:: int(x) + + Returns the webhooks's ID. + .. versionchanged:: 1.4 Webhooks are now comparable and hashable. diff --git a/discord/webhook/sync.py b/discord/webhook/sync.py index 5c85a036..62fb2d5f 100644 --- a/discord/webhook/sync.py +++ b/discord/webhook/sync.py @@ -475,6 +475,10 @@ class SyncWebhook(BaseWebhook): Returns the webhooks's hash. + .. describe:: int(x) + + Returns the webhooks's ID. + .. versionchanged:: 1.4 Webhooks are now comparable and hashable. -- 2.47.2