Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add helper methods to determine interactions integrations #2659

Merged
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
1e549e8
Add is_..._integration helper methods
DA-344 Nov 28, 2024
0d09f96
chore: Update changelog
DA-344 Nov 28, 2024
d63403e
Merge branch 'master' into feat/interaction-integrations-methods
DA-344 Dec 3, 2024
053bc06
chore: Update with suggestions
DA-344 Dec 10, 2024
ddee02b
chore: Update discord/commands/context.py
DA-344 Dec 10, 2024
80ceb6d
chore: Update discord/interactions.py
DA-344 Dec 10, 2024
6feb46f
Merge branch 'master' of https://github.com/Pycord-Development/pycord…
DA-344 Dec 15, 2024
5ded3fe
chore: Rename is_x_integration to is_x_authorised/authorized
DA-344 Dec 15, 2024
112a69f
Merge branch 'master' of https://github.com/Pycord-Development/pycord…
DA-344 Dec 18, 2024
8dd4b4f
chore: :alien: Update base max filesize to `10` Mb (#2671)
Paillat-dev Dec 18, 2024
df0dd91
chore: Update docstrings to mention aliases
DA-344 Dec 18, 2024
ff2f1b7
chore: Update CHANGELOG.md
DA-344 Dec 18, 2024
269f538
chore(deps-dev): update mypy requirement from ~=1.13.0 to ~=1.14.0 (#…
dependabot[bot] Dec 20, 2024
cf04e3e
Merge branch 'Pycord-Development:master' into feat/interaction-integr…
DA-344 Dec 22, 2024
556d06a
Merge branch 'master' into feat/interaction-integrations-methods
plun1331 Dec 25, 2024
dfa89fe
Update CHANGELOG.md
plun1331 Dec 26, 2024
317fcef
Merge branch 'master' into feat/interaction-integrations-methods
plun1331 Dec 27, 2024
9edbb55
chore: authorising -> authorizing (who commited this tf)
DA-344 Dec 27, 2024
c7ca029
Merge branch 'master' into feat/interaction-integrations-methods
DA-344 Dec 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ These changes are available on the `master` branch, but have not yet been releas
`Permissions.use_external_sounds`, and
`Permissions.view_creator_monetization_analytics`.
([#2620](https://github.com/Pycord-Development/pycord/pull/2620))
- Added helper methods to determine the authorising party of an `Interaction`.
DA-344 marked this conversation as resolved.
Show resolved Hide resolved
([#2659](https://github.com/Pycord-Development/pycord/pull/2659))

### Fixed

Expand Down
34 changes: 34 additions & 0 deletions discord/commands/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,40 @@ def cog(self) -> Cog | None:

return self.command.cog

def is_guild_authorised(self) -> bool:
""":class:`bool`: Checks if the invoked command is guild-installed.
This is a shortcut for :meth:`Interaction.is_guild_authorised`.

DA-344 marked this conversation as resolved.
Show resolved Hide resolved
There is an alias for this called :meth:`.is_guild_authorized`.

.. versionadded:: 2.7
"""
return self.interaction.is_guild_authorised()

def is_user_authorised(self) -> bool:
""":class:`bool`: Checks if the invoked command is user-installed.
This is a shortcut for :meth:`Interaction.is_user_authorised`.

DA-344 marked this conversation as resolved.
Show resolved Hide resolved
There is an alias for this called :meth:`.is_user_authorized`.

.. versionadded:: 2.7
"""
return self.interaction.is_user_authorised()

def is_guild_authorized(self) -> bool:
""":class:`bool`: An alias for :meth:`.is_guild_authorised`.

.. versionadded:: 2.7
"""
return self.is_guild_authorised()

def is_user_authorized(self) -> bool:
""":class:`bool`: An alias for :meth:`.is_user_authorised`.

.. versionadded:: 2.7
"""
return self.is_user_authorised()


class AutocompleteContext:
"""Represents context for a slash command's option autocomplete.
Expand Down
42 changes: 42 additions & 0 deletions discord/interactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,48 @@ def followup(self) -> Webhook:
}
return Webhook.from_state(data=payload, state=self._state)

def is_guild_authorised(self) -> bool:
""":class:`bool`: Checks if the interaction is guild authorised.

There is an alias for this called :meth:`.is_guild_authorized`.

.. versionadded:: 2.7
"""
if self.guild_id:
return self.authorizing_integration_owners.guild_id == self.guild_id
return False

def is_user_authorised(self) -> bool:
""":class:`bool`: Checks if the interaction is user authorised.

There is an alias for this called :meth:`.is_user_authorized`.

.. versionadded:: 2.7
"""
if self.user:
return self.authorizing_integration_owners.user_id == self.user.id

# This return should not be called but to make sure it returns the expected value
return False

def is_guild_authorized(self) -> bool:
""":class:`bool`: Checks if the interaction is guild authorized.

There is an alias for this called :meth:`.is_guild_authorised`.

.. versionadded:: 2.7
"""
return self.is_guild_authorised()

def is_user_authorized(self) -> bool:
""":class:`bool`: Checks if the interaction is user authorized.

There is an alias for this called :meth:`.is_user_authorised`.

.. versionadded:: 2.7
"""
return self.is_user_authorised()

async def original_response(self) -> InteractionMessage:
"""|coro|

Expand Down
Loading