From 849ade6e585572f4dd7c9a8210fa98df32d461f9 Mon Sep 17 00:00:00 2001 From: Michael H Date: Thu, 17 Jan 2019 22:45:34 -0500 Subject: [PATCH] Reconcile permission hooks with ctx.permission_state (#2375) Resolves #2374. See mod.py's voice mute for an example of why this may be necessary. --- redbot/core/bot.py | 7 ++++++- redbot/core/commands/requires.py | 11 +++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/redbot/core/bot.py b/redbot/core/bot.py index e0778f53c..4f5de7bee 100644 --- a/redbot/core/bot.py +++ b/redbot/core/bot.py @@ -500,7 +500,12 @@ class RedBase(commands.GroupMixin, commands.bot.BotBase, RPCMixin): if result is not None: hook_results.append(result) if hook_results: - return all(hook_results) + if all(hook_results): + ctx.permission_state = commands.PermState.ALLOWED_BY_HOOK + return True + else: + ctx.permission_state = commands.PermState.DENIED_BY_HOOK + return False class Red(RedBase, discord.AutoShardedClient): diff --git a/redbot/core/commands/requires.py b/redbot/core/commands/requires.py index 2b98d69c7..7c546b4e8 100644 --- a/redbot/core/commands/requires.py +++ b/redbot/core/commands/requires.py @@ -168,6 +168,17 @@ class PermState(enum.Enum): chain. """ + # The below are valid states, but should not be transitioned to + # They should be set if they apply. + + ALLOWED_BY_HOOK = enum.auto() + """This command has been actively allowed by a permission hook. + check validation doesn't need this, but is useful to developers""" + + DENIED_BY_HOOK = enum.auto() + """This command has been actively denied by a permission hook + check validation doesn't need this, but is useful to developers""" + def transition_to( self, next_state: "PermState" ) -> Tuple[Optional[bool], Union["PermState", Dict[bool, "PermState"]]]: