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
This commit is contained in:
Eli Gao 2016-09-20 12:38:49 +08:00 committed by Jannes Höke
parent 5116a77221
commit a91fe5f8f6
3 changed files with 7 additions and 4 deletions

View file

@ -11,6 +11,7 @@ The following wonderful people contributed directly or indirectly to this projec
- `Avanatiker <https://github.com/Avanatiker>`_ - `Avanatiker <https://github.com/Avanatiker>`_
- `Balduro <https://github.com/Balduro>`_ - `Balduro <https://github.com/Balduro>`_
- `bimmlerd <https://github.com/bimmlerd>`_ - `bimmlerd <https://github.com/bimmlerd>`_
- `Eli Gao <https://github.com/eligao>`_
- `ErgoZ Riftbit Vaper <https://github.com/ergoz>`_ - `ErgoZ Riftbit Vaper <https://github.com/ergoz>`_
- `franciscod <https://github.com/franciscod>`_ - `franciscod <https://github.com/franciscod>`_
- `Jacob Bom <https://github.com/bomjacob>`_ - `Jacob Bom <https://github.com/bomjacob>`_

View file

@ -39,7 +39,8 @@ class CommandHandler(Handler):
pass_args (optional[bool]): If the handler should be passed the pass_args (optional[bool]): If the handler should be passed the
arguments passed to the command as a keyword argument called ` arguments passed to the command as a keyword argument called `
``args``. It will contain a list of strings, which is the text ``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 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`` ``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 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 message = update.message or update.edited_message
if self.pass_args: 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) return self.callback(dispatcher.bot, update, **optional_args)

View file

@ -35,7 +35,8 @@ class StringCommandHandler(Handler):
pass_args (optional[bool]): If the handler should be passed the pass_args (optional[bool]): If the handler should be passed the
arguments passed to the command as a keyword argument called ` arguments passed to the command as a keyword argument called `
``args``. It will contain a list of strings, which is the text ``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 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`` ``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 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) optional_args = self.collect_optional_args(dispatcher)
if self.pass_args: if self.pass_args:
optional_args['args'] = update.split(' ')[1:] optional_args['args'] = update.split()[1:]
return self.callback(dispatcher.bot, update, **optional_args) return self.callback(dispatcher.bot, update, **optional_args)