Skip to content

Commit

Permalink
Fix Filters.regex failing on non-text message (#1158)
Browse files Browse the repository at this point in the history
* Fix #1115

* Improve regex filter test
  • Loading branch information
Dmitry Grigoryev authored and jsmnbom committed Aug 26, 2018
1 parent d4b5bd4 commit 8acff56
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 3 additions & 1 deletion telegram/ext/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,9 @@ def __init__(self, pattern):
# the matched groups and groupdict to the context object.

def filter(self, message):
return bool(self.pattern.search(message.text))
if message.text:
return bool(self.pattern.search(message.text))
return False

class _Reply(BaseFilter):
name = 'Filters.reply'
Expand Down
3 changes: 3 additions & 0 deletions tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ def test_filters_regex(self, message):
message.text = 'i love python'
assert Filters.regex(r'.\b[lo]{2}ve python')(message)

message.text = None
assert not Filters.regex(r'fail')(message)

def test_filters_reply(self, message):
another_message = Message(1, User(1, 'TestOther', False), datetime.datetime.now(),
Chat(0, 'private'))
Expand Down

0 comments on commit 8acff56

Please sign in to comment.