From b2d2b018a7f21deb7d04e28467100cf992d415ca Mon Sep 17 00:00:00 2001 From: eboshare Date: Wed, 15 Apr 2020 04:01:57 +0400 Subject: [PATCH] A small speedup in Dispatcher According to telegram Update specification: https://core.telegram.org/bots/api#update "At most one of the optional parameters can be present in any given update." --- aiogram/dispatcher/dispatcher.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/aiogram/dispatcher/dispatcher.py b/aiogram/dispatcher/dispatcher.py index 950ce60f..eae706ac 100644 --- a/aiogram/dispatcher/dispatcher.py +++ b/aiogram/dispatcher/dispatcher.py @@ -206,36 +206,36 @@ class Dispatcher(DataMixin, ContextInstanceMixin): types.User.set_current(update.message.from_user) types.Chat.set_current(update.message.chat) return await self.message_handlers.notify(update.message) - if update.edited_message: + elif update.edited_message: types.User.set_current(update.edited_message.from_user) types.Chat.set_current(update.edited_message.chat) return await self.edited_message_handlers.notify(update.edited_message) - if update.channel_post: + elif update.channel_post: types.Chat.set_current(update.channel_post.chat) return await self.channel_post_handlers.notify(update.channel_post) - if update.edited_channel_post: + elif update.edited_channel_post: types.Chat.set_current(update.edited_channel_post.chat) return await self.edited_channel_post_handlers.notify(update.edited_channel_post) - if update.inline_query: + elif update.inline_query: types.User.set_current(update.inline_query.from_user) return await self.inline_query_handlers.notify(update.inline_query) - if update.chosen_inline_result: + elif update.chosen_inline_result: types.User.set_current(update.chosen_inline_result.from_user) return await self.chosen_inline_result_handlers.notify(update.chosen_inline_result) - if update.callback_query: + elif update.callback_query: if update.callback_query.message: types.Chat.set_current(update.callback_query.message.chat) types.User.set_current(update.callback_query.from_user) return await self.callback_query_handlers.notify(update.callback_query) - if update.shipping_query: + elif update.shipping_query: types.User.set_current(update.shipping_query.from_user) return await self.shipping_query_handlers.notify(update.shipping_query) - if update.pre_checkout_query: + elif update.pre_checkout_query: types.User.set_current(update.pre_checkout_query.from_user) return await self.pre_checkout_query_handlers.notify(update.pre_checkout_query) - if update.poll: + elif update.poll: return await self.poll_handlers.notify(update.poll) - if update.poll_answer: + elif update.poll_answer: return await self.poll_answer_handlers.notify(update.poll_answer) except Exception as e: err = await self.errors_handlers.notify(update, e)