Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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>`_
Expand Down
35 changes: 17 additions & 18 deletions telegram/ext/commandhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,24 +134,23 @@ def check_update(self, update):
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

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

else:
return False
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)

return res and (command[0].lower() in self.command
and command[1].lower() == message.bot.username.lower())

return False

def handle_update(self, update, dispatcher):
"""Send the update to the :attr:`callback`.
Expand Down
3 changes: 3 additions & 0 deletions tests/test_commandhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ def test_single_slash(self, dp, message):
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)
Expand Down