Skip to content

Commit

Permalink
feat(permissions): add use_external_apps permission (#1211)
Browse files Browse the repository at this point in the history
  • Loading branch information
shiftinv authored Aug 7, 2024
1 parent b70b608 commit dd1e6aa
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog/1211.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add :attr:`Permissions.use_external_apps`, and a new :attr:`Permissions.apps` category to match the Discord client UI.
1 change: 1 addition & 0 deletions disnake/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,7 @@ async def set_permissions(
stream: Optional[bool] = ...,
use_application_commands: Optional[bool] = ...,
use_embedded_activities: Optional[bool] = ...,
use_external_apps: Optional[bool] = ...,
use_external_emojis: Optional[bool] = ...,
use_external_sounds: Optional[bool] = ...,
use_external_stickers: Optional[bool] = ...,
Expand Down
1 change: 1 addition & 0 deletions disnake/ext/commands/base_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,7 @@ def default_member_permissions(
stream: bool = ...,
use_application_commands: bool = ...,
use_embedded_activities: bool = ...,
use_external_apps: bool = ...,
use_external_emojis: bool = ...,
use_external_sounds: bool = ...,
use_external_stickers: bool = ...,
Expand Down
4 changes: 4 additions & 0 deletions disnake/ext/commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2039,6 +2039,7 @@ def has_permissions(
stream: bool = ...,
use_application_commands: bool = ...,
use_embedded_activities: bool = ...,
use_external_apps: bool = ...,
use_external_emojis: bool = ...,
use_external_sounds: bool = ...,
use_external_stickers: bool = ...,
Expand Down Expand Up @@ -2163,6 +2164,7 @@ def bot_has_permissions(
stream: bool = ...,
use_application_commands: bool = ...,
use_embedded_activities: bool = ...,
use_external_apps: bool = ...,
use_external_emojis: bool = ...,
use_external_sounds: bool = ...,
use_external_stickers: bool = ...,
Expand Down Expand Up @@ -2265,6 +2267,7 @@ def has_guild_permissions(
stream: bool = ...,
use_application_commands: bool = ...,
use_embedded_activities: bool = ...,
use_external_apps: bool = ...,
use_external_emojis: bool = ...,
use_external_sounds: bool = ...,
use_external_stickers: bool = ...,
Expand Down Expand Up @@ -2364,6 +2367,7 @@ def bot_has_guild_permissions(
stream: bool = ...,
use_application_commands: bool = ...,
use_embedded_activities: bool = ...,
use_external_apps: bool = ...,
use_external_emojis: bool = ...,
use_external_sounds: bool = ...,
use_external_stickers: bool = ...,
Expand Down
39 changes: 37 additions & 2 deletions disnake/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ def __init__(
stream: bool = ...,
use_application_commands: bool = ...,
use_embedded_activities: bool = ...,
use_external_apps: bool = ...,
use_external_emojis: bool = ...,
use_external_sounds: bool = ...,
use_external_stickers: bool = ...,
Expand Down Expand Up @@ -407,6 +408,9 @@ def text(cls) -> Self:
.. versionchanged:: 2.9
Added :attr:`send_voice_messages` permission.
.. versionchanged:: 2.10
Moved :attr:`use_application_commands` permission to :attr:`apps`.
"""
return cls(
send_messages=True,
Expand All @@ -423,7 +427,6 @@ def text(cls) -> Self:
manage_threads=True,
read_message_history=True,
send_tts_messages=True,
use_slash_commands=True,
send_voice_messages=True,
)

Expand All @@ -438,12 +441,14 @@ def voice(cls) -> Self:
.. versionchanged:: 2.9
Added :attr:`use_soundboard` and :attr:`use_external_sounds` permissions.
.. versionchanged:: 2.10
Moved :attr:`use_embedded_activities` permission to :attr:`apps`.
"""
return cls(
connect=True,
speak=True,
stream=True,
use_embedded_activities=True,
use_soundboard=True,
use_external_sounds=True,
use_voice_activation=True,
Expand Down Expand Up @@ -479,6 +484,20 @@ def stage_moderator(cls) -> Self:
move_members=True,
)

@classmethod
@cached_creation
def apps(cls) -> Self:
"""A factory method that creates a :class:`Permissions` with all
"Apps" permissions from the official Discord UI set to ``True``.
.. versionadded:: 2.10
"""
return cls(
use_application_commands=True,
use_embedded_activities=True,
use_external_apps=True,
)

@classmethod
@cached_creation
def events(cls) -> Self:
Expand Down Expand Up @@ -587,6 +606,7 @@ def update(
stream: bool = ...,
use_application_commands: bool = ...,
use_embedded_activities: bool = ...,
use_external_apps: bool = ...,
use_external_emojis: bool = ...,
use_external_sounds: bool = ...,
use_external_stickers: bool = ...,
Expand Down Expand Up @@ -1038,6 +1058,18 @@ def send_voice_messages(self) -> int:
"""
return 1 << 46

@flag_value
def use_external_apps(self) -> int:
""":class:`bool`: Returns ``True`` if a user's apps can send public responses.
If disabled, users can still use their user-installed applications, but the responses
will be forced ephemeral (i.e. only visible to them).
Only applies to user-installed apps that are not also installed to the guild.
.. versionadded:: 2.10
"""
return 1 << 50


def _augment_from_permissions(cls):
cls.VALID_NAMES = set(Permissions.VALID_FLAGS)
Expand Down Expand Up @@ -1150,6 +1182,7 @@ class PermissionOverwrite:
stream: Optional[bool]
use_application_commands: Optional[bool]
use_embedded_activities: Optional[bool]
use_external_apps: Optional[bool]
use_external_emojis: Optional[bool]
use_external_sounds: Optional[bool]
use_external_stickers: Optional[bool]
Expand Down Expand Up @@ -1216,6 +1249,7 @@ def __init__(
stream: Optional[bool] = ...,
use_application_commands: Optional[bool] = ...,
use_embedded_activities: Optional[bool] = ...,
use_external_apps: Optional[bool] = ...,
use_external_emojis: Optional[bool] = ...,
use_external_sounds: Optional[bool] = ...,
use_external_stickers: Optional[bool] = ...,
Expand Down Expand Up @@ -1349,6 +1383,7 @@ def update(
stream: Optional[bool] = ...,
use_application_commands: Optional[bool] = ...,
use_embedded_activities: Optional[bool] = ...,
use_external_apps: Optional[bool] = ...,
use_external_emojis: Optional[bool] = ...,
use_external_sounds: Optional[bool] = ...,
use_external_stickers: Optional[bool] = ...,
Expand Down

0 comments on commit dd1e6aa

Please sign in to comment.