From a91fe5f8f6058abdb12eb8ebaf47ad860313bd17 Mon Sep 17 00:00:00 2001 From: Eli Gao Date: Tue, 20 Sep 2016 12:38:49 +0800 Subject: [PATCH] Properly split and handle arguments in CommandHandler (#414) * Properly split and handle arguments in CommandHandler * Update the docstring for pass_args in CommandHandler * Properly split and handle arguments in StringCommandHandler --- AUTHORS.rst | 1 + telegram/ext/commandhandler.py | 5 +++-- telegram/ext/stringcommandhandler.py | 5 +++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/AUTHORS.rst b/AUTHORS.rst index 30a887e38..9a28e6f4b 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -11,6 +11,7 @@ The following wonderful people contributed directly or indirectly to this projec - `Avanatiker `_ - `Balduro `_ - `bimmlerd `_ +- `Eli Gao `_ - `ErgoZ Riftbit Vaper `_ - `franciscod `_ - `Jacob Bom `_ diff --git a/telegram/ext/commandhandler.py b/telegram/ext/commandhandler.py index 345f1a050..1b1e1e74e 100644 --- a/telegram/ext/commandhandler.py +++ b/telegram/ext/commandhandler.py @@ -39,7 +39,8 @@ class CommandHandler(Handler): pass_args (optional[bool]): If the handler should be passed the arguments passed to the command as a keyword argument called ` ``args``. It will contain a list of strings, which is the text - following the command split on spaces. Default is ``False`` + following the command split on single or consecutive whitespace characters. + Default is ``False`` pass_update_queue (optional[bool]): If set to ``True``, a keyword argument called ``update_queue`` will be passed to the callback function. It will be the ``Queue`` instance used by the ``Updater`` and ``Dispatcher`` that contains new updates which can @@ -80,7 +81,7 @@ class CommandHandler(Handler): message = update.message or update.edited_message if self.pass_args: - optional_args['args'] = message.text.split(' ')[1:] + optional_args['args'] = message.text.split()[1:] return self.callback(dispatcher.bot, update, **optional_args) diff --git a/telegram/ext/stringcommandhandler.py b/telegram/ext/stringcommandhandler.py index 9c39cdd6d..eaf37055f 100644 --- a/telegram/ext/stringcommandhandler.py +++ b/telegram/ext/stringcommandhandler.py @@ -35,7 +35,8 @@ class StringCommandHandler(Handler): pass_args (optional[bool]): If the handler should be passed the arguments passed to the command as a keyword argument called ` ``args``. It will contain a list of strings, which is the text - following the command split on spaces. Default is ``False`` + following the command split on single or consecutive whitespace characters. + Default is ``False`` pass_update_queue (optional[bool]): If set to ``True``, a keyword argument called ``update_queue`` will be passed to the callback function. It will be the ``Queue`` instance used by the ``Updater`` and ``Dispatcher`` that contains new updates which can @@ -65,7 +66,7 @@ class StringCommandHandler(Handler): optional_args = self.collect_optional_args(dispatcher) if self.pass_args: - optional_args['args'] = update.split(' ')[1:] + optional_args['args'] = update.split()[1:] return self.callback(dispatcher.bot, update, **optional_args)