-
Notifications
You must be signed in to change notification settings - Fork 139
feat: new command sync options #806
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
Merged
Merged
Changes from 37 commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
12c2a70
feat: implement new command sync behavior
onerandomusername fc36d51
docs: update the documentation on command sync
onerandomusername 6359147
chore: enable codemodding on new flags file
onerandomusername ca970cf
chore: add property for command sync
onerandomusername 311dcfd
chore: copy command sync before setting it
onerandomusername de8b449
docs: fix references to ApplicationCommandSyncFlags
onerandomusername 07535d3
fix: don't delete guild commands if delete is disabled
onerandomusername 4199ab1
docs: better explain lazy command sync for guild commands
onerandomusername 1ac09ea
chore: update debug diff shown when commands are not deleted
onerandomusername 40720b4
fix: check for the key in the diff
onerandomusername 9d5c268
chore: remove unused flag value
onerandomusername 0ba7728
docs: update default value
onerandomusername e8554dc
docs: add preliminary changelogs
onerandomusername 9511e55
fix: actually allow syncing just global or guild commands
onerandomusername e25f9c4
docs: add other changelogs
onerandomusername 9a6d775
docs: add missing command_sync documentation
onerandomusername 34095b5
fix: correct comments
onerandomusername 334b191
docs: varients -> variants
onerandomusername b6df491
fix: remove unused class
onerandomusername 4fd2b7f
fix: copy to delete_ignored
onerandomusername e931725
Merge branch 'master' into feat/command-sync
onerandomusername 90909cc
chore: rename ApplicationCommandSyncFlags to CommandSyncFlags
onerandomusername 16cf03f
remove unused import
onerandomusername f699422
docs: add |commands| prefix to changelog
onerandomusername c7dfaea
docs: address all doc comments
onerandomusername 003da6c
chore: rename command_sync to command_sync_flags
onerandomusername 3924c95
chore: change deprecations to not explicity state v2.8
onerandomusername 04639b9
clean up sync
onerandomusername 18de61d
chore: clean up the flag code
onerandomusername 8884f97
rename on_cog_unload to sync_on_cog_unload
onerandomusername 981057f
readd sync_commands and others to overloads
onerandomusername 43161f2
remove duplicated section
onerandomusername 4433b16
add suggestion documentation changes
onerandomusername c69ada2
chore: rename command_sync to command_sync_flags
onerandomusername 856efd2
consistency
onerandomusername 7667389
expand on sync_commands shortcut
onerandomusername fbf1df9
nit: fix typo
shiftinv 740aecd
fix: actually send the delete_ignored commands instead of deleting them
onerandomusername 9030d09
chore: rename sync_on_cog_unload to sync_on_cog_actions
onerandomusername 8d102dc
doc: update allow_command_deletion to explain how renames work
onerandomusername 4d3c7e4
fix: require sync guild commands to be enabled as well
onerandomusername bd6e394
refactor interaction handling
onerandomusername 5b1326f
fix: catch interaction timed out errors
onerandomusername 2baf2b7
refactor: clean up unknown command handling
shiftinv 5a063e5
Merge branch 'master' into feat/command-sync
onerandomusername 7f54110
nit: add dot
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
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| Add :class:`~disnake.ext.commands.CommandSyncFlags` to provide sync configuration to :class:`~disnake.ext.commands.Bot` and :class:`~disnake.ext.commands.InteractionBot` (and their autosharded variants) as ``command_sync_flags``. |
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:`~disnake.ext.commands.CommandSyncFlags` to provide sync configuration to :class:`~disnake.ext.commands.Bot` and :class:`~disnake.ext.commands.InteractionBot` (and their autosharded variants) as ``command_sync_flags``. |
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:`~disnake.ext.commands.CommandSyncFlags` to provide sync configuration to :class:`~disnake.ext.commands.Bot` and :class:`~disnake.ext.commands.InteractionBot` (and their autosharded variants) as ``command_sync_flags``. |
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| Deprecate the ``sync_commands``, ``sync_commands_debug``, and ``sync_commands_on_cog_unload`` parameters of :class:`~disnake.ext.commands.Bot` and :class:`~disnake.ext.commands.InteractionBot`. These have been replaced with the ``command_sync_flags`` parameter which takes a :class:`~disnake.ext.commands.CommandSyncFlags` instance. |
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:`~disnake.ext.commands.CommandSyncFlags` to provide sync configuration to :class:`~disnake.ext.commands.Bot` and :class:`~disnake.ext.commands.InteractionBot` (and their autosharded variants) as ``command_sync_flags``. |
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
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 |
---|---|---|
@@ -0,0 +1,179 @@ | ||
# SPDX-License-Identifier: MIT | ||
|
||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING, NoReturn, overload | ||
|
||
from disnake.flags import BaseFlags, alias_flag_value, all_flags_value, flag_value | ||
from disnake.utils import _generated | ||
|
||
if TYPE_CHECKING: | ||
from typing_extensions import Self | ||
|
||
__all__ = ("CommandSyncFlags",) | ||
|
||
|
||
class CommandSyncFlags(BaseFlags): | ||
"""Controls the library's application command syncing policy. | ||
|
||
This allows for finer grained control over what commands are synced automatically and in what cases. | ||
|
||
To construct an object you can pass keyword arguments denoting the flags | ||
to enable or disable. | ||
|
||
If command sync is disabled (see the docs of :attr:`sync_commands` for more info), other options will have no effect. | ||
|
||
.. versionadded:: 2.7 | ||
|
||
.. container:: operations | ||
|
||
.. describe:: x == y | ||
|
||
Checks if two CommandSyncFlags instances are equal. | ||
.. describe:: x != y | ||
|
||
Checks if two CommandSyncFlags instances are not equal. | ||
.. describe:: x <= y | ||
|
||
Checks if an CommandSyncFlags instance is a subset of another CommandSyncFlags instance. | ||
.. describe:: x >= y | ||
|
||
Checks if an CommandSyncFlags instance is a superset of another CommandSyncFlags instance. | ||
.. describe:: x < y | ||
|
||
Checks if an CommandSyncFlags instance is a strict subset of another CommandSyncFlags instance. | ||
.. describe:: x > y | ||
|
||
Checks if an CommandSyncFlags instance is a strict superset of another CommandSyncFlags instance. | ||
.. describe:: x | y, x |= y | ||
|
||
Returns a new CommandSyncFlags instance with all enabled flags from both x and y. | ||
(Using ``|=`` will update in place). | ||
.. describe:: x & y, x &= y | ||
|
||
Returns a new CommandSyncFlags instance with only flags enabled on both x and y. | ||
(Using ``&=`` will update in place). | ||
.. describe:: x ^ y, x ^= y | ||
|
||
Returns a new CommandSyncFlags instance with only flags enabled on one of x or y, but not both. | ||
(Using ``^=`` will update in place). | ||
.. describe:: ~x | ||
|
||
Returns a new CommandSyncFlags instance with all flags from x inverted. | ||
.. describe:: hash(x) | ||
|
||
Return the flag's hash. | ||
.. describe:: iter(x) | ||
|
||
Returns an iterator of ``(name, value)`` pairs. This allows it | ||
to be, for example, constructed as a dict or a list of pairs. | ||
Note that aliases are not shown. | ||
|
||
|
||
Additionally supported are a few operations on class attributes. | ||
|
||
.. describe:: CommandSyncFlags.y | CommandSyncFlags.z, CommandSyncFlags(y=True) | CommandSyncFlags.z | ||
|
||
Returns a CommandSyncFlags instance with all provided flags enabled. | ||
|
||
.. describe:: ~CommandSyncFlags.y | ||
|
||
Returns a CommandSyncFlags instance with all flags except ``y`` inverted from their default value. | ||
|
||
Attributes | ||
---------- | ||
value: :class:`int` | ||
The raw value. You should query flags via the properties | ||
rather than using this raw value. | ||
""" | ||
|
||
__slots__ = () | ||
|
||
@overload | ||
@_generated | ||
def __init__( | ||
self, | ||
*, | ||
allow_command_deletion: bool = ..., | ||
sync_commands: bool = ..., | ||
sync_commands_debug: bool = ..., | ||
sync_global_commands: bool = ..., | ||
sync_guild_commands: bool = ..., | ||
sync_on_cog_unload: bool = ..., | ||
): | ||
... | ||
|
||
@overload | ||
@_generated | ||
def __init__(self: NoReturn): | ||
... | ||
|
||
def __init__(self, **kwargs: bool): | ||
self.value = all_flags_value(self.VALID_FLAGS) | ||
for key, value in kwargs.items(): | ||
if key not in self.VALID_FLAGS: | ||
raise TypeError(f"{key!r} is not a valid flag name.") | ||
setattr(self, key, value) | ||
|
||
@classmethod | ||
def all(cls) -> Self: | ||
"""A factory method that creates a :class:`CommandSyncFlags` with everything enabled.""" | ||
self = cls.__new__(cls) | ||
self.value = all_flags_value(cls.VALID_FLAGS) | ||
return self | ||
|
||
@classmethod | ||
def none(cls) -> Self: | ||
"""A factory method that creates a :class:`CommandSyncFlags` with everything disabled.""" | ||
self = cls.__new__(cls) | ||
self.value = self.DEFAULT_VALUE | ||
return self | ||
|
||
@classmethod | ||
def default(cls) -> Self: | ||
"""A factory method that creates a :class:`CommandSyncFlags` with the default settings. | ||
|
||
The default is all flags enabled except for :attr:`sync_commands_debug`. | ||
""" | ||
self = cls.all() | ||
self.sync_commands_debug = False | ||
return self | ||
|
||
@property | ||
def _sync_enabled(self): | ||
return self.sync_global_commands or self.sync_guild_commands | ||
|
||
@alias_flag_value | ||
def sync_commands(self): | ||
""":class:`bool`: Whether to sync global and guild app commands. | ||
|
||
This controls the :attr:`sync_global_commands` and :attr:`sync_guild_commands` attributes. | ||
|
||
Note that it is possible for sync to be enabled for guild *or* global commands yet this will return ``False``. | ||
""" | ||
return 1 << 3 | 1 << 4 | ||
|
||
@flag_value | ||
def sync_commands_debug(self): | ||
""":class:`bool`: Whether or not to show app command sync debug messages.""" | ||
return 1 << 0 | ||
|
||
@flag_value | ||
def sync_on_cog_unload(self): | ||
""":class:`bool`: Whether or not to sync app commands on cog unload or reload.""" | ||
onerandomusername marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return 1 << 1 | ||
|
||
@flag_value | ||
def allow_command_deletion(self): | ||
""":class:`bool`: Whether to allow commands to be deleted by automatic command sync.""" | ||
onerandomusername marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return 1 << 2 | ||
|
||
@flag_value | ||
def sync_global_commands(self): | ||
""":class:`bool`: Whether to sync global commands.""" | ||
return 1 << 3 | ||
|
||
@flag_value | ||
def sync_guild_commands(self): | ||
""":class:`bool`: Whether to sync per-guild commands.""" | ||
return 1 << 4 |
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.