@@ -37,8 +37,6 @@ class MessageHandler(Handler):
3737 callback (function): A function that takes ``bot, update`` as
3838 positional arguments. It will be called when the ``check_update``
3939 has determined that an update should be processed by this handler.
40- allow_edited (Optional[bool]): If the handler should also accept edited messages.
41- Default is ``False``
4240 pass_update_queue (optional[bool]): If the handler should be passed the
4341 update queue as a keyword argument called ``update_queue``. It can
4442 be used to insert updates. Default is ``False``
@@ -52,8 +50,12 @@ class MessageHandler(Handler):
5250 For each update in the same chat, it will be the same ``dict``. Default is ``False``.
5351 message_updates (Optional[bool]): Should "normal" message updates be handled? Default is
5452 ``True``.
53+ allow_edited (Optional[bool]): If the handler should also accept edited messages.
54+ Default is ``False`` - Deprecated. use edited updates instead.
5555 channel_post_updates (Optional[bool]): Should channel posts updates be handled? Default is
5656 ``True``.
57+ edited_updates (Optional[bool]): Should "edited" message updates be handled? Default is
58+ ``False``.
5759
5860 """
5961
@@ -66,9 +68,14 @@ def __init__(self,
6668 pass_user_data = False ,
6769 pass_chat_data = False ,
6870 message_updates = True ,
69- channel_post_updates = True ):
70- if not message_updates and not channel_post_updates :
71- raise ValueError ('Both message_updates & channel_post_updates are False' )
71+ channel_post_updates = True ,
72+ edited_updates = False ):
73+ if not message_updates and not channel_post_updates and not edited_updates :
74+ raise ValueError (
75+ 'message_updates, channel_post_updates and edited_updates are all False' )
76+ if allow_edited :
77+ warnings .warn ('allow_edited is getting deprecated, please use edited_updates instead' )
78+ edited_updates = allow_edited
7279
7380 super (MessageHandler , self ).__init__ (
7481 callback ,
@@ -77,9 +84,9 @@ def __init__(self,
7784 pass_user_data = pass_user_data ,
7885 pass_chat_data = pass_chat_data )
7986 self .filters = filters
80- self .allow_edited = allow_edited
8187 self .message_updates = message_updates
8288 self .channel_post_updates = channel_post_updates
89+ self .edited_updates = edited_updates
8390
8491 # We put this up here instead of with the rest of checking code
8592 # in check_update since we don't wanna spam a ton
@@ -88,17 +95,13 @@ def __init__(self,
8895 'deprecated, please use bitwise operators (& and |) '
8996 'instead. More info: https://git.io/vPTbc.' )
9097
91- def _is_allowed_message (self , update ):
92- return (self .message_updates
93- and (update .message or (update .edited_message and self .allow_edited )))
94-
95- def _is_allowed_channel_post (self , update ):
96- return (self .channel_post_updates
97- and (update .channel_post or (update .edited_channel_post and self .allow_edited )))
98+ def _is_allowed_update (self , update ):
99+ return any ([(self .message_updates and update .message ),
100+ (self .edited_updates and update .edited_message ),
101+ (self .channel_post_updates and update .channel_post )])
98102
99103 def check_update (self , update ):
100- if (isinstance (update , Update )
101- and (self ._is_allowed_message (update ) or self ._is_allowed_channel_post (update ))):
104+ if isinstance (update , Update ) and self ._is_allowed_update (update ):
102105
103106 if not self .filters :
104107 res = True
0 commit comments