Skip to content

Commit 59b919f

Browse files
plun1331pre-commit-ci[bot]JustaSqu1dLulalabyDorukyum
authored
feat: user-installable apps (#2409)
* 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 <[email protected]> Signed-off-by: plun1331 <[email protected]> * Update CHANGELOG.md Seperate fix was made in #2411 Signed-off-by: plun1331 <[email protected]> * allow Message.interaction to be settable ref. mahtoid/DiscordChatExporterPy#106 Signed-off-by: plun1331 <[email protected]> * Update core.py Signed-off-by: plun1331 <[email protected]> * Update interactions.py Signed-off-by: plun1331 <[email protected]> * style(pre-commit): auto fixes from pre-commit.com hooks * Update core.py Signed-off-by: plun1331 <[email protected]> * style(pre-commit): auto fixes from pre-commit.com hooks * Update core.py Signed-off-by: plun1331 <[email protected]> * Apply suggestions from code review Co-authored-by: Dorukyum <[email protected]> Signed-off-by: plun1331 <[email protected]> * Update permissions.py Signed-off-by: plun1331 <[email protected]> * Update permissions.py Signed-off-by: plun1331 <[email protected]> * style(pre-commit): auto fixes from pre-commit.com hooks * Update interactions.py Signed-off-by: plun1331 <[email protected]> * Apply suggestions from code review Signed-off-by: Dorukyum <[email protected]> * Update discord/interactions.py Signed-off-by: Dorukyum <[email protected]> * style(pre-commit): auto fixes from pre-commit.com hooks --------- Signed-off-by: plun1331 <[email protected]> Signed-off-by: Dorukyum <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: JustaSqu1d <[email protected]> Co-authored-by: Lala Sabathil <[email protected]> Co-authored-by: Dorukyum <[email protected]>
1 parent 284d40c commit 59b919f

File tree

13 files changed

+556
-44
lines changed

13 files changed

+556
-44
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ These changes are available on the `master` branch, but have not yet been releas
2828
([#2408](https://github.com/Pycord-Development/pycord/pull/2408))
2929
- Added `stacklevel` param to `utils.warn_deprecated` and `utils.deprecated`.
3030
([#2450](https://github.com/Pycord-Development/pycord/pull/2450))
31+
- Added support for user-installable applications.
32+
([#2409](https://github.com/Pycord-Development/pycord/pull/2409)
3133

3234
### Fixed
3335

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

7582
### Removed
7683

discord/bot.py

+50-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
UserCommand,
4949
command,
5050
)
51-
from .enums import InteractionType
51+
from .enums import IntegrationType, InteractionContextType, InteractionType
5252
from .errors import CheckFailure, DiscordException
5353
from .interactions import Interaction
5454
from .shard import AutoShardedClient
@@ -125,6 +125,13 @@ def add_application_command(self, command: ApplicationCommand) -> None:
125125

126126
if self._bot.debug_guilds and command.guild_ids is None:
127127
command.guild_ids = self._bot.debug_guilds
128+
if self._bot.default_command_contexts and command.contexts is None:
129+
command.contexts = self._bot.default_command_contexts
130+
if (
131+
self._bot.default_command_integration_types
132+
and command.integration_types is None
133+
):
134+
command.integration_types = self._bot.default_command_integration_types
128135

129136
for cmd in self.pending_application_commands:
130137
if cmd == command:
@@ -271,7 +278,6 @@ def _check_command(cmd: ApplicationCommand, match: Mapping[str, Any]) -> bool:
271278
else:
272279
as_dict = cmd.to_dict()
273280
to_check = {
274-
"dm_permission": None,
275281
"nsfw": None,
276282
"default_member_permissions": None,
277283
"name": None,
@@ -287,6 +293,8 @@ def _check_command(cmd: ApplicationCommand, match: Mapping[str, Any]) -> bool:
287293
"name_localizations",
288294
"description_localizations",
289295
],
296+
"contexts": None,
297+
"integration_types": None,
290298
}
291299
for check, value in to_check.items():
292300
if type(to_check[check]) == list:
@@ -1157,6 +1165,21 @@ def __init__(self, description=None, *args, **options):
11571165
self.auto_sync_commands = options.get("auto_sync_commands", True)
11581166

11591167
self.debug_guilds = options.pop("debug_guilds", None)
1168+
self.default_command_contexts = options.pop(
1169+
"default_command_contexts",
1170+
{
1171+
InteractionContextType.guild,
1172+
InteractionContextType.bot_dm,
1173+
InteractionContextType.private_channel,
1174+
},
1175+
)
1176+
1177+
self.default_command_integration_types = options.pop(
1178+
"default_command_integration_types",
1179+
{
1180+
IntegrationType.guild_install,
1181+
},
1182+
)
11601183

11611184
if self.owner_id and self.owner_ids:
11621185
raise TypeError("Both owner_id and owner_ids are set.")
@@ -1167,6 +1190,20 @@ def __init__(self, description=None, *args, **options):
11671190
raise TypeError(
11681191
f"owner_ids must be a collection not {self.owner_ids.__class__!r}"
11691192
)
1193+
if not isinstance(self.default_command_contexts, collections.abc.Collection):
1194+
raise TypeError(
1195+
f"default_command_contexts must be a collection not {self.default_command_contexts.__class__!r}"
1196+
)
1197+
if not isinstance(
1198+
self.default_command_integration_types, collections.abc.Collection
1199+
):
1200+
raise TypeError(
1201+
f"default_command_integration_types must be a collection not {self.default_command_integration_types.__class__!r}"
1202+
)
1203+
self.default_command_contexts = set(self.default_command_contexts)
1204+
self.default_command_integration_types = set(
1205+
self.default_command_integration_types
1206+
)
11701207

11711208
self._checks = []
11721209
self._check_once = []
@@ -1447,6 +1484,17 @@ class Bot(BotBase, Client):
14471484
:attr:`.process_application_commands` if the command is not found. Defaults to ``True``.
14481485
14491486
.. versionadded:: 2.0
1487+
default_command_contexts: Collection[:class:`InteractionContextType`]
1488+
The default context types that the bot will use for commands.
1489+
Defaults to a set containing :attr:`InteractionContextType.guild`, :attr:`InteractionContextType.bot_dm`, and
1490+
:attr:`InteractionContextType.private_channel`.
1491+
1492+
.. versionadded:: 2.6
1493+
default_command_integration_types: Collection[:class:`IntegrationType`]]
1494+
The default integration types that the bot will use for commands.
1495+
Defaults to a set containing :attr:`IntegrationType.guild_install`.
1496+
1497+
.. versionadded:: 2.6
14501498
"""
14511499

14521500
@property

0 commit comments

Comments
 (0)