mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-11-21 22:56:38 +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>`_
|
||||
- `overquota <https://github.com/overquota>`_
|
||||
- `Patrick Hofmann <https://github.com/PH89>`_
|
||||
- `Paul Larsen <https://github.com/PaulSonOfLars>`_
|
||||
- `Pieter Schutz <https://github.com/eldinnie>`_
|
||||
- `Rahiel Kasim <https://github.com/rahiel>`_
|
||||
- `Sascha <https://github.com/saschalalala>`_
|
||||
|
|
|
@ -134,24 +134,23 @@ class CommandHandler(Handler):
|
|||
message = update.message or update.edited_message
|
||||
|
||||
if message.text and message.text.startswith('/') and len(message.text) > 1:
|
||||
command = message.text[1:].split(None, 1)[0].split('@')
|
||||
command.append(
|
||||
message.bot.username) # in case the command was send without a username
|
||||
first_word = message.text_html.split(None, 1)[0]
|
||||
if len(first_word) > 1 and first_word.startswith('/'):
|
||||
command = first_word[1:].split('@')
|
||||
command.append(
|
||||
message.bot.username) # in case the command was sent without a username
|
||||
|
||||
if self.filters is None:
|
||||
res = True
|
||||
elif isinstance(self.filters, list):
|
||||
res = any(func(message) for func in self.filters)
|
||||
else:
|
||||
res = self.filters(message)
|
||||
if self.filters is None:
|
||||
res = True
|
||||
elif isinstance(self.filters, list):
|
||||
res = any(func(message) for func in self.filters)
|
||||
else:
|
||||
res = self.filters(message)
|
||||
|
||||
return res and (command[0].lower() in self.command
|
||||
and command[1].lower() == message.bot.username.lower())
|
||||
else:
|
||||
return False
|
||||
return res and (command[0].lower() in self.command
|
||||
and command[1].lower() == message.bot.username.lower())
|
||||
|
||||
else:
|
||||
return False
|
||||
return False
|
||||
|
||||
def handle_update(self, update, dispatcher):
|
||||
"""Send the update to the :attr:`callback`.
|
||||
|
|
|
@ -190,6 +190,9 @@ class TestCommandHandler(object):
|
|||
message.text = '/'
|
||||
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):
|
||||
handler = CommandHandler('test', self.callback_data_1, pass_user_data=True)
|
||||
dp.add_handler(handler)
|
||||
|
|
Loading…
Reference in a new issue