mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-03-26 16:38:53 +01:00
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:
parent
5116a77221
commit
a91fe5f8f6
3 changed files with 7 additions and 4 deletions
|
@ -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>`_
|
||||||
|
|
|
@ -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)
|
||||||
|
|
||||||
|
|
|
@ -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)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue