From b79a4549abc2f98cd3c46177a6b8537c0fe0fb24 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Thu, 7 Jan 2016 17:31:56 -0500 Subject: [PATCH] [commands] Special handling for when the converter is bool. --- discord/ext/commands/core.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/discord/ext/commands/core.py b/discord/ext/commands/core.py index ef2a3b156..06c64b1bd 100644 --- a/discord/ext/commands/core.py +++ b/discord/ext/commands/core.py @@ -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)