From 28680ac1d5dadb927d7ee3359238909d511bc7e5 Mon Sep 17 00:00:00 2001 From: Eldinnie Date: Sat, 14 Oct 2017 22:48:06 +0200 Subject: [PATCH] edited_updates also for channel_posts (#832) --- telegram/ext/messagehandler.py | 8 ++++---- telegram/ext/regexhandler.py | 6 +++--- tests/test_messagehandler.py | 12 ++++++------ tests/test_regexhandler.py | 8 ++++---- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/telegram/ext/messagehandler.py b/telegram/ext/messagehandler.py index 11c10803c..ae68d3ddc 100644 --- a/telegram/ext/messagehandler.py +++ b/telegram/ext/messagehandler.py @@ -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`. diff --git a/telegram/ext/regexhandler.py b/telegram/ext/regexhandler.py index 9397ff372..b25bd94c4 100644 --- a/telegram/ext/regexhandler.py +++ b/telegram/ext/regexhandler.py @@ -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) diff --git a/tests/test_messagehandler.py b/tests/test_messagehandler.py index 114d03ed6..45be591e5 100644 --- a/tests/test_messagehandler.py +++ b/tests/test_messagehandler.py @@ -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'): diff --git a/tests/test_regexhandler.py b/tests/test_regexhandler.py index bd87bc705..a9110bb95 100644 --- a/tests/test_regexhandler.py +++ b/tests/test_regexhandler.py @@ -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'):