[commands] Add max_concurrency decorator
This commit is contained in:
@ -41,6 +41,7 @@ __all__ = (
|
||||
'TooManyArguments',
|
||||
'UserInputError',
|
||||
'CommandOnCooldown',
|
||||
'MaxConcurrencyReached',
|
||||
'NotOwner',
|
||||
'MissingRole',
|
||||
'BotMissingRole',
|
||||
@ -240,6 +241,28 @@ class CommandOnCooldown(CommandError):
|
||||
self.retry_after = retry_after
|
||||
super().__init__('You are on cooldown. Try again in {:.2f}s'.format(retry_after))
|
||||
|
||||
class MaxConcurrencyReached(CommandError):
|
||||
"""Exception raised when the command being invoked has reached its maximum concurrency.
|
||||
|
||||
This inherits from :exc:`CommandError`.
|
||||
|
||||
Attributes
|
||||
------------
|
||||
number: :class:`int`
|
||||
The maximum number of concurrent invokers allowed.
|
||||
per: :class:`BucketType`
|
||||
The bucket type passed to the :func:`.max_concurrency` decorator.
|
||||
"""
|
||||
|
||||
def __init__(self, number, per):
|
||||
self.number = number
|
||||
self.per = per
|
||||
name = per.name
|
||||
suffix = 'per %s' % name if per.name != 'default' else 'globally'
|
||||
plural = '%s times %s' if number > 1 else '%s time %s'
|
||||
fmt = plural % (number, suffix)
|
||||
super().__init__('Too many people using this command. It can only be used {}.'.format(fmt))
|
||||
|
||||
class MissingRole(CheckFailure):
|
||||
"""Exception raised when the command invoker lacks a role to run a command.
|
||||
|
||||
|
Reference in New Issue
Block a user