edited_updates also for channel_posts (#832)

This commit is contained in:
Eldinnie 2017-10-14 22:48:06 +02:00 committed by Noam Meltzer
parent ec9b16ac7b
commit 28680ac1d5
4 changed files with 17 additions and 17 deletions

View file

@ -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):
@ -125,9 +125,9 @@ class MessageHandler(Handler):
'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`.

View file

@ -145,9 +145,9 @@ class RegexHandler(Handler):
"""
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)

View file

@ -87,7 +87,7 @@ class TestMessageHandler(object):
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,
@ -105,17 +105,17 @@ class TestMessageHandler(object):
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'):

View file

@ -118,7 +118,7 @@ class TestRegexHandler(object):
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,
@ -136,9 +136,9 @@ class TestRegexHandler(object):
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)
@ -146,7 +146,7 @@ class TestRegexHandler(object):
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'):