Skip to content

CommandHandler - ignore strings in entities and "/" followed by whitespace #1020

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 1, 2018
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
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