Fix Filters.regex failing on non-text message (#1158)

* Fix #1115

* Improve regex filter test
This commit is contained in:
Dmitry Grigoryev 2018-08-26 21:39:01 +03:00 committed by Jasmin Bom
parent d4b5bd40a5
commit 8acff56145
2 changed files with 6 additions and 1 deletions

View file

@ -198,7 +198,9 @@ class Filters(object):
# 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'

View file

@ -68,6 +68,9 @@ class TestFilters(object):
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'))