Skip to content

Commit

Permalink
Revert "feat: move command sync config to flags"
Browse files Browse the repository at this point in the history
This reverts commit 237ac58.
  • Loading branch information
onerandomusername committed Oct 21, 2022
1 parent 7eda7e4 commit e824ed8
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 18 deletions.
1 change: 0 additions & 1 deletion disnake/ext/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from .custom_warnings import *
from .errors import *
from .flag_converter import *
from .flags import *
from .help import *
from .params import *
from .slash_core import *
5 changes: 0 additions & 5 deletions disnake/ext/commands/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ class Bot(BotBase, InteractionBotBase, disnake.Client):
.. versionadded:: 2.1
command_sync: :class:`ApplicationCommandSyncFlags`
The configuration for application command sync.
.. versionadded:: 2.6
sync_commands: :class:`bool`
Whether to enable automatic synchronization of application commands in your code.
Defaults to ``True``, which means that commands in API are automatically synced
Expand Down
4 changes: 2 additions & 2 deletions disnake/ext/commands/cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ def _inject(self, bot: AnyBot) -> Self:
bot.add_listener(getattr(self, method_name), name)

try:
if bot._command_sync.on_cog_unload:
if bot._sync_commands_on_cog_unload:
bot._schedule_delayed_command_sync()
except NotImplementedError:
pass
Expand Down Expand Up @@ -874,7 +874,7 @@ def _eject(self, bot: AnyBot) -> None:

finally:
try:
if bot._command_sync.on_cog_unload:
if bot._sync_commands_on_cog_unload:
bot._schedule_delayed_command_sync()
except NotImplementedError:
pass
Expand Down
20 changes: 10 additions & 10 deletions disnake/ext/commands/interaction_bot_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
user_command,
)
from .errors import CommandRegistrationError
from .flags import ApplicationCommandSyncFlags
from .slash_core import InvokableSlashCommand, SubCommand, SubCommandGroup, slash_command

if TYPE_CHECKING:
Expand Down Expand Up @@ -142,7 +141,9 @@ class InteractionBotBase(CommonBotBase):
def __init__(
self,
*,
command_sync: Optional[ApplicationCommandSyncFlags] = None,
sync_commands: bool = True,
sync_commands_debug: bool = False,
sync_commands_on_cog_unload: bool = True,
test_guilds: Optional[Sequence[int]] = None,
**options: Any,
):
Expand All @@ -153,11 +154,10 @@ def __init__(

test_guilds = None if test_guilds is None else tuple(test_guilds)
self._test_guilds: Optional[Tuple[int, ...]] = test_guilds
if command_sync is None:
command_sync = ApplicationCommandSyncFlags.default()

self._sync_commands: bool = sync_commands
self._sync_commands_debug: bool = sync_commands_debug
self._sync_commands_on_cog_unload = sync_commands_on_cog_unload
self._sync_queued: bool = False
self._command_sync = command_sync

self._slash_command_checks = []
self._slash_command_check_once = []
Expand Down Expand Up @@ -853,7 +853,7 @@ async def _sync_application_commands(self) -> None:
if not isinstance(self, disnake.Client):
raise NotImplementedError("This method is only usable in disnake.Client subclasses")

if not self._command_sync.sync_commands or self._is_closed or self.loop.is_closed():
if not self._sync_commands or self._is_closed or self.loop.is_closed():
return

# We assume that all commands are already cached.
Expand Down Expand Up @@ -921,7 +921,7 @@ async def _sync_application_commands(self) -> None:
self._log_sync_debug("Command synchronization task has finished")

def _log_sync_debug(self, text: str) -> None:
if self._command_sync.sync_commands_debug:
if self._sync_commands_debug:
# if sync debugging is enabled, *always* output logs
if _log.isEnabledFor(logging.INFO):
# if the log level is `INFO` or higher, use that
Expand Down Expand Up @@ -978,7 +978,7 @@ async def _delayed_command_sync(self) -> None:
raise NotImplementedError("This method is only usable in disnake.Client subclasses")

if (
not self._command_sync.sync_commands
not self._sync_commands
or self._sync_queued
or not self.is_ready()
or self._is_closed
Expand Down Expand Up @@ -1403,7 +1403,7 @@ async def process_application_commands(
interaction: :class:`disnake.ApplicationCommandInteraction`
The interaction to process commands for.
"""
if self._command_sync.sync_commands and not self._sync_queued:
if self._sync_commands and not self._sync_queued:
known_command = self.get_global_command(interaction.data.id) # type: ignore

if known_command is None:
Expand Down

0 comments on commit e824ed8

Please sign in to comment.