diff options
| author | 2022-09-18 22:06:55 +0100 | |
|---|---|---|
| committer | 2022-09-18 22:06:55 +0100 | |
| commit | 240d58e79343ce31becb21bcc58d88c72b245809 (patch) | |
| tree | 8062d0c064c9ee27f513693c1ef49f577c115b64 /bot/utils | |
| parent | Merge pull request #1096 from python-discord/fix-issue-1090 (diff) | |
| parent | Merge branch 'main' into fix-whitelist-inheritance (diff) | |
Merge pull request #981 from onerandomusername/fix-whitelist-inheritance
fix: subcommands inherit their parent's whitelist
Diffstat (limited to 'bot/utils')
| -rw-r--r-- | bot/utils/decorators.py | 27 | 
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): | 
