mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-07 11:48:55 -05:00
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:
parent
0d4e6a0865
commit
849ade6e58
@ -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):
|
||||||
|
|||||||
@ -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"]]]:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user