From 1ced320a195e022b5ba46f4011dd57cc621b244b Mon Sep 17 00:00:00 2001 From: Abror Maksudov <93431820+abrikk@users.noreply.github.com> Date: Wed, 22 Jun 2022 03:03:44 +0500 Subject: [PATCH] make ChatTypeFilter work with inline queries (#915) * make ChatTypeFilter work with inline queries * add condition when call.message is none --- aiogram/dispatcher/filters/builtin.py | 12 +++++++----- aiogram/types/chat.py | 2 ++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/aiogram/dispatcher/filters/builtin.py b/aiogram/dispatcher/filters/builtin.py index ebd38f08..373dafe5 100644 --- a/aiogram/dispatcher/filters/builtin.py +++ b/aiogram/dispatcher/filters/builtin.py @@ -728,18 +728,20 @@ class ChatTypeFilter(BoundFilter): self.chat_type: typing.Set[str] = set(chat_type) - async def check(self, obj: Union[Message, CallbackQuery, ChatMemberUpdated]): + async def check(self, obj: Union[Message, CallbackQuery, ChatMemberUpdated, InlineQuery]): if isinstance(obj, Message): - obj = obj.chat + chat_type = obj.chat.type elif isinstance(obj, CallbackQuery): - obj = obj.message.chat + chat_type = obj.message.chat.type if obj.message else None elif isinstance(obj, ChatMemberUpdated): - obj = obj.chat + chat_type = obj.chat.type + elif isinstance(obj, InlineQuery): + chat_type = obj.chat_type else: warnings.warn("ChatTypeFilter doesn't support %s as input", type(obj)) return False - return obj.type in self.chat_type + return chat_type in self.chat_type class MediaGroupFilter(BoundFilter): diff --git a/aiogram/types/chat.py b/aiogram/types/chat.py index dd11100a..4377851a 100644 --- a/aiogram/types/chat.py +++ b/aiogram/types/chat.py @@ -654,6 +654,7 @@ class ChatType(helper.Helper): """ List of chat types + :key: SENDER :key: PRIVATE :key: GROUP :key: SUPER_GROUP @@ -663,6 +664,7 @@ class ChatType(helper.Helper): mode = helper.HelperMode.lowercase + SENDER = helper.Item() # sender PRIVATE = helper.Item() # private GROUP = helper.Item() # group SUPERGROUP = helper.Item() # supergroup