diff --git a/AUTHORS.rst b/AUTHORS.rst index 9282f2b1f78..2c30ad999b3 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -54,6 +54,7 @@ The following wonderful people contributed directly or indirectly to this projec - `Oleg Sushchenko `_ - `overquota `_ - `Patrick Hofmann `_ +- `Paul Larsen `_ - `Pieter Schutz `_ - `Rahiel Kasim `_ - `Sascha `_ diff --git a/telegram/ext/commandhandler.py b/telegram/ext/commandhandler.py index 2f681cf99d7..3fffa557fdf 100644 --- a/telegram/ext/commandhandler.py +++ b/telegram/ext/commandhandler.py @@ -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`. diff --git a/tests/test_commandhandler.py b/tests/test_commandhandler.py index 8b41acc26f4..a8140cb6b20 100644 --- a/tests/test_commandhandler.py +++ b/tests/test_commandhandler.py @@ -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) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy