-
Notifications
You must be signed in to change notification settings - Fork 139
refactor: store invokable application commands properly #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
35
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 all commits
Commits
Show all changes
35 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 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
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
837
to
+840
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.