mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
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:
parent
ce5077876b
commit
1ced320a19
2 changed files with 9 additions and 5 deletions
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue