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.
This commit is contained in:
Michael H 2019-01-17 22:45:34 -05:00 committed by Toby Harradine
parent 0d4e6a0865
commit 849ade6e58
2 changed files with 17 additions and 1 deletions

View File

@ -500,7 +500,12 @@ class RedBase(commands.GroupMixin, commands.bot.BotBase, RPCMixin):
if result is not None: if result is not None:
hook_results.append(result) hook_results.append(result)
if hook_results: 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): class Red(RedBase, discord.AutoShardedClient):

View File

@ -168,6 +168,17 @@ class PermState(enum.Enum):
chain. 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( def transition_to(
self, next_state: "PermState" self, next_state: "PermState"
) -> Tuple[Optional[bool], Union["PermState", Dict[bool, "PermState"]]]: ) -> Tuple[Optional[bool], Union["PermState", Dict[bool, "PermState"]]]: