mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-12-22 14:35:00 +01:00
Fix Filters.regex failing on non-text message (#1158)
* Fix #1115 * Improve regex filter test
This commit is contained in:
parent
d4b5bd40a5
commit
8acff56145
2 changed files with 6 additions and 1 deletions
|
@ -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'
|
||||
|
|
|
@ -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'))
|
||||
|
|
Loading…
Reference in a new issue