2424import pyrogram
2525from pyrogram import utils
2626from pyrogram .handlers import (
27- CallbackQueryHandler , MessageHandler , DeletedMessagesHandler ,
27+ CallbackQueryHandler , MessageHandler , EditedMessageHandler , DeletedMessagesHandler ,
2828 UserStatusHandler , RawUpdateHandler , InlineQueryHandler , PollHandler ,
2929 ChosenInlineResultHandler , ChatMemberUpdatedHandler , ChatJoinRequestHandler
3030)
4242
4343
4444class Dispatcher :
45- NEW_MESSAGE_UPDATES = (
46- UpdateNewMessage ,
47- UpdateNewChannelMessage ,
48- UpdateNewScheduledMessage
49- )
50-
51- EDIT_MESSAGE_UPDATES = (
52- UpdateEditMessage ,
53- UpdateEditChannelMessage ,
54- )
55-
56- DELETE_MESSAGES_UPDATES = (
57- UpdateDeleteMessages ,
58- UpdateDeleteChannelMessages
59- )
60-
61- CALLBACK_QUERY_UPDATES = (
62- UpdateBotCallbackQuery ,
63- UpdateInlineBotCallbackQuery
64- )
65-
66- CHAT_MEMBER_UPDATES = (
67- UpdateChatParticipant ,
68- UpdateChannelParticipant
69- )
70-
71- MESSAGE_UPDATES = NEW_MESSAGE_UPDATES + EDIT_MESSAGE_UPDATES
45+ NEW_MESSAGE_UPDATES = (UpdateNewMessage , UpdateNewChannelMessage , UpdateNewScheduledMessage )
46+ EDIT_MESSAGE_UPDATES = (UpdateEditMessage , UpdateEditChannelMessage )
47+ DELETE_MESSAGES_UPDATES = (UpdateDeleteMessages , UpdateDeleteChannelMessages )
48+ CALLBACK_QUERY_UPDATES = (UpdateBotCallbackQuery , UpdateInlineBotCallbackQuery )
49+ CHAT_MEMBER_UPDATES = (UpdateChatParticipant , UpdateChannelParticipant )
50+ USER_STATUS_UPDATES = (UpdateUserStatus ,)
51+ BOT_INLINE_QUERY_UPDATES = (UpdateBotInlineQuery ,)
52+ POLL_UPDATES = (UpdateMessagePoll ,)
53+ CHOSEN_INLINE_RESULT_UPDATES = (UpdateBotInlineSend ,)
54+ CHAT_JOIN_REQUEST_UPDATES = (UpdateBotChatInviteRequester ,)
7255
7356 def __init__ (self , client : "pyrogram.Client" ):
7457 self .client = client
@@ -81,45 +64,80 @@ def __init__(self, client: "pyrogram.Client"):
8164 self .groups = OrderedDict ()
8265
8366 async def message_parser (update , users , chats ):
84- return await pyrogram .types .Message ._parse (
85- self .client , update .message , users , chats ,
86- isinstance (update , UpdateNewScheduledMessage )
87- ), MessageHandler
67+ return (
68+ await pyrogram .types .Message ._parse (self .client , update .message , users , chats ,
69+ isinstance (update , UpdateNewScheduledMessage )),
70+ MessageHandler
71+ )
72+
73+ async def edited_message_parser (update , users , chats ):
74+ # Edited messages are parsed the same way as new messages, but the handler is different
75+ parsed , _ = await message_parser (update , users , chats )
76+
77+ return (
78+ parsed ,
79+ EditedMessageHandler
80+ )
8881
8982 async def deleted_messages_parser (update , users , chats ):
90- return utils .parse_deleted_messages (self .client , update ), DeletedMessagesHandler
83+ return (
84+ utils .parse_deleted_messages (self .client , update ),
85+ DeletedMessagesHandler
86+ )
9187
9288 async def callback_query_parser (update , users , chats ):
93- return await pyrogram .types .CallbackQuery ._parse (self .client , update , users ), CallbackQueryHandler
89+ return (
90+ await pyrogram .types .CallbackQuery ._parse (self .client , update , users ),
91+ CallbackQueryHandler
92+ )
9493
9594 async def user_status_parser (update , users , chats ):
96- return pyrogram .types .User ._parse_user_status (self .client , update ), UserStatusHandler
95+ return (
96+ pyrogram .types .User ._parse_user_status (self .client , update ),
97+ UserStatusHandler
98+ )
9799
98100 async def inline_query_parser (update , users , chats ):
99- return pyrogram .types .InlineQuery ._parse (self .client , update , users ), InlineQueryHandler
101+ return (
102+ pyrogram .types .InlineQuery ._parse (self .client , update , users ),
103+ InlineQueryHandler
104+ )
100105
101106 async def poll_parser (update , users , chats ):
102- return pyrogram .types .Poll ._parse_update (self .client , update ), PollHandler
107+ return (
108+ pyrogram .types .Poll ._parse_update (self .client , update ),
109+ PollHandler
110+ )
103111
104112 async def chosen_inline_result_parser (update , users , chats ):
105- return pyrogram .types .ChosenInlineResult ._parse (self .client , update , users ), ChosenInlineResultHandler
113+ return (
114+ pyrogram .types .ChosenInlineResult ._parse (self .client , update , users ),
115+ ChosenInlineResultHandler
116+ )
106117
107118 async def chat_member_updated_parser (update , users , chats ):
108- return pyrogram .types .ChatMemberUpdated ._parse (self .client , update , users , chats ), ChatMemberUpdatedHandler
119+ return (
120+ pyrogram .types .ChatMemberUpdated ._parse (self .client , update , users , chats ),
121+ ChatMemberUpdatedHandler
122+ )
109123
110124 async def chat_join_request_parser (update , users , chats ):
111- return pyrogram .types .ChatJoinRequest ._parse (self .client , update , users , chats ), ChatJoinRequestHandler
125+ return (
126+ pyrogram .types .ChatJoinRequest ._parse (self .client , update , users , chats ),
127+ ChatJoinRequestHandler
128+ )
112129
113130 self .update_parsers = {
114- Dispatcher .MESSAGE_UPDATES : message_parser ,
131+ Dispatcher .NEW_MESSAGE_UPDATES : message_parser ,
132+ Dispatcher .EDIT_MESSAGE_UPDATES : edited_message_parser ,
115133 Dispatcher .DELETE_MESSAGES_UPDATES : deleted_messages_parser ,
116134 Dispatcher .CALLBACK_QUERY_UPDATES : callback_query_parser ,
117- ( UpdateUserStatus ,) : user_status_parser ,
118- ( UpdateBotInlineQuery ,) : inline_query_parser ,
119- ( UpdateMessagePoll ,) : poll_parser ,
120- ( UpdateBotInlineSend ,) : chosen_inline_result_parser ,
135+ Dispatcher . USER_STATUS_UPDATES : user_status_parser ,
136+ Dispatcher . BOT_INLINE_QUERY_UPDATES : inline_query_parser ,
137+ Dispatcher . POLL_UPDATES : poll_parser ,
138+ Dispatcher . CHOSEN_INLINE_RESULT_UPDATES : chosen_inline_result_parser ,
121139 Dispatcher .CHAT_MEMBER_UPDATES : chat_member_updated_parser ,
122- ( UpdateBotChatInviteRequester ,) : chat_join_request_parser
140+ Dispatcher . CHAT_JOIN_REQUEST_UPDATES : chat_join_request_parser
123141 }
124142
125143 self .update_parsers = {key : value for key_tuple , value in self .update_parsers .items () for key in key_tuple }
0 commit comments