aboutsummaryrefslogtreecommitdiffstats
path: root/bot/utils/decorators.py
diff options
context:
space:
mode:
authorGravatar Xithrius <[email protected]>2022-11-02 02:07:29 -0700
committerGravatar GitHub <[email protected]>2022-11-02 02:07:29 -0700
commit43a2acf5ee4eb354ce3dfaeef9504eee9b9b46b4 (patch)
treecbdfeb08f8d582aa98acec6a529f0fa3dcd7933c /bot/utils/decorators.py
parentAppeased the formatter (diff)
parentMerge pull request #1137 from DivyanshuBist/bug-issue1122-message-of-type-None (diff)
Merge branch 'main' into main
Diffstat (limited to 'bot/utils/decorators.py')
-rw-r--r--bot/utils/decorators.py27
1 files changed, 21 insertions, 6 deletions
diff --git a/bot/utils/decorators.py b/bot/utils/decorators.py
index 8954e016..442eb841 100644
--- a/bot/utils/decorators.py
+++ b/bot/utils/decorators.py
@@ -199,13 +199,28 @@ def whitelist_check(**default_kwargs: Container[int]) -> Callable[[Context], boo
kwargs = default_kwargs.copy()
allow_dms = False
- # Update kwargs based on override
- if hasattr(ctx.command.callback, "override"):
+ # Determine which command's overrides we will use. Group commands will
+ # inherit from their parents if they don't define their own overrides
+ overridden_command: Optional[commands.Command] = None
+ for command in [ctx.command, *ctx.command.parents]:
+ if hasattr(command.callback, "override"):
+ overridden_command = command
+ break
+ if overridden_command is not None:
+ log.debug(f'Command {overridden_command} has overrides')
+ if overridden_command is not ctx.command:
+ log.debug(
+ f"Command '{ctx.command.qualified_name}' inherited overrides "
+ "from parent command '{overridden_command.qualified_name}'"
+ )
+
+ # Update kwargs based on override, if one exists
+ if overridden_command:
# Handle DM invocations
- allow_dms = ctx.command.callback.override_dm
+ allow_dms = overridden_command.callback.override_dm
# Remove default kwargs if reset is True
- if ctx.command.callback.override_reset:
+ if overridden_command.callback.override_reset:
kwargs = {}
log.debug(
f"{ctx.author} called the '{ctx.command.name}' command and "
@@ -213,9 +228,9 @@ def whitelist_check(**default_kwargs: Container[int]) -> Callable[[Context], boo
)
# Merge overwrites and defaults
- for arg in ctx.command.callback.override:
+ for arg in overridden_command.callback.override:
default_value = kwargs.get(arg)
- new_value = ctx.command.callback.override[arg]
+ new_value = overridden_command.callback.override[arg]
# Skip values that don't need merging, or can't be merged
if default_value is None or isinstance(arg, int):