diff options
| author | 2021-08-30 22:09:44 -0400 | |
|---|---|---|
| committer | 2021-08-30 22:09:44 -0400 | |
| commit | 8bc54b2e2aeaeef30efd9f7f684cce48b7b64daf (patch) | |
| tree | 91e844d1431a127815d33406139e5798341b533a /bot/utils/checks.py | |
| parent | Numerous syntax and bug fixes (diff) | |
| parent | Merge pull request #831 from brad90four/patch-1 (diff) | |
Update branch with main
Diffstat (limited to 'bot/utils/checks.py')
| -rw-r--r-- | bot/utils/checks.py | 35 | 
1 files changed, 25 insertions, 10 deletions
diff --git a/bot/utils/checks.py b/bot/utils/checks.py index 9dd4dde0..438ec750 100644 --- a/bot/utils/checks.py +++ b/bot/utils/checks.py @@ -75,6 +75,11 @@ def in_whitelist_check(          log.trace(f"{ctx.author} may use the `{ctx.command.name}` command as they are in a whitelisted category.")          return True +    category = getattr(ctx.channel, "category", None) +    if category and category.name == constants.codejam_categories_name: +        log.trace(f"{ctx.author} may use the `{ctx.command.name}` command as they are in a codejam team channel.") +        return True +      # Only check the roles whitelist if we have one and ensure the author's roles attribute returns      # an iterable to prevent breakage in DM channels (for if we ever decide to enable commands there).      if roles and any(r.id in roles for r in getattr(ctx.author, "roles", ())): @@ -92,8 +97,10 @@ def in_whitelist_check(  def with_role_check(ctx: Context, *role_ids: int) -> bool:      """Returns True if the user has any one of the roles in role_ids."""      if not ctx.guild:  # Return False in a DM -        log.trace(f"{ctx.author} tried to use the '{ctx.command.name}'command from a DM. " -                  "This command is restricted by the with_role decorator. Rejecting request.") +        log.trace( +            f"{ctx.author} tried to use the '{ctx.command.name}'command from a DM. " +            "This command is restricted by the with_role decorator. Rejecting request." +        )          return False      for role in ctx.author.roles: @@ -101,22 +108,28 @@ def with_role_check(ctx: Context, *role_ids: int) -> bool:              log.trace(f"{ctx.author} has the '{role.name}' role, and passes the check.")              return True -    log.trace(f"{ctx.author} does not have the required role to use " -              f"the '{ctx.command.name}' command, so the request is rejected.") +    log.trace( +        f"{ctx.author} does not have the required role to use " +        f"the '{ctx.command.name}' command, so the request is rejected." +    )      return False  def without_role_check(ctx: Context, *role_ids: int) -> bool:      """Returns True if the user does not have any of the roles in role_ids."""      if not ctx.guild:  # Return False in a DM -        log.trace(f"{ctx.author} tried to use the '{ctx.command.name}' command from a DM. " -                  "This command is restricted by the without_role decorator. Rejecting request.") +        log.trace( +            f"{ctx.author} tried to use the '{ctx.command.name}' command from a DM. " +            "This command is restricted by the without_role decorator. Rejecting request." +        )          return False      author_roles = [role.id for role in ctx.author.roles]      check = all(role not in author_roles for role in role_ids) -    log.trace(f"{ctx.author} tried to call the '{ctx.command.name}' command. " -              f"The result of the without_role check was {check}.") +    log.trace( +        f"{ctx.author} tried to call the '{ctx.command.name}' command. " +        f"The result of the without_role check was {check}." +    )      return check @@ -154,8 +167,10 @@ def cooldown_with_role_bypass(rate: int, per: float, type: BucketType = BucketTy          #          # If the `before_invoke` detail is ever a problem then I can quickly just swap over.          if not isinstance(command, Command): -            raise TypeError('Decorator `cooldown_with_role_bypass` must be applied after the command decorator. ' -                            'This means it has to be above the command decorator in the code.') +            raise TypeError( +                "Decorator `cooldown_with_role_bypass` must be applied after the command decorator. " +                "This means it has to be above the command decorator in the code." +            )          command._before_invoke = predicate  |