aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2016-01-07 17:31:56 -0500
committerRapptz <[email protected]>2016-01-07 17:31:56 -0500
commitb79a4549abc2f98cd3c46177a6b8537c0fe0fb24 (patch)
tree4a6b3fefea1db7a047e52d2a62fa1cacf5b15fc9
parent[commands] Allow registration of multiple command prefixes. (diff)
downloaddiscord.py-b79a4549abc2f98cd3c46177a6b8537c0fe0fb24.tar.xz
discord.py-b79a4549abc2f98cd3c46177a6b8537c0fe0fb24.zip
[commands] Special handling for when the converter is bool.
-rw-r--r--discord/ext/commands/core.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/discord/ext/commands/core.py b/discord/ext/commands/core.py
index ef2a3b15..06c64b1b 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)