Skip to content

Commit

Permalink
feat(permissions): add create_guild_expressions and create_events
Browse files Browse the repository at this point in the history
… permissions (#1091)
  • Loading branch information
shiftinv authored Nov 22, 2023
1 parent cd48c92 commit fb73dbb
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 15 deletions.
1 change: 1 addition & 0 deletions changelog/1091.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add :attr:`Permissions.create_guild_expressions` and :attr:`Permissions.create_events`.
2 changes: 2 additions & 0 deletions disnake/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = ...,
Expand Down
1 change: 1 addition & 0 deletions disnake/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1207,6 +1207,7 @@ def permissions_for(
denied.update(
manage_channels=True,
manage_roles=True,
create_events=True,
manage_events=True,
manage_webhooks=True,
)
Expand Down
4 changes: 2 additions & 2 deletions disnake/emoji.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions disnake/ext/commands/base_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ...,
Expand Down
8 changes: 8 additions & 0 deletions disnake/ext/commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ...,
Expand Down Expand Up @@ -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 = ...,
Expand Down Expand Up @@ -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 = ...,
Expand Down Expand Up @@ -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 = ...,
Expand Down
6 changes: 3 additions & 3 deletions disnake/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
"""
Expand Down Expand Up @@ -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.
"""
Expand Down
10 changes: 5 additions & 5 deletions disnake/guild_scheduled_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
------
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
56 changes: 53 additions & 3 deletions disnake/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ...,
Expand Down Expand Up @@ -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`
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
)

Expand Down Expand Up @@ -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 = ...,
Expand Down Expand Up @@ -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
"""
Expand Down Expand Up @@ -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
"""
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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] = ...,
Expand Down Expand Up @@ -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] = ...,
Expand Down
4 changes: 2 additions & 2 deletions disnake/sticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
"""
Expand Down

0 comments on commit fb73dbb

Please sign in to comment.