From 4367a9afd3938b7a3b8b0448e483d1b775d0e6ee Mon Sep 17 00:00:00 2001 From: Jakub Kuczys Date: Sat, 1 Oct 2022 09:14:03 +0200 Subject: [PATCH] Set thread related perms in private channels to False --- discord/channel.py | 28 ++++++++++++++++++---------- discord/guild.py | 2 +- discord/permissions.py | 12 ++++++++++++ 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/discord/channel.py b/discord/channel.py index 35e843dca..a39a62789 100644 --- a/discord/channel.py +++ b/discord/channel.py @@ -2820,11 +2820,19 @@ class DMChannel(discord.abc.Messageable, discord.abc.Connectable, discord.abc.Pr - :attr:`~Permissions.send_tts_messages`: You cannot send TTS messages in a DM. - :attr:`~Permissions.manage_messages`: You cannot delete others messages in a DM. + - :attr:`~Permissions.create_private_threads`: There are no threads in a DM. + - :attr:`~Permissions.create_public_threads`: There are no threads in a DM. + - :attr:`~Permissions.manage_threads`: There are no threads in a DM. + - :attr:`~Permissions.send_messages_in_threads`: There are no threads in a DM. .. versionchanged:: 2.0 ``obj`` parameter is now positional-only. + .. versionchanged:: 2.0 + + Thread related permissions are now set to ``False``. + Parameters ----------- obj: :class:`~discord.abc.Snowflake` @@ -2836,12 +2844,7 @@ class DMChannel(discord.abc.Messageable, discord.abc.Connectable, discord.abc.Pr :class:`Permissions` The resolved permissions. """ - - base = Permissions.text() - base.read_messages = True - base.send_tts_messages = False - base.manage_messages = False - return base + return Permissions._dm_permissions() def get_partial_message(self, message_id: int, /) -> PartialMessage: """Creates a :class:`PartialMessage` from the message ID. @@ -3181,6 +3184,10 @@ class GroupChannel(discord.abc.Messageable, discord.abc.Connectable, discord.abc - :attr:`~Permissions.send_tts_messages`: You cannot send TTS messages in a DM. - :attr:`~Permissions.manage_messages`: You cannot delete others messages in a DM. + - :attr:`~Permissions.create_private_threads`: There are no threads in a DM. + - :attr:`~Permissions.create_public_threads`: There are no threads in a DM. + - :attr:`~Permissions.manage_threads`: There are no threads in a DM. + - :attr:`~Permissions.send_messages_in_threads`: There are no threads in a DM. This also checks the kick_members permission if the user is the owner. @@ -3188,6 +3195,10 @@ class GroupChannel(discord.abc.Messageable, discord.abc.Connectable, discord.abc ``obj`` parameter is now positional-only. + .. versionchanged:: 2.0 + + Thread related permissions are now set to ``False``. + Parameters ----------- obj: :class:`~discord.abc.Snowflake` @@ -3199,10 +3210,7 @@ class GroupChannel(discord.abc.Messageable, discord.abc.Connectable, discord.abc The resolved permissions for the user. """ if obj.id in [x.id for x in self.recipients]: - base = Permissions.text() - base.read_messages = True - base.send_tts_messages = False - base.manage_messages = False + base = Permissions._dm_permissions() base.mention_everyone = True if not self.managed: base.create_instant_invite = True diff --git a/discord/guild.py b/discord/guild.py index 04dbd665f..ab8e2c087 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -1790,7 +1790,7 @@ class Guild(Hashable): .. versionchanged:: 2.0 The ``premium_progress_bar_enabled`` keyword parameter was added. - .. versionchanged:: 2.1 + .. versionchanged:: 2.0 The ``discoverable`` and ``invites_disabled`` keyword parameters were added. Parameters diff --git a/discord/permissions.py b/discord/permissions.py index f5f8ae2f0..2f5c17640 100644 --- a/discord/permissions.py +++ b/discord/permissions.py @@ -186,6 +186,18 @@ class Permissions(BaseFlags): p.read_message_history = False return ~p.value + @classmethod + def _dm_permissions(cls) -> Self: + base = cls.text() + base.read_messages = True + base.send_tts_messages = False + base.manage_messages = False + base.create_private_threads = False + base.create_public_threads = False + base.manage_threads = False + base.send_messages_in_threads = False + return base + @classmethod def all_channel(cls) -> Self: """A :class:`Permissions` with all channel-specific permissions set to