-
Notifications
You must be signed in to change notification settings - Fork 145
refactor(commands): rewrite app command storage to support multiple per-guild commands with the same name #1107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
EQUENOS
wants to merge
70
commits into
master
Choose a base branch
from
refactor/app-command-storage
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 35 commits
Commits
Show all changes
70 commits
Select commit
Hold shift + click to select a range
3c37179
A draft of the app commands storage refactor
EQUENOS b650009
Add missing deprecation warnings and properties
EQUENOS ec3896d
Fix a bad check
EQUENOS ea1ad65
Fix linting issues
EQUENOS 424ed03
Update docs and add changelog
EQUENOS a2b0677
Avoid unnecessary generators
EQUENOS dbd7920
Fix docs references
EQUENOS e86e5cb
Add errors for ambiguous app command searches
EQUENOS f80dbf6
First word of the docstring should not be "This"
EQUENOS 4ed930d
docs: group some changelog entries
EQUENOS 192d2b9
chore: rename `AppCommandRegistrationError`
EQUENOS 686bd48
docs: fix references in changelog entries
EQUENOS 8b5916c
docs: hide the `ext.commands` prefix in changelog entries
EQUENOS 88584c7
docs: revert the removal of `ext.commands` prefix
EQUENOS 1f10a8d
fix: subcommands trying to be top level commands
EQUENOS f5d5d57
chore: remove deprecated undocumented things
EQUENOS 164df50
chore: fix a small linting issue
EQUENOS 0064e9a
chore: replace `warn_deprecated` with `deprecated `
EQUENOS 4736dad
chore: resolve `remove_app_command` nits
EQUENOS 8c6bb90
chore: add suggested typings
EQUENOS c44806b
docs: fix typos and improve comments
EQUENOS ef591e6
chore: simplify ambiguity checks
EQUENOS 42c7e6f
docs: explain command location priorities
EQUENOS 9a4d1aa
Make `bot.all_app_commands` a mapping proxy
EQUENOS 55299b2
fix: unintended breaking change (handling `guild_ids=[]`)
EQUENOS 8dc756e
docs: `AppCmdIndex`
EQUENOS d519711
fix: docs and linting
EQUENOS 413f759
Make `AppCmdIndex` public
EQUENOS 304a829
docs: fix a reference
EQUENOS 63ce007
docs: improve AppCmdIndex docstring
EQUENOS a580238
docs: small fixes; chore: move `AppCmdIndex` to a different file
EQUENOS 764324a
Merge branch 'master' into refactor/app-command-storage
EQUENOS ebdeb33
fix: prevent an unintended breaking change
EQUENOS 93880cf
refactor: `remove_app_command` now takes a single `guild_id`
EQUENOS 84eff42
refactor: use `@deprecated` for `add_xxx_command`
EQUENOS 009c849
Update disnake/ext/commands/interaction_bot_base.py
Snipy7374 72e4839
Update disnake/ext/commands/interaction_bot_base.py
Snipy7374 d6ea6ae
Update disnake/interactions/application_command.py
Snipy7374 e8cea43
move localize call outside loop
Snipy7374 40528ce
make guild_id kwarg only
Snipy7374 fd86765
update versionadded version
Snipy7374 4a6cd0e
add versionadded to AppCmdIndex
Snipy7374 a238f66
bump versionadded
Snipy7374 08decec
Merge branch 'master' into refactor/app-command-storage
Snipy7374 e26dcd2
bump versionadded
Snipy7374 0ef6837
add note about name and guild_ids attributes
Snipy7374 311e67e
Merge branch 'master' into refactor/app-command-storage
onerandomusername aa7fe6b
Merge remote-tracking branch 'real_disnake/master' into refactor/app-…
Snipy7374 8f08755
chore: undo broken docs annotation upgrades
shiftinv c9ac04c
chore: upgrade documentation annotations
shiftinv 96e7731
Merge remote-tracking branch 'upstream/master' into refactor/app-comm…
shiftinv be3ecea
lint: use pyright ignore instead of type ignore
shiftinv 0a6c107
fix(docs): use |vnext|
shiftinv 41ae57a
fix: updated deprecation decorators
shiftinv 80c9a89
docs: adjust `slash_command` `guild_ids` type hint to match
shiftinv db1af6b
fix: apply contexts/install_types defaults again
shiftinv 4d2058d
chore: misc grammar/phrasing fixes
shiftinv 2dfaa1e
fix: use `deprecated` decorator for `remove_*` methds
shiftinv 242bd3b
refactor: deduplicate `remove_app_command` + `_remove_app_commands`
shiftinv 5da2aba
fix: avoid partially adding commands to cache in case of ambiguity er…
shiftinv 18d50b0
feat: make `add_app_command` param positional-only
shiftinv 6eafade
refactor: extract common logic from `get_*_command`
shiftinv c154a3d
refactor: move `chat_input -> slash` special casing into property
shiftinv ad6cac7
docs: add versionadded to new `guild_id` parameters
shiftinv 92b1793
chore: opinionated style changes
shiftinv fd66261
Merge remote-tracking branch 'upstream/master' into refactor/app-comm…
shiftinv f0fc6b1
docs: merge changelog fragments
shiftinv bbde5d6
docs: remove module prefix
shiftinv 03bb1cd
Merge remote-tracking branch 'upstream/master' into refactor/app-comm…
shiftinv 35455ee
docs: add changelog fragment for `inter.data.guild_id`
shiftinv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| |commands| Allow registering 2 commands with the same type and name in different guilds. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| |commands| :attr:`.ext.commands.InteractionBot.all_slash_commands`, :attr:`.ext.commands.InteractionBot.all_user_commands`, :attr:`.ext.commands.InteractionBot.all_message_commands` are deprecated. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| |commands| :meth:`.ext.commands.InteractionBot.add_slash_command`, :meth:`.ext.commands.InteractionBot.add_user_command`, :meth:`.ext.commands.InteractionBot.add_message_command` are deprecated. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| |commands| :meth:`.ext.commands.InteractionBot.remove_slash_command`, :meth:`.ext.commands.InteractionBot.remove_user_command`, :meth:`.ext.commands.InteractionBot.remove_message_command` are deprecated. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| |commands| Add :meth:`.ext.commands.InteractionBot.add_app_command` and :meth:`.ext.commands.InteractionBot.remove_app_command`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| |commands| Add ``guild_id`` parameter to :meth:`.ext.commands.InteractionBot.get_slash_command`, :meth:`.ext.commands.InteractionBot.get_user_command`, and :meth:`.ext.commands.InteractionBot.get_message_command`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| |commands| Add :class:`.ext.commands.ApplicationCommandRegistrationError`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,7 +27,7 @@ | |
| from ._types import _BaseCommand | ||
| from .base_core import InvokableApplicationCommand | ||
| from .ctx_menus_core import InvokableMessageCommand, InvokableUserCommand | ||
| from .slash_core import InvokableSlashCommand | ||
| from .slash_core import InvokableSlashCommand, SubCommand, SubCommandGroup | ||
|
|
||
| if TYPE_CHECKING: | ||
| from typing_extensions import Self | ||
|
|
@@ -753,22 +753,16 @@ def _inject(self, bot: AnyBot) -> Self: | |
|
|
||
| for index, command in enumerate(self.__cog_app_commands__): | ||
| command.cog = self | ||
| if isinstance(command, (SubCommand, SubCommandGroup)): | ||
| continue | ||
| try: | ||
| if isinstance(command, InvokableSlashCommand): | ||
| bot.add_slash_command(command) | ||
| elif isinstance(command, InvokableUserCommand): | ||
| bot.add_user_command(command) | ||
| elif isinstance(command, InvokableMessageCommand): | ||
| bot.add_message_command(command) | ||
| bot.add_app_command(command) | ||
| except Exception: | ||
| # undo our additions | ||
| for to_undo in self.__cog_app_commands__[:index]: | ||
| if isinstance(to_undo, InvokableSlashCommand): | ||
| bot.remove_slash_command(to_undo.name) | ||
| elif isinstance(to_undo, InvokableUserCommand): | ||
| bot.remove_user_command(to_undo.name) | ||
| elif isinstance(to_undo, InvokableMessageCommand): | ||
| bot.remove_message_command(to_undo.name) | ||
| bot._remove_app_commands( | ||
| to_undo.body.type, to_undo.name, guild_ids=to_undo.guild_ids | ||
| ) | ||
| raise | ||
|
|
||
| if not hasattr(self.cog_load.__func__, "__cog_special_method__"): | ||
|
|
@@ -841,12 +835,9 @@ def _eject(self, bot: AnyBot) -> None: | |
| bot.remove_command(command.name) # type: ignore | ||
|
|
||
| for app_command in self.__cog_app_commands__: | ||
| if isinstance(app_command, InvokableSlashCommand): | ||
| bot.remove_slash_command(app_command.name) | ||
| elif isinstance(app_command, InvokableUserCommand): | ||
| bot.remove_user_command(app_command.name) | ||
| elif isinstance(app_command, InvokableMessageCommand): | ||
| bot.remove_message_command(app_command.name) | ||
| bot._remove_app_commands( | ||
| app_command.body.type, app_command.name, guild_ids=app_command.guild_ids | ||
| ) | ||
|
Comment on lines
835
to
+832
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't pose an issue right now, but may need to check for |
||
|
|
||
| for name, method_name in self.__cog_listeners__: | ||
| bot.remove_listener(getattr(self, method_name), name) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.