diff options
Diffstat (limited to '')
| -rw-r--r-- | bot/decorators.py | 55 | 
1 files changed, 34 insertions, 21 deletions
diff --git a/bot/decorators.py b/bot/decorators.py index f556660e..02cf4b8a 100644 --- a/bot/decorators.py +++ b/bot/decorators.py @@ -24,8 +24,10 @@ def with_role(*role_ids: int):      """Check to see whether the invoking user has any of the roles specified in role_ids."""      async def predicate(ctx: Context):          if not ctx.guild:  # Return False in a DM -            log.debug(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.debug( +                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: @@ -33,8 +35,10 @@ def with_role(*role_ids: int):                  log.debug(f"{ctx.author} has the '{role.name}' role, and passes the check.")                  return True -        log.debug(f"{ctx.author} does not have the required role to use " -                  f"the '{ctx.command.name}' command, so the request is rejected.") +        log.debug( +            f"{ctx.author} does not have the required role to use " +            f"the '{ctx.command.name}' command, so the request is rejected." +        )          return False      return commands.check(predicate) @@ -43,14 +47,18 @@ def without_role(*role_ids: int):      """Check whether the invoking user does not have all of the roles specified in role_ids."""      async def predicate(ctx: Context):          if not ctx.guild:  # Return False in a DM -            log.debug(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.debug( +                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.debug(f"{ctx.author} tried to call the '{ctx.command.name}' command. " -                  f"The result of the without_role check was {check}.") +        log.debug( +            f"{ctx.author} tried to call the '{ctx.command.name}' command. " +            f"The result of the without_role check was {check}." +        )          return check      return commands.check(predicate) @@ -63,25 +71,30 @@ def in_channel_check(*channels: int, bypass_roles: typing.Container[int] = None)              return True          if ctx.channel.id in channels: -            log.debug(f"{ctx.author} tried to call the '{ctx.command.name}' command. " -                      f"The command was used in a whitelisted channel.") +            log.debug( +                f"{ctx.author} tried to call the '{ctx.command.name}' command " +                f"and the command was used in a whitelisted channel." +            )              return True          if hasattr(ctx.command.callback, "in_channel_override"): -            log.debug(f"{ctx.author} tried to call the '{ctx.command.name}' command. " -                      f"The command was not used in a whitelisted channel, " -                      f"but the command was whitelisted to bypass the in_channel check.") +            log.debug( +                f"{ctx.author} called the '{ctx.command.name}' command " +                f"and the command was whitelisted to bypass the in_channel check." +            )              return True -        if bypass_roles: -            if any(r.id in bypass_roles for r in ctx.author.roles): -                log.debug(f"{ctx.author} tried to call the '{ctx.command.name}' command. " -                          f"The command was not used in a whitelisted channel, " -                          f"but the author had a role to bypass the in_channel check.") -                return True +        if bypass_roles and any(r.id in bypass_roles for r in ctx.author.roles): +            log.debug( +                f"{ctx.author} called the '{ctx.command.name}' command and " +                f"had a role to bypass the in_channel check." +            ) +            return True -        log.debug(f"{ctx.author} tried to call the '{ctx.command.name}' command. " -                  f"The in_channel check failed.") +        log.debug( +            f"{ctx.author} tried to call the '{ctx.command.name}' command. " +            f"The in_channel check failed." +        )          channels_str = ', '.join(f"<#{c_id}>" for c_id in channels)          raise InChannelCheckFailure(  |