diff options
| author | 2020-05-27 07:51:20 +0200 | |
|---|---|---|
| committer | 2020-05-27 07:51:20 +0200 | |
| commit | c3cbc842dce1c26f09d774b7ca85eff613765480 (patch) | |
| tree | 7c5ea65b2cc79e1f77a633cfc5958779e3a4b068 | |
| parent | No redirect for mod management. (diff) | |
Allow some commands to fail checks silently.
For example, we don't want the mod commands to produce any kind of error
message when run by ordinary users in regular channels - these should
have the perception of being invisible and unavailable.
Diffstat (limited to '')
| -rw-r--r-- | bot/cogs/moderation/management.py | 1 | ||||
| -rw-r--r-- | bot/decorators.py | 3 | ||||
| -rw-r--r-- | bot/utils/checks.py | 7 | 
3 files changed, 9 insertions, 2 deletions
| diff --git a/bot/cogs/moderation/management.py b/bot/cogs/moderation/management.py index c7c19e89d..c39c7f3bc 100644 --- a/bot/cogs/moderation/management.py +++ b/bot/cogs/moderation/management.py @@ -291,6 +291,7 @@ class ModManagement(commands.Cog):                  channels=constants.MODERATION_CHANNELS,                  categories=[constants.Categories.modmail],                  redirect=None, +                fail_silently=True,              )          ]          return all(checks) diff --git a/bot/decorators.py b/bot/decorators.py index 1e77afe60..500197c89 100644 --- a/bot/decorators.py +++ b/bot/decorators.py @@ -23,6 +23,7 @@ def in_whitelist(      categories: Container[int] = (),      roles: Container[int] = (),      redirect: Optional[int] = Channels.bot_commands, +    fail_silently: bool = False,  ) -> Callable:      """      Check if a command was issued in a whitelisted context. @@ -39,7 +40,7 @@ def in_whitelist(      """      def predicate(ctx: Context) -> bool:          """Check if command was issued in a whitelisted context.""" -        return in_whitelist_check(ctx, channels, categories, roles, redirect) +        return in_whitelist_check(ctx, channels, categories, roles, redirect, fail_silently)      return commands.check(predicate) diff --git a/bot/utils/checks.py b/bot/utils/checks.py index 63568b29e..d5ebe4ec9 100644 --- a/bot/utils/checks.py +++ b/bot/utils/checks.py @@ -40,6 +40,7 @@ def in_whitelist_check(      categories: Container[int] = (),      roles: Container[int] = (),      redirect: Optional[int] = constants.Channels.bot_commands, +    fail_silently: bool = False,  ) -> bool:      """      Check if a command was issued in a whitelisted context. @@ -81,7 +82,11 @@ def in_whitelist_check(          return True      log.trace(f"{ctx.author} may not use the `{ctx.command.name}` command within this context.") -    raise InWhitelistCheckFailure(redirect) + +    # Some commands are secret, and should produce no feedback at all. +    if not fail_silently: +        raise InWhitelistCheckFailure(redirect) +    return False  def with_role_check(ctx: Context, *role_ids: int) -> bool: | 
