[commands] Add is_owner check and Bot.is_owner.

This commit is contained in:
Rapptz
2017-03-27 06:55:21 -04:00
parent afb64fb5e3
commit 5c5e7ae1d6
3 changed files with 49 additions and 2 deletions

View File

@@ -37,7 +37,7 @@ from . import converter as converters
__all__ = [ 'Command', 'Group', 'GroupMixin', 'command', 'group',
'has_role', 'has_permissions', 'has_any_role', 'check',
'bot_has_role', 'bot_has_permissions', 'bot_has_any_role',
'cooldown', 'guild_only', ]
'cooldown', 'guild_only', 'is_owner']
def wrap_callback(coro):
@functools.wraps(coro)
@@ -1104,6 +1104,24 @@ def guild_only():
return check(predicate)
def is_owner():
"""A :func:`check` that checks if the person invoking this command is the
owner of the bot.
This is powered by :meth:`Bot.is_owner`.
This check raises a special exception, :exc:`NotOwner` that is derived
from :exc:`CheckFailure`.
"""
@asyncio.coroutine
def predicate(ctx):
if not (yield from ctx.bot.is_owner(ctx.author)):
raise NotOwner('You do not own this bot.')
return True
return check(predicate)
def cooldown(rate, per, type=BucketType.default):
"""A decorator that adds a cooldown to a :class:`Command`
or its subclasses.