Skip to content

Commit 28680ac

Browse files
Eldinnietsnoam
authored andcommitted
edited_updates also for channel_posts (python-telegram-bot#832)
1 parent ec9b16a commit 28680ac

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

telegram/ext/messagehandler.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
"""This module contains the MessageHandler class."""
2121
import warnings
2222

23-
from .handler import Handler
2423
from telegram import Update
24+
from .handler import Handler
2525

2626

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

127127
def _is_allowed_update(self, update):
128-
return any([(self.message_updates and update.message),
129-
(self.edited_updates and update.edited_message),
130-
(self.channel_post_updates and update.channel_post)])
128+
return any([self.message_updates and update.message,
129+
self.edited_updates and (update.edited_message or update.edited_channel_post),
130+
self.channel_post_updates and update.channel_post])
131131

132132
def check_update(self, update):
133133
"""Determines whether an update should be passed to this handlers :attr:`callback`.

telegram/ext/regexhandler.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ def check_update(self, update):
145145
"""
146146
if not isinstance(update, Update) and not update.effective_message:
147147
return False
148-
if any([(self.message_updates and update.message),
149-
(self.edited_updates and update.edited_message),
150-
(self.channel_post_updates and update.channel_post)]) and \
148+
if any([self.message_updates and update.message,
149+
self.edited_updates and (update.edited_message or update.edited_channel_post),
150+
self.channel_post_updates and update.channel_post]) and \
151151
update.effective_message.text:
152152
match = re.match(self.pattern, update.effective_message.text)
153153
return bool(match)

tests/test_messagehandler.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def test_edited(self, message):
8787
assert handler.check_update(Update(0, edited_message=message))
8888
assert not handler.check_update(Update(0, message=message))
8989
assert not handler.check_update(Update(0, channel_post=message))
90-
assert not handler.check_update(Update(0, edited_channel_post=message))
90+
assert handler.check_update(Update(0, edited_channel_post=message))
9191

9292
def test_channel_post(self, message):
9393
handler = MessageHandler(None, self.callback_basic, edited_updates=False,
@@ -105,17 +105,17 @@ def test_multiple_flags(self, message):
105105
assert handler.check_update(Update(0, edited_message=message))
106106
assert handler.check_update(Update(0, message=message))
107107
assert handler.check_update(Update(0, channel_post=message))
108-
assert not handler.check_update(Update(0, edited_channel_post=message))
108+
assert handler.check_update(Update(0, edited_channel_post=message))
109109

110-
def test_allow_updated(self, message):
110+
def test_allow_edited(self, message):
111111
with pytest.warns(UserWarning):
112112
handler = MessageHandler(None, self.callback_basic, message_updates=True,
113-
allow_edited=True)
113+
allow_edited=True, channel_post_updates=False)
114114

115115
assert handler.check_update(Update(0, edited_message=message))
116116
assert handler.check_update(Update(0, message=message))
117-
assert handler.check_update(Update(0, channel_post=message))
118-
assert not handler.check_update(Update(0, edited_channel_post=message))
117+
assert not handler.check_update(Update(0, channel_post=message))
118+
assert handler.check_update(Update(0, edited_channel_post=message))
119119

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

tests/test_regexhandler.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def test_edited(self, message):
118118
assert handler.check_update(Update(0, edited_message=message))
119119
assert not handler.check_update(Update(0, message=message))
120120
assert not handler.check_update(Update(0, channel_post=message))
121-
assert not handler.check_update(Update(0, edited_channel_post=message))
121+
assert handler.check_update(Update(0, edited_channel_post=message))
122122

123123
def test_channel_post(self, message):
124124
handler = RegexHandler('.*', self.callback_basic, edited_updates=False,
@@ -136,17 +136,17 @@ def test_multiple_flags(self, message):
136136
assert handler.check_update(Update(0, edited_message=message))
137137
assert handler.check_update(Update(0, message=message))
138138
assert handler.check_update(Update(0, channel_post=message))
139-
assert not handler.check_update(Update(0, edited_channel_post=message))
139+
assert handler.check_update(Update(0, edited_channel_post=message))
140140

141-
def test_allow_updated(self, message):
141+
def test_allow_edited(self, message):
142142
with pytest.warns(UserWarning):
143143
handler = RegexHandler('.*', self.callback_basic, message_updates=True,
144144
allow_edited=True)
145145

146146
assert handler.check_update(Update(0, edited_message=message))
147147
assert handler.check_update(Update(0, message=message))
148148
assert not handler.check_update(Update(0, channel_post=message))
149-
assert not handler.check_update(Update(0, edited_channel_post=message))
149+
assert handler.check_update(Update(0, edited_channel_post=message))
150150

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

0 commit comments

Comments
 (0)