mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-05-12 08:49:48 +00:00
[commands] Special handling for when the converter is bool.
This commit is contained in:
parent
542ddc4938
commit
b79a4549ab
@ -36,6 +36,15 @@ from .view import quoted_word
|
||||
__all__ = [ 'Command', 'Group', 'GroupMixin', 'command', 'group',
|
||||
'has_role', 'has_permissions', 'has_any_role', 'check' ]
|
||||
|
||||
def _convert_to_bool(argument):
|
||||
lowered = argument.lower()
|
||||
if lowered in ('yes', 'y', 'true', 't', '1', 'enable', 'on'):
|
||||
return True
|
||||
elif lowered in ('no', 'n', 'false', 'f', '0', 'disable', 'off'):
|
||||
return False
|
||||
else:
|
||||
raise BadArgument(lowered + ' is not a recognised boolean option')
|
||||
|
||||
class Command:
|
||||
"""A class that implements the protocol for a bot text command.
|
||||
|
||||
@ -90,6 +99,9 @@ class Command:
|
||||
return result
|
||||
|
||||
def do_conversion(self, bot, message, converter, argument):
|
||||
if converter is bool:
|
||||
return _convert_to_bool(argument)
|
||||
|
||||
if converter.__module__.split('.')[0] != 'discord':
|
||||
return converter(argument)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user