Skip to content

Commit

Permalink
feat: user-installable apps (#2409)
Browse files Browse the repository at this point in the history
* add enums, do command stuff, add context to interaction

* style(pre-commit): auto fixes from pre-commit.com hooks

* add authorizing_integration_owners

* style(pre-commit): auto fixes from pre-commit.com hooks

* add application_metadata

* style(pre-commit): auto fixes from pre-commit.com hooks

* don't trust copilot

* style(pre-commit): auto fixes from pre-commit.com hooks

* update __all__

* circular import

* style(pre-commit): auto fixes from pre-commit.com hooks

* fix numbers

* h

* style(pre-commit): auto fixes from pre-commit.com hooks

* update guild_only deco to use contexts

* type

* style(pre-commit): auto fixes from pre-commit.com hooks

* deprecation warnings

* style(pre-commit): auto fixes from pre-commit.com hooks

* docs

* example

* style(pre-commit): auto fixes from pre-commit.com hooks

* edit docs

* update changelog

* style(pre-commit): auto fixes from pre-commit.com hooks

* update changelog

* add default contexts and integration_types values

* style(pre-commit): auto fixes from pre-commit.com hooks

* add default contexts and integration_types values

* h

* style(pre-commit): auto fixes from pre-commit.com hooks

* subcmds

* subcmds

* update check for desynced cmds

* h

* h

* Apply suggestions from code review

Co-authored-by: JustaSqu1d <89910983+JustaSqu1d@users.noreply.github.com>
Signed-off-by: plun1331 <plun1331@gmail.com>

* Update CHANGELOG.md

Seperate fix was made in #2411

Signed-off-by: plun1331 <plun1331@gmail.com>

* allow Message.interaction to be settable

ref. mahtoid/DiscordChatExporterPy#106

Signed-off-by: plun1331 <plun1331@gmail.com>

* Update core.py

Signed-off-by: plun1331 <plun1331@gmail.com>

* Update interactions.py

Signed-off-by: plun1331 <plun1331@gmail.com>

* style(pre-commit): auto fixes from pre-commit.com hooks

* Update core.py

Signed-off-by: plun1331 <plun1331@gmail.com>

* style(pre-commit): auto fixes from pre-commit.com hooks

* Update core.py

Signed-off-by: plun1331 <plun1331@gmail.com>

* Apply suggestions from code review

Co-authored-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com>
Signed-off-by: plun1331 <plun1331@gmail.com>

* Update permissions.py

Signed-off-by: plun1331 <plun1331@gmail.com>

* Update permissions.py

Signed-off-by: plun1331 <plun1331@gmail.com>

* style(pre-commit): auto fixes from pre-commit.com hooks

* Update interactions.py

Signed-off-by: plun1331 <plun1331@gmail.com>

* Apply suggestions from code review

Signed-off-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com>

* Update discord/interactions.py

Signed-off-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com>

* style(pre-commit): auto fixes from pre-commit.com hooks

---------

Signed-off-by: plun1331 <plun1331@gmail.com>
Signed-off-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: JustaSqu1d <89910983+JustaSqu1d@users.noreply.github.com>
Co-authored-by: Lala Sabathil <lala@pycord.dev>
Co-authored-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com>
  • Loading branch information
5 people committed Jun 25, 2024
1 parent 284d40c commit 59b919f
Show file tree
Hide file tree
Showing 13 changed files with 556 additions and 44 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ These changes are available on the `master` branch, but have not yet been releas
([#2408](https://github.com/Pycord-Development/pycord/pull/2408))
- Added `stacklevel` param to `utils.warn_deprecated` and `utils.deprecated`.
([#2450](https://github.com/Pycord-Development/pycord/pull/2450))
- Added support for user-installable applications.
([#2409](https://github.com/Pycord-Development/pycord/pull/2409)

### Fixed

Expand Down Expand Up @@ -71,6 +73,11 @@ These changes are available on the `master` branch, but have not yet been releas
([#2417](https://github.com/Pycord-Development/pycord/pull/2417))
- `Guild.query_members` now accepts `limit=None` to retrieve all members.
([#2419](https://github.com/Pycord-Development/pycord/pull/2419))
- `ApplicationCommand.guild_only` is now deprecated in favor of
`ApplicationCommand.contexts`.
([#2409](https://github.com/Pycord-Development/pycord/pull/2409))
- `Message.interaction` is now deprecated in favor of `Message.interaction_metadata`.
([#2409](https://github.com/Pycord-Development/pycord/pull/2409)

### Removed

Expand Down
52 changes: 50 additions & 2 deletions discord/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
UserCommand,
command,
)
from .enums import InteractionType
from .enums import IntegrationType, InteractionContextType, InteractionType
from .errors import CheckFailure, DiscordException
from .interactions import Interaction
from .shard import AutoShardedClient
Expand Down Expand Up @@ -125,6 +125,13 @@ def add_application_command(self, command: ApplicationCommand) -> None:

if self._bot.debug_guilds and command.guild_ids is None:
command.guild_ids = self._bot.debug_guilds
if self._bot.default_command_contexts and command.contexts is None:
command.contexts = self._bot.default_command_contexts
if (
self._bot.default_command_integration_types
and command.integration_types is None
):
command.integration_types = self._bot.default_command_integration_types

for cmd in self.pending_application_commands:
if cmd == command:
Expand Down Expand Up @@ -271,7 +278,6 @@ def _check_command(cmd: ApplicationCommand, match: Mapping[str, Any]) -> bool:
else:
as_dict = cmd.to_dict()
to_check = {
"dm_permission": None,
"nsfw": None,
"default_member_permissions": None,
"name": None,
Expand All @@ -287,6 +293,8 @@ def _check_command(cmd: ApplicationCommand, match: Mapping[str, Any]) -> bool:
"name_localizations",
"description_localizations",
],
"contexts": None,
"integration_types": None,
}
for check, value in to_check.items():
if type(to_check[check]) == list:
Expand Down Expand Up @@ -1157,6 +1165,21 @@ def __init__(self, description=None, *args, **options):
self.auto_sync_commands = options.get("auto_sync_commands", True)

self.debug_guilds = options.pop("debug_guilds", None)
self.default_command_contexts = options.pop(
"default_command_contexts",
{
InteractionContextType.guild,
InteractionContextType.bot_dm,
InteractionContextType.private_channel,
},
)

self.default_command_integration_types = options.pop(
"default_command_integration_types",
{
IntegrationType.guild_install,
},
)

if self.owner_id and self.owner_ids:
raise TypeError("Both owner_id and owner_ids are set.")
Expand All @@ -1167,6 +1190,20 @@ def __init__(self, description=None, *args, **options):
raise TypeError(
f"owner_ids must be a collection not {self.owner_ids.__class__!r}"
)
if not isinstance(self.default_command_contexts, collections.abc.Collection):
raise TypeError(
f"default_command_contexts must be a collection not {self.default_command_contexts.__class__!r}"
)
if not isinstance(
self.default_command_integration_types, collections.abc.Collection
):
raise TypeError(
f"default_command_integration_types must be a collection not {self.default_command_integration_types.__class__!r}"
)
self.default_command_contexts = set(self.default_command_contexts)
self.default_command_integration_types = set(
self.default_command_integration_types
)

self._checks = []
self._check_once = []
Expand Down Expand Up @@ -1447,6 +1484,17 @@ class Bot(BotBase, Client):
:attr:`.process_application_commands` if the command is not found. Defaults to ``True``.
.. versionadded:: 2.0
default_command_contexts: Collection[:class:`InteractionContextType`]
The default context types that the bot will use for commands.
Defaults to a set containing :attr:`InteractionContextType.guild`, :attr:`InteractionContextType.bot_dm`, and
:attr:`InteractionContextType.private_channel`.
.. versionadded:: 2.6
default_command_integration_types: Collection[:class:`IntegrationType`]]
The default integration types that the bot will use for commands.
Defaults to a set containing :attr:`IntegrationType.guild_install`.
.. versionadded:: 2.6
"""

@property
Expand Down
Loading

0 comments on commit 59b919f

Please sign in to comment.