Skip to content

Commit

Permalink
Fix _human_only check to not allow webhooks and webhook_only check (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
davfsa committed Jan 3, 2021
1 parent a07fa58 commit fc51c8a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
22 changes: 21 additions & 1 deletion lightbulb/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"guild_only",
"owner_only",
"bot_only",
"webhook_only",
"human_only",
"has_roles",
"has_guild_permissions",
Expand Down Expand Up @@ -103,8 +104,14 @@ async def _bot_only(ctx: context.Context) -> bool:
return True


async def _webhook_only(ctx: context.Context) -> bool:
if not ctx.author.is_webhook:
raise errors.WebhookOnly(f"Only a webhook can use {ctx.invoked_with}")
return True


async def _human_only(ctx: context.Context) -> bool:
if ctx.author.is_bot:
if not ctx.author.is_human:
raise errors.HumanOnly(f"Only an human can use {ctx.invoked_with}")
return True

Expand Down Expand Up @@ -275,6 +282,19 @@ def decorate(command: T_inv) -> T_inv:
return decorate


def webhook_only() -> typing.Callable[[T_inv], T_inv]:
"""
A decorator that prevents a command from being used by anyone other than a webhook.
"""

def decorate(command: T_inv) -> T_inv:
_check_check_decorator_above_commands_decorator(command)
command.add_check(_webhook_only)
return command

return decorate


def human_only() -> typing.Callable[[T_inv], T_inv]:
"""
A decorator that prevents a command from being used by anyone other than a human.
Expand Down
10 changes: 10 additions & 0 deletions lightbulb/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,16 @@ def __init__(self, text: str) -> None:
"""The error text."""


class WebhookOnly(CheckFailure):
"""
Error raised when the command invoker is not a webhook.
"""

def __init__(self, text: str) -> None:
self.text: str = text
"""The error text."""


class HumanOnly(CheckFailure):
"""
Error raised when the command invoker is not an human.
Expand Down

0 comments on commit fc51c8a

Please sign in to comment.