Skip to content

Commit

Permalink
Merge branch 'master' into partial-autocomplete
Browse files Browse the repository at this point in the history
Signed-off-by: Paillat <[email protected]>
  • Loading branch information
Paillat-dev authored Dec 28, 2024
2 parents 1165cb6 + 9fa5cbe commit 0378f17
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 1 deletion.
5 changes: 5 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 authorizing party of an `Interaction`.
([#2659](https://github.com/Pycord-Development/pycord/pull/2659))
- Added the ability to use functions with any number of optional arguments and functions
returning an awaitable as `Option.autocomplete`.
([#2669](https://github.com/Pycord-Development/pycord/pull/2669))
Expand Down Expand Up @@ -67,6 +69,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

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`.
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.
Expand Down
2 changes: 1 addition & 1 deletion discord/ext/pages/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
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

0 comments on commit 0378f17

Please sign in to comment.