From 7bd92359e55cfe1f43900780b20d9393d0294282 Mon Sep 17 00:00:00 2001 From: Paillat Date: Fri, 27 Dec 2024 09:37:03 +0100 Subject: [PATCH 1/2] fix: :bug: fix responding with paginator after deferring interaction ephemerally (#2661) * :bug: Fix error when responding with paginator to an ephemeral deferred interaction * :memo: CHANGELOG.md * :pencil2: Fix writing --------- Signed-off-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com> Co-authored-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com> --- CHANGELOG.md | 3 +++ discord/ext/pages/pagination.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b5a0edc608..02a2e4ceb9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,6 +64,9 @@ These changes are available on the `master` branch, but have not yet been releas apps. ([#2650](https://github.com/Pycord-Development/pycord/pull/2650)) - Fixed type annotations of cached properties. ([#2635](https://github.com/Pycord-Development/pycord/issues/2635)) +- Fixed an error when responding non-ephemerally with a `Paginator` to an ephemerally + deferred interaction. + ([#2661](https://github.com/Pycord-Development/pycord/pull/2661)) ### Changed diff --git a/discord/ext/pages/pagination.py b/discord/ext/pages/pagination.py index dc99996f2a..5fa297e6ee 100644 --- a/discord/ext/pages/pagination.py +++ b/discord/ext/pages/pagination.py @@ -1202,7 +1202,7 @@ async def respond( ) # convert from WebhookMessage to Message reference to bypass # 15min webhook token timeout (non-ephemeral messages only) - if not ephemeral: + if not ephemeral and not msg.flags.ephemeral: msg = await msg.channel.fetch_message(msg.id) else: msg = await interaction.response.send_message( From 9fa5cbe0d6e9de481799a6cd15e4dcd9ee18220a Mon Sep 17 00:00:00 2001 From: DA344 <108473820+DA-344@users.noreply.github.com> Date: Fri, 27 Dec 2024 22:17:25 +0100 Subject: [PATCH 2/2] 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 <89910983+JustaSqu1d@users.noreply.github.com> Signed-off-by: DA344 <108473820+DA-344@users.noreply.github.com> * chore: Update discord/commands/context.py Co-authored-by: JustaSqu1d <89910983+JustaSqu1d@users.noreply.github.com> Signed-off-by: DA344 <108473820+DA-344@users.noreply.github.com> * chore: Update discord/interactions.py Co-authored-by: JustaSqu1d <89910983+JustaSqu1d@users.noreply.github.com> Signed-off-by: DA344 <108473820+DA-344@users.noreply.github.com> * chore: Rename is_x_integration to is_x_authorised/authorized * chore: :alien: Update base max filesize to `10` Mb (#2671) * :alien: Update base max filesize to `10` Mb * :memo: CHANGELOG.md * chore: Update docstrings to mention aliases * chore: Update CHANGELOG.md Co-authored-by: JustaSqu1d <89910983+JustaSqu1d@users.noreply.github.com> Signed-off-by: DA344 <108473820+DA-344@users.noreply.github.com> * 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](https://github.com/python/mypy/compare/v1.13.0...v1.14.0) --- updated-dependencies: - dependency-name: mypy dependency-type: direct:development ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Update CHANGELOG.md Signed-off-by: plun1331 * chore: authorising -> authorizing (who commited this tf) Co-authored-by: JustaSqu1d <89910983+JustaSqu1d@users.noreply.github.com> Signed-off-by: DA344 <108473820+DA-344@users.noreply.github.com> --------- Signed-off-by: DA344 <108473820+DA-344@users.noreply.github.com> Signed-off-by: dependabot[bot] Signed-off-by: plun1331 Co-authored-by: JustaSqu1d <89910983+JustaSqu1d@users.noreply.github.com> Co-authored-by: Paillat Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: plun1331 --- CHANGELOG.md | 2 ++ discord/commands/context.py | 34 ++++++++++++++++++++++++++++++ discord/interactions.py | 42 +++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 02a2e4ceb9..dd27c65485 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 authorizing party of an `Interaction`. + ([#2659](https://github.com/Pycord-Development/pycord/pull/2659)) ### Fixed diff --git a/discord/commands/context.py b/discord/commands/context.py index 27c3b0acba..532d8abe2a 100644 --- a/discord/commands/context.py +++ b/discord/commands/context.py @@ -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`. + + 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`. + + 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. diff --git a/discord/interactions.py b/discord/interactions.py index e7d7fade3e..e9b9c16eec 100644 --- a/discord/interactions.py +++ b/discord/interactions.py @@ -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|