make ChatTypeFilter work with inline queries (#915)

* make ChatTypeFilter work with inline queries

* add condition when call.message is none
This commit is contained in:
Abror Maksudov 2022-06-22 03:03:44 +05:00 committed by GitHub
parent ce5077876b
commit 1ced320a19
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 5 deletions

View file

@ -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):

View file

@ -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