mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-11-29 03:32:49 +01:00
CommandHandler - ignore strings in entities and "/" followed by whitespace (#1020)
This commit is contained in:
parent
f6332d45a8
commit
b67ea7a691
3 changed files with 18 additions and 15 deletions
|
@ -54,6 +54,7 @@ The following wonderful people contributed directly or indirectly to this projec
|
||||||
- `Oleg Sushchenko <https://github.com/feuillemorte>`_
|
- `Oleg Sushchenko <https://github.com/feuillemorte>`_
|
||||||
- `overquota <https://github.com/overquota>`_
|
- `overquota <https://github.com/overquota>`_
|
||||||
- `Patrick Hofmann <https://github.com/PH89>`_
|
- `Patrick Hofmann <https://github.com/PH89>`_
|
||||||
|
- `Paul Larsen <https://github.com/PaulSonOfLars>`_
|
||||||
- `Pieter Schutz <https://github.com/eldinnie>`_
|
- `Pieter Schutz <https://github.com/eldinnie>`_
|
||||||
- `Rahiel Kasim <https://github.com/rahiel>`_
|
- `Rahiel Kasim <https://github.com/rahiel>`_
|
||||||
- `Sascha <https://github.com/saschalalala>`_
|
- `Sascha <https://github.com/saschalalala>`_
|
||||||
|
|
|
@ -134,24 +134,23 @@ class CommandHandler(Handler):
|
||||||
message = update.message or update.edited_message
|
message = update.message or update.edited_message
|
||||||
|
|
||||||
if message.text and message.text.startswith('/') and len(message.text) > 1:
|
if message.text and message.text.startswith('/') and len(message.text) > 1:
|
||||||
command = message.text[1:].split(None, 1)[0].split('@')
|
first_word = message.text_html.split(None, 1)[0]
|
||||||
command.append(
|
if len(first_word) > 1 and first_word.startswith('/'):
|
||||||
message.bot.username) # in case the command was send without a username
|
command = first_word[1:].split('@')
|
||||||
|
command.append(
|
||||||
|
message.bot.username) # in case the command was sent without a username
|
||||||
|
|
||||||
if self.filters is None:
|
if self.filters is None:
|
||||||
res = True
|
res = True
|
||||||
elif isinstance(self.filters, list):
|
elif isinstance(self.filters, list):
|
||||||
res = any(func(message) for func in self.filters)
|
res = any(func(message) for func in self.filters)
|
||||||
else:
|
else:
|
||||||
res = self.filters(message)
|
res = self.filters(message)
|
||||||
|
|
||||||
return res and (command[0].lower() in self.command
|
return res and (command[0].lower() in self.command
|
||||||
and command[1].lower() == message.bot.username.lower())
|
and command[1].lower() == message.bot.username.lower())
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
|
||||||
else:
|
return False
|
||||||
return False
|
|
||||||
|
|
||||||
def handle_update(self, update, dispatcher):
|
def handle_update(self, update, dispatcher):
|
||||||
"""Send the update to the :attr:`callback`.
|
"""Send the update to the :attr:`callback`.
|
||||||
|
|
|
@ -190,6 +190,9 @@ class TestCommandHandler(object):
|
||||||
message.text = '/'
|
message.text = '/'
|
||||||
assert not handler.check_update(Update(0, message))
|
assert not handler.check_update(Update(0, message))
|
||||||
|
|
||||||
|
message.text = '/ test'
|
||||||
|
assert not handler.check_update(Update(0, message))
|
||||||
|
|
||||||
def test_pass_user_or_chat_data(self, dp, message):
|
def test_pass_user_or_chat_data(self, dp, message):
|
||||||
handler = CommandHandler('test', self.callback_data_1, pass_user_data=True)
|
handler = CommandHandler('test', self.callback_data_1, pass_user_data=True)
|
||||||
dp.add_handler(handler)
|
dp.add_handler(handler)
|
||||||
|
|
Loading…
Reference in a new issue