Skip to content

Commit 9fa5cbe

Browse files
DA-344JustaSqu1dPaillat-devdependabot[bot]plun1331
authored
feat: Add helper methods to determine interactions integrations (#2659)
* Add is_..._integration helper methods * chore: Update changelog * chore: Update with suggestions Co-authored-by: JustaSqu1d <[email protected]> Signed-off-by: DA344 <[email protected]> * chore: Update discord/commands/context.py Co-authored-by: JustaSqu1d <[email protected]> Signed-off-by: DA344 <[email protected]> * chore: Update discord/interactions.py Co-authored-by: JustaSqu1d <[email protected]> Signed-off-by: DA344 <[email protected]> * chore: Rename is_x_integration to is_x_authorised/authorized * chore: 👽 Update base max filesize to `10` Mb (#2671) * 👽 Update base max filesize to `10` Mb * 📝 CHANGELOG.md * chore: Update docstrings to mention aliases * chore: Update CHANGELOG.md Co-authored-by: JustaSqu1d <[email protected]> Signed-off-by: DA344 <[email protected]> * chore(deps-dev): update mypy requirement from ~=1.13.0 to ~=1.14.0 (#2676) Updates the requirements on [mypy](https://github.com/python/mypy) to permit the latest version. - [Changelog](https://github.com/python/mypy/blob/master/CHANGELOG.md) - [Commits](python/mypy@v1.13.0...v1.14.0) --- updated-dependencies: - dependency-name: mypy dependency-type: direct:development ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Update CHANGELOG.md Signed-off-by: plun1331 <[email protected]> * chore: authorising -> authorizing (who commited this tf) Co-authored-by: JustaSqu1d <[email protected]> Signed-off-by: DA344 <[email protected]> --------- Signed-off-by: DA344 <[email protected]> Signed-off-by: dependabot[bot] <[email protected]> Signed-off-by: plun1331 <[email protected]> Co-authored-by: JustaSqu1d <[email protected]> Co-authored-by: Paillat <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: plun1331 <[email protected]>
1 parent 7bd9235 commit 9fa5cbe

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ These changes are available on the `master` branch, but have not yet been releas
3636
`Permissions.use_external_sounds`, and
3737
`Permissions.view_creator_monetization_analytics`.
3838
([#2620](https://github.com/Pycord-Development/pycord/pull/2620))
39+
- Added helper methods to determine the authorizing party of an `Interaction`.
40+
([#2659](https://github.com/Pycord-Development/pycord/pull/2659))
3941

4042
### Fixed
4143

discord/commands/context.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,40 @@ def cog(self) -> Cog | None:
345345

346346
return self.command.cog
347347

348+
def is_guild_authorised(self) -> bool:
349+
""":class:`bool`: Checks if the invoked command is guild-installed.
350+
This is a shortcut for :meth:`Interaction.is_guild_authorised`.
351+
352+
There is an alias for this called :meth:`.is_guild_authorized`.
353+
354+
.. versionadded:: 2.7
355+
"""
356+
return self.interaction.is_guild_authorised()
357+
358+
def is_user_authorised(self) -> bool:
359+
""":class:`bool`: Checks if the invoked command is user-installed.
360+
This is a shortcut for :meth:`Interaction.is_user_authorised`.
361+
362+
There is an alias for this called :meth:`.is_user_authorized`.
363+
364+
.. versionadded:: 2.7
365+
"""
366+
return self.interaction.is_user_authorised()
367+
368+
def is_guild_authorized(self) -> bool:
369+
""":class:`bool`: An alias for :meth:`.is_guild_authorised`.
370+
371+
.. versionadded:: 2.7
372+
"""
373+
return self.is_guild_authorised()
374+
375+
def is_user_authorized(self) -> bool:
376+
""":class:`bool`: An alias for :meth:`.is_user_authorised`.
377+
378+
.. versionadded:: 2.7
379+
"""
380+
return self.is_user_authorised()
381+
348382

349383
class AutocompleteContext:
350384
"""Represents context for a slash command's option autocomplete.

discord/interactions.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,48 @@ def followup(self) -> Webhook:
360360
}
361361
return Webhook.from_state(data=payload, state=self._state)
362362

363+
def is_guild_authorised(self) -> bool:
364+
""":class:`bool`: Checks if the interaction is guild authorised.
365+
366+
There is an alias for this called :meth:`.is_guild_authorized`.
367+
368+
.. versionadded:: 2.7
369+
"""
370+
if self.guild_id:
371+
return self.authorizing_integration_owners.guild_id == self.guild_id
372+
return False
373+
374+
def is_user_authorised(self) -> bool:
375+
""":class:`bool`: Checks if the interaction is user authorised.
376+
377+
There is an alias for this called :meth:`.is_user_authorized`.
378+
379+
.. versionadded:: 2.7
380+
"""
381+
if self.user:
382+
return self.authorizing_integration_owners.user_id == self.user.id
383+
384+
# This return should not be called but to make sure it returns the expected value
385+
return False
386+
387+
def is_guild_authorized(self) -> bool:
388+
""":class:`bool`: Checks if the interaction is guild authorized.
389+
390+
There is an alias for this called :meth:`.is_guild_authorised`.
391+
392+
.. versionadded:: 2.7
393+
"""
394+
return self.is_guild_authorised()
395+
396+
def is_user_authorized(self) -> bool:
397+
""":class:`bool`: Checks if the interaction is user authorized.
398+
399+
There is an alias for this called :meth:`.is_user_authorised`.
400+
401+
.. versionadded:: 2.7
402+
"""
403+
return self.is_user_authorised()
404+
363405
async def original_response(self) -> InteractionMessage:
364406
"""|coro|
365407

0 commit comments

Comments
 (0)