From fb73dbbc4731eb19d653e71fe48f300556f6cd96 Mon Sep 17 00:00:00 2001 From: shiftinv <8530778+shiftinv@users.noreply.github.com> Date: Wed, 22 Nov 2023 14:30:58 +0100 Subject: [PATCH] feat(permissions): add `create_guild_expressions` and `create_events` permissions (#1091) --- changelog/1091.feature.rst | 1 + disnake/abc.py | 2 ++ disnake/channel.py | 1 + disnake/emoji.py | 4 +-- disnake/ext/commands/base_core.py | 2 ++ disnake/ext/commands/core.py | 8 +++++ disnake/guild.py | 6 ++-- disnake/guild_scheduled_event.py | 10 +++--- disnake/permissions.py | 56 +++++++++++++++++++++++++++++-- disnake/sticker.py | 4 +-- 10 files changed, 79 insertions(+), 15 deletions(-) create mode 100644 changelog/1091.feature.rst diff --git a/changelog/1091.feature.rst b/changelog/1091.feature.rst new file mode 100644 index 0000000000..6ae43e7e5f --- /dev/null +++ b/changelog/1091.feature.rst @@ -0,0 +1 @@ +Add :attr:`Permissions.create_guild_expressions` and :attr:`Permissions.create_events`. diff --git a/disnake/abc.py b/disnake/abc.py index b9a60f3ee5..a6f84163ac 100644 --- a/disnake/abc.py +++ b/disnake/abc.py @@ -853,7 +853,9 @@ async def set_permissions( ban_members: Optional[bool] = ..., change_nickname: Optional[bool] = ..., connect: Optional[bool] = ..., + create_events: Optional[bool] = ..., create_forum_threads: Optional[bool] = ..., + create_guild_expressions: Optional[bool] = ..., create_instant_invite: Optional[bool] = ..., create_private_threads: Optional[bool] = ..., create_public_threads: Optional[bool] = ..., diff --git a/disnake/channel.py b/disnake/channel.py index ffb11f2d2c..00598927ca 100644 --- a/disnake/channel.py +++ b/disnake/channel.py @@ -1207,6 +1207,7 @@ def permissions_for( denied.update( manage_channels=True, manage_roles=True, + create_events=True, manage_events=True, manage_webhooks=True, ) diff --git a/disnake/emoji.py b/disnake/emoji.py index 2a24877b07..badedbce86 100644 --- a/disnake/emoji.py +++ b/disnake/emoji.py @@ -192,7 +192,7 @@ async def delete(self, *, reason: Optional[str] = None) -> None: Raises ------ Forbidden - You are not allowed to delete emojis. + You are not allowed to delete this emoji. HTTPException An error occurred deleting the emoji. """ @@ -227,7 +227,7 @@ async def edit( Raises ------ Forbidden - You are not allowed to edit emojis. + You are not allowed to edit this emoji. HTTPException An error occurred editing the emoji. diff --git a/disnake/ext/commands/base_core.py b/disnake/ext/commands/base_core.py index 3599ea0908..b5e0498399 100644 --- a/disnake/ext/commands/base_core.py +++ b/disnake/ext/commands/base_core.py @@ -636,7 +636,9 @@ def default_member_permissions( ban_members: bool = ..., change_nickname: bool = ..., connect: bool = ..., + create_events: bool = ..., create_forum_threads: bool = ..., + create_guild_expressions: bool = ..., create_instant_invite: bool = ..., create_private_threads: bool = ..., create_public_threads: bool = ..., diff --git a/disnake/ext/commands/core.py b/disnake/ext/commands/core.py index 2ddcb10075..b9d49ab269 100644 --- a/disnake/ext/commands/core.py +++ b/disnake/ext/commands/core.py @@ -1999,7 +1999,9 @@ def has_permissions( ban_members: bool = ..., change_nickname: bool = ..., connect: bool = ..., + create_events: bool = ..., create_forum_threads: bool = ..., + create_guild_expressions: bool = ..., create_instant_invite: bool = ..., create_private_threads: bool = ..., create_public_threads: bool = ..., @@ -2121,7 +2123,9 @@ def bot_has_permissions( ban_members: bool = ..., change_nickname: bool = ..., connect: bool = ..., + create_events: bool = ..., create_forum_threads: bool = ..., + create_guild_expressions: bool = ..., create_instant_invite: bool = ..., create_private_threads: bool = ..., create_public_threads: bool = ..., @@ -2221,7 +2225,9 @@ def has_guild_permissions( ban_members: bool = ..., change_nickname: bool = ..., connect: bool = ..., + create_events: bool = ..., create_forum_threads: bool = ..., + create_guild_expressions: bool = ..., create_instant_invite: bool = ..., create_private_threads: bool = ..., create_public_threads: bool = ..., @@ -2318,7 +2324,9 @@ def bot_has_guild_permissions( ban_members: bool = ..., change_nickname: bool = ..., connect: bool = ..., + create_events: bool = ..., create_forum_threads: bool = ..., + create_guild_expressions: bool = ..., create_instant_invite: bool = ..., create_private_threads: bool = ..., create_public_threads: bool = ..., diff --git a/disnake/guild.py b/disnake/guild.py index ba140f2298..449f303c27 100644 --- a/disnake/guild.py +++ b/disnake/guild.py @@ -2387,7 +2387,7 @@ async def create_scheduled_event( Creates a :class:`GuildScheduledEvent`. - You must have :attr:`.Permissions.manage_events` permission to do this. + You must have :attr:`~Permissions.manage_events` permission to do this. Based on the channel/entity type, there are different restrictions regarding other parameter values, as shown in this table: @@ -3274,7 +3274,7 @@ async def delete_sticker(self, sticker: Snowflake, *, reason: Optional[str] = No Raises ------ Forbidden - You are not allowed to delete stickers. + You are not allowed to delete this sticker. HTTPException An error occurred deleting the sticker. """ @@ -3429,7 +3429,7 @@ async def delete_emoji(self, emoji: Snowflake, *, reason: Optional[str] = None) Raises ------ Forbidden - You are not allowed to delete emojis. + You are not allowed to delete this emoji. HTTPException An error occurred deleting the emoji. """ diff --git a/disnake/guild_scheduled_event.py b/disnake/guild_scheduled_event.py index 63b23620fe..1b01be136c 100644 --- a/disnake/guild_scheduled_event.py +++ b/disnake/guild_scheduled_event.py @@ -253,7 +253,7 @@ async def delete(self) -> None: Deletes the guild scheduled event. - You must have :attr:`.Permissions.manage_events` permission to do this. + You must have :attr:`~Permissions.manage_events` permission to do this. Raises ------ @@ -382,7 +382,7 @@ async def edit( Edits the guild scheduled event. - You must have :attr:`.Permissions.manage_events` permission to do this. + You must have :attr:`~Permissions.manage_events` permission to do this. .. versionchanged:: 2.6 Updates must follow requirements of :func:`Guild.create_scheduled_event` @@ -536,7 +536,7 @@ async def start(self, *, reason: Optional[str] = None) -> GuildScheduledEvent: Changes the event status to :attr:`~GuildScheduledEventStatus.active`. - You must have :attr:`.Permissions.manage_events` permission to do this. + You must have :attr:`~Permissions.manage_events` permission to do this. .. versionadded:: 2.7 @@ -570,7 +570,7 @@ async def end(self, *, reason: Optional[str] = None) -> GuildScheduledEvent: Changes the event status to :attr:`~GuildScheduledEventStatus.completed`. - You must have :attr:`.Permissions.manage_events` permission to do this. + You must have :attr:`~Permissions.manage_events` permission to do this. .. versionadded:: 2.7 @@ -604,7 +604,7 @@ async def cancel(self, *, reason: Optional[str] = None) -> GuildScheduledEvent: Changes the event status to :attr:`~GuildScheduledEventStatus.cancelled`. - You must have :attr:`.Permissions.manage_events` permission to do this. + You must have :attr:`~Permissions.manage_events` permission to do this. .. versionadded:: 2.7 diff --git a/disnake/permissions.py b/disnake/permissions.py index a7df815caa..edad50e84d 100644 --- a/disnake/permissions.py +++ b/disnake/permissions.py @@ -164,7 +164,9 @@ def __init__( ban_members: bool = ..., change_nickname: bool = ..., connect: bool = ..., + create_events: bool = ..., create_forum_threads: bool = ..., + create_guild_expressions: bool = ..., create_instant_invite: bool = ..., create_private_threads: bool = ..., create_public_threads: bool = ..., @@ -291,6 +293,7 @@ def all_channel(cls) -> Self: ``True`` and the guild-specific ones set to ``False``. The guild-specific permissions are currently: + - :attr:`create_guild_expressions` - :attr:`manage_guild_expressions` - :attr:`view_audit_log` - :attr:`view_guild_insights` @@ -316,12 +319,16 @@ def all_channel(cls) -> Self: .. versionchanged:: 2.9 Added :attr:`use_soundboard` and :attr:`send_voice_messages` permissions. + + .. versionchanged:: 2.10 + Added :attr:`create_events` permission. """ instance = cls.all() instance.update( administrator=False, ban_members=False, change_nickname=False, + create_guild_expressions=False, kick_members=False, manage_guild=False, manage_guild_expressions=False, @@ -347,11 +354,15 @@ def general(cls) -> Self: .. versionchanged:: 2.9 Added :attr:`view_creator_monetization_analytics` permission. + + .. versionchanged:: 2.10 + Added :attr:`create_guild_expressions` permission. """ return cls( view_channel=True, manage_channels=True, manage_roles=True, + create_guild_expressions=True, manage_guild_expressions=True, view_audit_log=True, view_guild_insights=True, @@ -475,8 +486,12 @@ def events(cls) -> Self: "Events" permissions from the official Discord UI set to ``True``. .. versionadded:: 2.4 + + .. versionchanged:: 2.10 + Added :attr:`create_events` permission. """ return cls( + create_events=True, manage_events=True, ) @@ -532,7 +547,9 @@ def update( ban_members: bool = ..., change_nickname: bool = ..., connect: bool = ..., + create_events: bool = ..., create_forum_threads: bool = ..., + create_guild_expressions: bool = ..., create_instant_invite: bool = ..., create_private_threads: bool = ..., create_public_threads: bool = ..., @@ -830,8 +847,10 @@ def manage_webhooks(self) -> int: @flag_value def manage_guild_expressions(self) -> int: - """:class:`bool`: Returns ``True`` if a user can create, edit, or delete - emojis, stickers, and soundboard sounds. + """:class:`bool`: Returns ``True`` if a user can edit or delete + emojis, stickers, and soundboard sounds created by all users. + + See also :attr:`create_guild_expressions`. .. versionadded:: 2.9 """ @@ -879,7 +898,10 @@ def request_to_speak(self) -> int: @flag_value def manage_events(self) -> int: - """:class:`bool`: Returns ``True`` if a user can manage guild events. + """:class:`bool`: Returns ``True`` if a user can edit or delete guild scheduled events + created by all users. + + See also :attr:`create_events`. .. versionadded:: 2.0 """ @@ -978,6 +1000,28 @@ def use_soundboard(self) -> int: """ return 1 << 42 + @flag_value + def create_guild_expressions(self) -> int: + """:class:`bool`: Returns ``True`` if a user can create emojis, stickers, + and soundboard sounds, as well as edit and delete the ones they created. + + See also :attr:`manage_guild_expressions`. + + .. versionadded:: 2.10 + """ + return 1 << 43 + + @flag_value + def create_events(self) -> int: + """:class:`bool`: Returns ``True`` if a user can create guild scheduled events, + as well as edit and delete the ones they created. + + See also :attr:`manage_events`. + + .. versionadded:: 2.10 + """ + return 1 << 44 + @flag_value def use_external_sounds(self) -> int: """:class:`bool`: Returns ``True`` if a user can use custom soundboard sounds from other guilds. @@ -1066,7 +1110,9 @@ class PermissionOverwrite: ban_members: Optional[bool] change_nickname: Optional[bool] connect: Optional[bool] + create_events: Optional[bool] create_forum_threads: Optional[bool] + create_guild_expressions: Optional[bool] create_instant_invite: Optional[bool] create_private_threads: Optional[bool] create_public_threads: Optional[bool] @@ -1130,7 +1176,9 @@ def __init__( ban_members: Optional[bool] = ..., change_nickname: Optional[bool] = ..., connect: Optional[bool] = ..., + create_events: Optional[bool] = ..., create_forum_threads: Optional[bool] = ..., + create_guild_expressions: Optional[bool] = ..., create_instant_invite: Optional[bool] = ..., create_private_threads: Optional[bool] = ..., create_public_threads: Optional[bool] = ..., @@ -1261,7 +1309,9 @@ def update( ban_members: Optional[bool] = ..., change_nickname: Optional[bool] = ..., connect: Optional[bool] = ..., + create_events: Optional[bool] = ..., create_forum_threads: Optional[bool] = ..., + create_guild_expressions: Optional[bool] = ..., create_instant_invite: Optional[bool] = ..., create_private_threads: Optional[bool] = ..., create_public_threads: Optional[bool] = ..., diff --git a/disnake/sticker.py b/disnake/sticker.py index 0d94c1ebcc..be7479cf2b 100644 --- a/disnake/sticker.py +++ b/disnake/sticker.py @@ -450,7 +450,7 @@ async def edit( Raises ------ Forbidden - You are not allowed to edit stickers. + You are not allowed to edit this sticker. HTTPException An error occurred editing the sticker. @@ -498,7 +498,7 @@ async def delete(self, *, reason: Optional[str] = None) -> None: Raises ------ Forbidden - You are not allowed to delete stickers. + You are not allowed to delete this sticker. HTTPException An error occurred deleting the sticker. """