From 5c6d7ec54bf9188827d96f97f81994fe33b79077 Mon Sep 17 00:00:00 2001 From: darksidecat <58224121+darksidecat@users.noreply.github.com> Date: Sat, 21 Aug 2021 10:51:26 +0300 Subject: [PATCH] requested changes --- aiogram/dispatcher/dispatcher.py | 2 +- aiogram/types/update.py | 72 +++++++++++++------------------- 2 files changed, 29 insertions(+), 45 deletions(-) diff --git a/aiogram/dispatcher/dispatcher.py b/aiogram/dispatcher/dispatcher.py index 22c8d2ac..9b31d42d 100644 --- a/aiogram/dispatcher/dispatcher.py +++ b/aiogram/dispatcher/dispatcher.py @@ -188,7 +188,7 @@ class Dispatcher(Router): :return: """ try: - update_type, event = update.event + update_type, event = update.content() except UpdateTypeLookupError: warnings.warn( "Detected unknown update type.\n" diff --git a/aiogram/types/update.py b/aiogram/types/update.py index b1b55d9a..786dcc43 100644 --- a/aiogram/types/update.py +++ b/aiogram/types/update.py @@ -54,60 +54,44 @@ class Update(TelegramObject): chat_member: Optional[ChatMemberUpdated] = None """*Optional*. A chat member's status was updated in a chat. The bot must be an administrator in the chat and must explicitly specify 'chat_member' in the list of *allowed_updates* to receive these updates.""" - @property - def event(self) -> Tuple[str, TelegramObject]: + def content(self) -> Tuple[str, TelegramObject]: """ Detect content type - Return update type and event + Return update type and content If update type unknown raise UpdateTypeLookupError :return: """ event: TelegramObject if self.message: - update_type = "message" - event = self.message - elif self.edited_message: - update_type = "edited_message" - event = self.edited_message - elif self.channel_post: - update_type = "channel_post" - event = self.channel_post - elif self.edited_channel_post: - update_type = "edited_channel_post" - event = self.edited_channel_post - elif self.inline_query: - update_type = "inline_query" - event = self.inline_query - elif self.chosen_inline_result: - update_type = "chosen_inline_result" - event = self.chosen_inline_result - elif self.callback_query: - update_type = "callback_query" - event = self.callback_query - elif self.shipping_query: - update_type = "shipping_query" - event = self.shipping_query - elif self.pre_checkout_query: - update_type = "pre_checkout_query" - event = self.pre_checkout_query - elif self.poll: - update_type = "poll" - event = self.poll - elif self.poll_answer: - update_type = "poll_answer" - event = self.poll_answer - elif self.my_chat_member: - update_type = "my_chat_member" - event = self.my_chat_member - elif self.chat_member: - update_type = "chat_member" - event = self.chat_member - else: - raise UpdateTypeLookupError("Unknown update type") + return "message", self.message + if self.edited_message: + return "edited_message", self.edited_message + if self.channel_post: + return "channel_post", self.channel_post + if self.edited_channel_post: + return "edited_channel_post", self.edited_channel_post + if self.inline_query: + return "inline_query", self.inline_query + if self.chosen_inline_result: + return "chosen_inline_result", self.chosen_inline_result + if self.callback_query: + return "callback_query", self.callback_query + if self.shipping_query: + return "shipping_query", self.shipping_query + if self.pre_checkout_query: + return "pre_checkout_query", self.pre_checkout_query + if self.poll: + return "poll", self.poll + if self.poll_answer: + return "poll_answer", self.poll_answer + if self.my_chat_member: + return "my_chat_member", self.my_chat_member + if self.chat_member: + return "chat_member", self.chat_member - return update_type, event + raise UpdateTypeLookupError("Unknown update type") class UpdateTypeLookupError(LookupError):