[commands] Add the concept of global checks.

Global checks are checks that are executed before regular per-command
checks except done to every command that the bot has registered. This
allows you to have checks that apply to every command without having to
override `on_message` or appending the check to every single command.
This commit is contained in:
Rapptz
2016-06-19 22:06:09 -04:00
parent 6f173cc095
commit adbf2c720f
2 changed files with 91 additions and 3 deletions

View File

@@ -395,8 +395,11 @@ class Command:
if self.no_pm and ctx.message.channel.is_private:
raise NoPrivateMessage('This command cannot be used in private messages.')
if not ctx.bot.can_run(ctx):
raise CheckFailure('The global check functions for command {0.qualified_name} failed.'.format(self))
if not self.can_run(ctx):
raise CheckFailure('The check functions for command {0.name} failed.'.format(self))
raise CheckFailure('The check functions for command {0.qualified_name} failed.'.format(self))
@asyncio.coroutine
def invoke(self, ctx):