2525import pyrogram
2626from pyrogram .api import types
2727from ..ext import utils
28- from ..handlers import RawUpdateHandler , CallbackQueryHandler , MessageHandler
28+ from ..handlers import RawUpdateHandler , CallbackQueryHandler , MessageHandler , DeletedMessagesHandler
2929
3030log = logging .getLogger (__name__ )
3131
@@ -41,6 +41,11 @@ class Dispatcher:
4141 types .UpdateEditChannelMessage
4242 )
4343
44+ DELETE_MESSAGE_UPDATES = (
45+ types .UpdateDeleteMessages ,
46+ types .UpdateDeleteChannelMessages
47+ )
48+
4449 MESSAGE_UPDATES = NEW_MESSAGE_UPDATES + EDIT_MESSAGE_UPDATES
4550
4651 def __init__ (self , client , workers ):
@@ -97,13 +102,21 @@ def dispatch(self, update, users: dict = None, chats: dict = None, is_raw: bool
97102 or update .edited_message
98103 or update .edited_channel_post )
99104
105+ deleted_messages = (update .deleted_channel_posts
106+ or update .deleted_messages )
107+
100108 callback_query = update .callback_query
101109
102110 if message and isinstance (handler , MessageHandler ):
103111 if not handler .check (message ):
104112 continue
105113
106114 args = (self .client , message )
115+ elif deleted_messages and isinstance (handler , DeletedMessagesHandler ):
116+ if not handler .check (deleted_messages ):
117+ continue
118+
119+ args = (self .client , deleted_messages )
107120 elif callback_query and isinstance (handler , CallbackQueryHandler ):
108121 if not handler .check (callback_query ):
109122 continue
@@ -161,6 +174,22 @@ def update_worker(self):
161174 else None )
162175 )
163176 )
177+
178+ elif isinstance (update , Dispatcher .DELETE_MESSAGE_UPDATES ):
179+ is_channel = hasattr (update , 'channel_id' )
180+
181+ messages = utils .parse_deleted_messages (
182+ update .messages ,
183+ (update .channel_id if is_channel else None )
184+ )
185+
186+ self .dispatch (
187+ pyrogram .Update (
188+ deleted_messages = (messages if not is_channel else None ),
189+ deleted_channel_posts = (messages if is_channel else None )
190+ )
191+ )
192+
164193 elif isinstance (update , types .UpdateBotCallbackQuery ):
165194 self .dispatch (
166195 pyrogram .Update (
0 commit comments