Skip to content
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
8 changes: 4 additions & 4 deletions telegram/ext/messagehandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"""This module contains the MessageHandler class."""
import warnings

from .handler import Handler
from telegram import Update
from .handler import Handler


class MessageHandler(Handler):
Expand Down Expand Up @@ -125,9 +125,9 @@ def __init__(self,
'instead. More info: https://git.io/vPTbc.')

def _is_allowed_update(self, update):
return any([(self.message_updates and update.message),
(self.edited_updates and update.edited_message),
(self.channel_post_updates and update.channel_post)])
return any([self.message_updates and update.message,
self.edited_updates and (update.edited_message or update.edited_channel_post),
self.channel_post_updates and update.channel_post])

def check_update(self, update):
"""Determines whether an update should be passed to this handlers :attr:`callback`.
Expand Down
6 changes: 3 additions & 3 deletions telegram/ext/regexhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ def check_update(self, update):
"""
if not isinstance(update, Update) and not update.effective_message:
return False
if any([(self.message_updates and update.message),
(self.edited_updates and update.edited_message),
(self.channel_post_updates and update.channel_post)]) and \
if any([self.message_updates and update.message,
self.edited_updates and (update.edited_message or update.edited_channel_post),
self.channel_post_updates and update.channel_post]) and \
update.effective_message.text:
match = re.match(self.pattern, update.effective_message.text)
return bool(match)
Expand Down
12 changes: 6 additions & 6 deletions tests/test_messagehandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def test_edited(self, message):
assert handler.check_update(Update(0, edited_message=message))
assert not handler.check_update(Update(0, message=message))
assert not handler.check_update(Update(0, channel_post=message))
assert not handler.check_update(Update(0, edited_channel_post=message))
assert handler.check_update(Update(0, edited_channel_post=message))

def test_channel_post(self, message):
handler = MessageHandler(None, self.callback_basic, edited_updates=False,
Expand All @@ -105,17 +105,17 @@ def test_multiple_flags(self, message):
assert handler.check_update(Update(0, edited_message=message))
assert handler.check_update(Update(0, message=message))
assert handler.check_update(Update(0, channel_post=message))
assert not handler.check_update(Update(0, edited_channel_post=message))
assert handler.check_update(Update(0, edited_channel_post=message))

def test_allow_updated(self, message):
def test_allow_edited(self, message):
with pytest.warns(UserWarning):
handler = MessageHandler(None, self.callback_basic, message_updates=True,
allow_edited=True)
allow_edited=True, channel_post_updates=False)

assert handler.check_update(Update(0, edited_message=message))
assert handler.check_update(Update(0, message=message))
assert handler.check_update(Update(0, channel_post=message))
assert not handler.check_update(Update(0, edited_channel_post=message))
assert not handler.check_update(Update(0, channel_post=message))
assert handler.check_update(Update(0, edited_channel_post=message))

def test_none_allowed(self):
with pytest.raises(ValueError, match='are all False'):
Expand Down
8 changes: 4 additions & 4 deletions tests/test_regexhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def test_edited(self, message):
assert handler.check_update(Update(0, edited_message=message))
assert not handler.check_update(Update(0, message=message))
assert not handler.check_update(Update(0, channel_post=message))
assert not handler.check_update(Update(0, edited_channel_post=message))
assert handler.check_update(Update(0, edited_channel_post=message))

def test_channel_post(self, message):
handler = RegexHandler('.*', self.callback_basic, edited_updates=False,
Expand All @@ -136,17 +136,17 @@ def test_multiple_flags(self, message):
assert handler.check_update(Update(0, edited_message=message))
assert handler.check_update(Update(0, message=message))
assert handler.check_update(Update(0, channel_post=message))
assert not handler.check_update(Update(0, edited_channel_post=message))
assert handler.check_update(Update(0, edited_channel_post=message))

def test_allow_updated(self, message):
def test_allow_edited(self, message):
with pytest.warns(UserWarning):
handler = RegexHandler('.*', self.callback_basic, message_updates=True,
allow_edited=True)

assert handler.check_update(Update(0, edited_message=message))
assert handler.check_update(Update(0, message=message))
assert not handler.check_update(Update(0, channel_post=message))
assert not handler.check_update(Update(0, edited_channel_post=message))
assert handler.check_update(Update(0, edited_channel_post=message))

def test_none_allowed(self):
with pytest.raises(ValueError, match='are all False'):
Expand Down