From 9e00bce48bb57f34eb8e06e6a53305888bcb6a5f Mon Sep 17 00:00:00 2001 From: Mike Date: Fri, 23 May 2025 17:45:36 +0300 Subject: [PATCH 1/4] fix-filter-update-types --- pyrogram/filters.py | 116 +++++++++++++++++++++++++++++++++----------- 1 file changed, 88 insertions(+), 28 deletions(-) diff --git a/pyrogram/filters.py b/pyrogram/filters.py index fe08ad0fe..60100a230 100644 --- a/pyrogram/filters.py +++ b/pyrogram/filters.py @@ -163,56 +163,76 @@ async def all_filter(_, __, ___): # endregion # region me_filter -async def me_filter(_, __, m: Message): +async def me_filter(_, __, upd: Update): + if isinstance(upd, Message): + m = upd + elif not (m := upd.message): + raise ValueError(f"Me filter doesn't work with {type(upd)}") return bool(m.from_user and m.from_user.is_self or getattr(m, "outgoing", False)) me = create(me_filter) -"""Filter messages generated by you yourself.""" +"""Filter updates generated by you yourself.""" # endregion # region bot_filter -async def bot_filter(_, __, m: Message): +async def bot_filter(_, __, upd: Update): + if isinstance(upd, Message): + m = upd + elif not (m := upd.message): + raise ValueError(f"Bot filter doesn't work with {type(upd)}") return bool(m.from_user and m.from_user.is_bot) bot = create(bot_filter) -"""Filter messages coming from bots.""" +"""Filter updates coming from bots.""" # endregion # region sender_chat_filter -async def sender_chat_filter(_, __, m: Message): +async def sender_chat_filter(_, __, upd: Update): + if isinstance(upd, Message): + m = upd + elif not (m := upd.message): + raise ValueError(f"Sender chat filter doesn't work with {type(upd)}") return bool(m.sender_chat) sender_chat = create(sender_chat_filter) -"""Filter messages coming from sender chat.""" +"""Filter updates coming from sender chat.""" # endregion # region incoming_filter -async def incoming_filter(_, __, m: Message): +async def incoming_filter(_, __, upd: Update): + if isinstance(upd, Message): + m = upd + elif not (m := upd.message): + raise ValueError(f"Incoming filter doesn't work with {type(upd)}") return not m.outgoing incoming = create(incoming_filter) -"""Filter incoming messages. Messages sent to your own chat (Saved Messages) are also recognised as incoming.""" +"""Filter incoming updates. Updates sent to your own chat (Saved Messages) are also recognised as incoming.""" # endregion # region outgoing_filter -async def outgoing_filter(_, __, m: Message): +async def outgoing_filter(_, __, upd: Update): + if isinstance(upd, Message): + m = upd + elif not (m := upd.message): + raise ValueError(f"Outgoing filter doesn't work with {type(upd)}") return m.outgoing outgoing = create(outgoing_filter) -"""Filter outgoing messages. Messages sent to your own chat (Saved Messages) are not recognized as outgoing.""" +"""Filter outgoing updates. Updates sent to your own chat (Saved Messages) are not recognized as outgoing.""" # endregion @@ -537,45 +557,61 @@ async def media_spoiler_filter(_, __, m: Message): # endregion # region private_filter -async def private_filter(_, __, m: Message): +async def private_filter(_, __, upd: Update): + if isinstance(upd, Message): + m = upd + elif not (m := upd.message): + raise ValueError(f"Private filter doesn't work with {type(upd)}") return bool(m.chat and m.chat.type in {enums.ChatType.PRIVATE, enums.ChatType.BOT}) private = create(private_filter) -"""Filter messages sent in private chats.""" +"""Filter updates sent in private chats.""" # endregion # region group_filter -async def group_filter(_, __, m: Message): +async def group_filter(_, __, upd: Update): + if isinstance(upd, Message): + m = upd + elif not (m := upd.message): + raise ValueError(f"Group filter doesn't work with {type(upd)}") return bool(m.chat and m.chat.type in {enums.ChatType.GROUP, enums.ChatType.SUPERGROUP}) group = create(group_filter) -"""Filter messages sent in group or supergroup chats.""" +"""Filter updates sent in group or supergroup chats.""" # endregion # region channel_filter -async def channel_filter(_, __, m: Message): +async def channel_filter(_, __, upd: Update): + if isinstance(upd, Message): + m = upd + elif not (m := upd.message): + raise ValueError(f"Channel filter doesn't work with {type(upd)}") return bool(m.chat and m.chat.type == enums.ChatType.CHANNEL) channel = create(channel_filter) -"""Filter messages sent in channels.""" +"""Filter updates sent in channels.""" # endregion # region forum_filter -async def forum_filter(_, __, m: Message): +async def forum_filter(_, __, upd: Update): + if isinstance(upd, Message): + m = upd + elif not (m := upd.message): + raise ValueError(f"Forum filter doesn't work with {type(upd)}") return bool(m.chat and m.chat.is_forum) forum = create(forum_filter) -"""Filter messages sent in forums.""" +"""Filter updates sent in forums.""" # endregion @@ -768,7 +804,11 @@ async def via_bot_filter(_, __, m: Message): # endregion # region admin_filter -async def admin_filter(_, __, m: Message): +async def admin_filter(_, __, upd: Update): + if isinstance(upd, Message): + m = upd + elif not (m := upd.message): + raise ValueError(f"Admin filter doesn't work with {type(upd)}") return bool(m.chat and m.chat.is_admin) @@ -801,12 +841,16 @@ async def video_chat_ended_filter(_, __, m: Message): # endregion # region business -async def business_filter(_, __, m: Message): +async def business_filter(_, __, upd: Update): + if isinstance(upd, Message): + m = upd + elif not (m := upd.message): + raise ValueError(f"Business filter doesn't work with {type(upd)}") return bool(m.business_connection_id) business = create(business_filter) -"""Filter messages sent via business bot""" +"""Filter updates sent via business bot""" # endregion @@ -899,7 +943,11 @@ async def paid_message_filter(_, __, m: Message): # endregion # region linked_channel_filter -async def linked_channel_filter(_, __, m: Message): +async def linked_channel_filter(_, __, upd: Update): + if isinstance(upd, Message): + m = upd + elif not (m := upd.message): + raise ValueError(f"LinkedChannel filter doesn't work with {type(upd)}") return bool( m.forward_origin and m.forward_origin.type == enums.MessageOriginType.CHANNEL and @@ -1036,7 +1084,7 @@ async def func(flt, _, update: Update): # noinspection PyPep8Naming class user(Filter, set): - """Filter messages coming from one or more users. + """Filter updates coming from one or more users. You can use `set bound methods `_ to manipulate the users container. @@ -1057,7 +1105,11 @@ def __init__(self, users: Optional[Union[int, str, List[Union[int, str]]]] = Non else u for u in users ) - async def __call__(self, _, message: Message): + async def __call__(self, _, update: Update): + if isinstance(update, Message): + message = update + elif not (message := update.message): + raise ValueError(f"User filter doesn't work with {type(update)}") return (message.from_user and (message.from_user.id in self or (message.from_user.username @@ -1068,7 +1120,7 @@ async def __call__(self, _, message: Message): # noinspection PyPep8Naming class chat(Filter, set): - """Filter messages coming from one or more chats. + """Filter updates coming from one or more chats. You can use `set bound methods `_ to manipulate the chats container. @@ -1089,7 +1141,11 @@ def __init__(self, chats: Optional[Union[int, str, List[Union[int, str]]]] = Non else c for c in chats ) - async def __call__(self, _, message: Message): + async def __call__(self, _, update: Update): + if isinstance(update, Message): + message = update + elif not (message := update.message): + raise ValueError(f"Chat filter doesn't work with {type(update)}") return (message.chat and (message.chat.id in self or (message.chat.username @@ -1102,7 +1158,7 @@ async def __call__(self, _, message: Message): # noinspection PyPep8Naming class topic(Filter, set): - """Filter messages coming from one or more topics. + """Filter updates coming from one or more topics. You can use `set bound methods `_ to manipulate the topics container. @@ -1120,5 +1176,9 @@ def __init__(self, topics: Optional[Union[int, List[int]]] = None): t for t in topics ) - async def __call__(self, _, message: Message): + async def __call__(self, _, update: Update): + if isinstance(update, Message): + message = update + elif not (message := update.message): + raise ValueError(f"Topic filter doesn't work with {type(update)}") return message.topic and message.topic.id in self From 925a7269b011b9c07fb5bfcf70a9db9c22318a1f Mon Sep 17 00:00:00 2001 From: Mike Date: Sat, 31 May 2025 22:09:01 +0300 Subject: [PATCH 2/4] fix: bot.api file_id decode --- pyrogram/file_id.py | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/pyrogram/file_id.py b/pyrogram/file_id.py index 1a54a49d6..5291f9e69 100644 --- a/pyrogram/file_id.py +++ b/pyrogram/file_id.py @@ -139,6 +139,11 @@ class ThumbnailSource(IntEnum): CHAT_PHOTO_SMALL = 2 # DialogPhotoSmall CHAT_PHOTO_BIG = 3 # DialogPhotoBig STICKER_SET_THUMBNAIL = 4 + FULL_LEGACY = 5 + DIALOGPHOTO_SMALL_LEGACY = 6 + DIALOGPHOTO_BIG_LEGACY = 7 + STICKERSET_THUMBNAIL_LEGACY = 8 + STICKERSET_THUMBNAIL_VERSION = 9 # Photo-like file ids are longer and contain extra info, the rest are all documents @@ -246,8 +251,8 @@ def decode(file_id: str): media_id, access_hash = struct.unpack("= 8 else None - return FileId( + fileId = FileId( major=major, minor=minor, file_type=file_type, @@ -305,13 +309,12 @@ def decode(file_id: str): thumbnail_source=thumbnail_source, chat_id=chat_id, chat_access_hash=chat_access_hash, - local_id=local_id ) if thumbnail_source == ThumbnailSource.STICKER_SET_THUMBNAIL: - sticker_set_id, sticker_set_access_hash, local_id = struct.unpack(" Date: Sun, 1 Jun 2025 21:24:20 +0300 Subject: [PATCH 3/4] Discard changes to pyrogram/filters.py --- pyrogram/filters.py | 116 +++++++++++--------------------------------- 1 file changed, 28 insertions(+), 88 deletions(-) diff --git a/pyrogram/filters.py b/pyrogram/filters.py index 60100a230..fe08ad0fe 100644 --- a/pyrogram/filters.py +++ b/pyrogram/filters.py @@ -163,76 +163,56 @@ async def all_filter(_, __, ___): # endregion # region me_filter -async def me_filter(_, __, upd: Update): - if isinstance(upd, Message): - m = upd - elif not (m := upd.message): - raise ValueError(f"Me filter doesn't work with {type(upd)}") +async def me_filter(_, __, m: Message): return bool(m.from_user and m.from_user.is_self or getattr(m, "outgoing", False)) me = create(me_filter) -"""Filter updates generated by you yourself.""" +"""Filter messages generated by you yourself.""" # endregion # region bot_filter -async def bot_filter(_, __, upd: Update): - if isinstance(upd, Message): - m = upd - elif not (m := upd.message): - raise ValueError(f"Bot filter doesn't work with {type(upd)}") +async def bot_filter(_, __, m: Message): return bool(m.from_user and m.from_user.is_bot) bot = create(bot_filter) -"""Filter updates coming from bots.""" +"""Filter messages coming from bots.""" # endregion # region sender_chat_filter -async def sender_chat_filter(_, __, upd: Update): - if isinstance(upd, Message): - m = upd - elif not (m := upd.message): - raise ValueError(f"Sender chat filter doesn't work with {type(upd)}") +async def sender_chat_filter(_, __, m: Message): return bool(m.sender_chat) sender_chat = create(sender_chat_filter) -"""Filter updates coming from sender chat.""" +"""Filter messages coming from sender chat.""" # endregion # region incoming_filter -async def incoming_filter(_, __, upd: Update): - if isinstance(upd, Message): - m = upd - elif not (m := upd.message): - raise ValueError(f"Incoming filter doesn't work with {type(upd)}") +async def incoming_filter(_, __, m: Message): return not m.outgoing incoming = create(incoming_filter) -"""Filter incoming updates. Updates sent to your own chat (Saved Messages) are also recognised as incoming.""" +"""Filter incoming messages. Messages sent to your own chat (Saved Messages) are also recognised as incoming.""" # endregion # region outgoing_filter -async def outgoing_filter(_, __, upd: Update): - if isinstance(upd, Message): - m = upd - elif not (m := upd.message): - raise ValueError(f"Outgoing filter doesn't work with {type(upd)}") +async def outgoing_filter(_, __, m: Message): return m.outgoing outgoing = create(outgoing_filter) -"""Filter outgoing updates. Updates sent to your own chat (Saved Messages) are not recognized as outgoing.""" +"""Filter outgoing messages. Messages sent to your own chat (Saved Messages) are not recognized as outgoing.""" # endregion @@ -557,61 +537,45 @@ async def media_spoiler_filter(_, __, m: Message): # endregion # region private_filter -async def private_filter(_, __, upd: Update): - if isinstance(upd, Message): - m = upd - elif not (m := upd.message): - raise ValueError(f"Private filter doesn't work with {type(upd)}") +async def private_filter(_, __, m: Message): return bool(m.chat and m.chat.type in {enums.ChatType.PRIVATE, enums.ChatType.BOT}) private = create(private_filter) -"""Filter updates sent in private chats.""" +"""Filter messages sent in private chats.""" # endregion # region group_filter -async def group_filter(_, __, upd: Update): - if isinstance(upd, Message): - m = upd - elif not (m := upd.message): - raise ValueError(f"Group filter doesn't work with {type(upd)}") +async def group_filter(_, __, m: Message): return bool(m.chat and m.chat.type in {enums.ChatType.GROUP, enums.ChatType.SUPERGROUP}) group = create(group_filter) -"""Filter updates sent in group or supergroup chats.""" +"""Filter messages sent in group or supergroup chats.""" # endregion # region channel_filter -async def channel_filter(_, __, upd: Update): - if isinstance(upd, Message): - m = upd - elif not (m := upd.message): - raise ValueError(f"Channel filter doesn't work with {type(upd)}") +async def channel_filter(_, __, m: Message): return bool(m.chat and m.chat.type == enums.ChatType.CHANNEL) channel = create(channel_filter) -"""Filter updates sent in channels.""" +"""Filter messages sent in channels.""" # endregion # region forum_filter -async def forum_filter(_, __, upd: Update): - if isinstance(upd, Message): - m = upd - elif not (m := upd.message): - raise ValueError(f"Forum filter doesn't work with {type(upd)}") +async def forum_filter(_, __, m: Message): return bool(m.chat and m.chat.is_forum) forum = create(forum_filter) -"""Filter updates sent in forums.""" +"""Filter messages sent in forums.""" # endregion @@ -804,11 +768,7 @@ async def via_bot_filter(_, __, m: Message): # endregion # region admin_filter -async def admin_filter(_, __, upd: Update): - if isinstance(upd, Message): - m = upd - elif not (m := upd.message): - raise ValueError(f"Admin filter doesn't work with {type(upd)}") +async def admin_filter(_, __, m: Message): return bool(m.chat and m.chat.is_admin) @@ -841,16 +801,12 @@ async def video_chat_ended_filter(_, __, m: Message): # endregion # region business -async def business_filter(_, __, upd: Update): - if isinstance(upd, Message): - m = upd - elif not (m := upd.message): - raise ValueError(f"Business filter doesn't work with {type(upd)}") +async def business_filter(_, __, m: Message): return bool(m.business_connection_id) business = create(business_filter) -"""Filter updates sent via business bot""" +"""Filter messages sent via business bot""" # endregion @@ -943,11 +899,7 @@ async def paid_message_filter(_, __, m: Message): # endregion # region linked_channel_filter -async def linked_channel_filter(_, __, upd: Update): - if isinstance(upd, Message): - m = upd - elif not (m := upd.message): - raise ValueError(f"LinkedChannel filter doesn't work with {type(upd)}") +async def linked_channel_filter(_, __, m: Message): return bool( m.forward_origin and m.forward_origin.type == enums.MessageOriginType.CHANNEL and @@ -1084,7 +1036,7 @@ async def func(flt, _, update: Update): # noinspection PyPep8Naming class user(Filter, set): - """Filter updates coming from one or more users. + """Filter messages coming from one or more users. You can use `set bound methods `_ to manipulate the users container. @@ -1105,11 +1057,7 @@ def __init__(self, users: Optional[Union[int, str, List[Union[int, str]]]] = Non else u for u in users ) - async def __call__(self, _, update: Update): - if isinstance(update, Message): - message = update - elif not (message := update.message): - raise ValueError(f"User filter doesn't work with {type(update)}") + async def __call__(self, _, message: Message): return (message.from_user and (message.from_user.id in self or (message.from_user.username @@ -1120,7 +1068,7 @@ async def __call__(self, _, update: Update): # noinspection PyPep8Naming class chat(Filter, set): - """Filter updates coming from one or more chats. + """Filter messages coming from one or more chats. You can use `set bound methods `_ to manipulate the chats container. @@ -1141,11 +1089,7 @@ def __init__(self, chats: Optional[Union[int, str, List[Union[int, str]]]] = Non else c for c in chats ) - async def __call__(self, _, update: Update): - if isinstance(update, Message): - message = update - elif not (message := update.message): - raise ValueError(f"Chat filter doesn't work with {type(update)}") + async def __call__(self, _, message: Message): return (message.chat and (message.chat.id in self or (message.chat.username @@ -1158,7 +1102,7 @@ async def __call__(self, _, update: Update): # noinspection PyPep8Naming class topic(Filter, set): - """Filter updates coming from one or more topics. + """Filter messages coming from one or more topics. You can use `set bound methods `_ to manipulate the topics container. @@ -1176,9 +1120,5 @@ def __init__(self, topics: Optional[Union[int, List[int]]] = None): t for t in topics ) - async def __call__(self, _, update: Update): - if isinstance(update, Message): - message = update - elif not (message := update.message): - raise ValueError(f"Topic filter doesn't work with {type(update)}") + async def __call__(self, _, message: Message): return message.topic and message.topic.id in self From 4f86aa8e64c0cfccb803f78b37c691513c9dc8ac Mon Sep 17 00:00:00 2001 From: xync Date: Thu, 26 Jun 2025 14:54:21 +0300 Subject: [PATCH 4/4] Revert "Discard changes to pyrogram/filters.py" This reverts commit 52027ed4 --- pyrogram/filters.py | 116 +++++++++++++++++++++++++++++++++----------- 1 file changed, 88 insertions(+), 28 deletions(-) diff --git a/pyrogram/filters.py b/pyrogram/filters.py index fd9d829da..aa0b6fd18 100644 --- a/pyrogram/filters.py +++ b/pyrogram/filters.py @@ -163,56 +163,76 @@ async def all_filter(_, __, ___): # endregion # region me_filter -async def me_filter(_, __, m: Message): +async def me_filter(_, __, upd: Update): + if isinstance(upd, Message): + m = upd + elif not (m := upd.message): + raise ValueError(f"Me filter doesn't work with {type(upd)}") return bool(m.from_user and m.from_user.is_self or getattr(m, "outgoing", False)) me = create(me_filter) -"""Filter messages generated by you yourself.""" +"""Filter updates generated by you yourself.""" # endregion # region bot_filter -async def bot_filter(_, __, m: Message): +async def bot_filter(_, __, upd: Update): + if isinstance(upd, Message): + m = upd + elif not (m := upd.message): + raise ValueError(f"Bot filter doesn't work with {type(upd)}") return bool(m.from_user and m.from_user.is_bot) bot = create(bot_filter) -"""Filter messages coming from bots.""" +"""Filter updates coming from bots.""" # endregion # region sender_chat_filter -async def sender_chat_filter(_, __, m: Message): +async def sender_chat_filter(_, __, upd: Update): + if isinstance(upd, Message): + m = upd + elif not (m := upd.message): + raise ValueError(f"Sender chat filter doesn't work with {type(upd)}") return bool(m.sender_chat) sender_chat = create(sender_chat_filter) -"""Filter messages coming from sender chat.""" +"""Filter updates coming from sender chat.""" # endregion # region incoming_filter -async def incoming_filter(_, __, m: Message): +async def incoming_filter(_, __, upd: Update): + if isinstance(upd, Message): + m = upd + elif not (m := upd.message): + raise ValueError(f"Incoming filter doesn't work with {type(upd)}") return not m.outgoing incoming = create(incoming_filter) -"""Filter incoming messages. Messages sent to your own chat (Saved Messages) are also recognised as incoming.""" +"""Filter incoming updates. Updates sent to your own chat (Saved Messages) are also recognised as incoming.""" # endregion # region outgoing_filter -async def outgoing_filter(_, __, m: Message): +async def outgoing_filter(_, __, upd: Update): + if isinstance(upd, Message): + m = upd + elif not (m := upd.message): + raise ValueError(f"Outgoing filter doesn't work with {type(upd)}") return m.outgoing outgoing = create(outgoing_filter) -"""Filter outgoing messages. Messages sent to your own chat (Saved Messages) are not recognized as outgoing.""" +"""Filter outgoing updates. Updates sent to your own chat (Saved Messages) are not recognized as outgoing.""" # endregion @@ -537,34 +557,46 @@ async def media_spoiler_filter(_, __, m: Message): # endregion # region private_filter -async def private_filter(_, __, m: Message): +async def private_filter(_, __, upd: Update): + if isinstance(upd, Message): + m = upd + elif not (m := upd.message): + raise ValueError(f"Private filter doesn't work with {type(upd)}") return bool(m.chat and m.chat.type in {enums.ChatType.PRIVATE, enums.ChatType.BOT}) private = create(private_filter) -"""Filter messages sent in private chats.""" +"""Filter updates sent in private chats.""" # endregion # region group_filter -async def group_filter(_, __, m: Message): +async def group_filter(_, __, upd: Update): + if isinstance(upd, Message): + m = upd + elif not (m := upd.message): + raise ValueError(f"Group filter doesn't work with {type(upd)}") return bool(m.chat and m.chat.type in {enums.ChatType.GROUP, enums.ChatType.SUPERGROUP, enums.ChatType.FORUM}) group = create(group_filter) -"""Filter messages sent in group or supergroup chats.""" +"""Filter updates sent in group or supergroup chats.""" # endregion # region channel_filter -async def channel_filter(_, __, m: Message): +async def channel_filter(_, __, upd: Update): + if isinstance(upd, Message): + m = upd + elif not (m := upd.message): + raise ValueError(f"Channel filter doesn't work with {type(upd)}") return bool(m.chat and m.chat.type == enums.ChatType.CHANNEL) channel = create(channel_filter) -"""Filter messages sent in channels.""" +"""Filter updates sent in channels.""" # endregion @@ -581,12 +613,16 @@ async def direct_filter(_, __, m: Message): # endregion # region forum_filter -async def forum_filter(_, __, m: Message): +async def forum_filter(_, __, upd: Update): + if isinstance(upd, Message): + m = upd + elif not (m := upd.message): + raise ValueError(f"Forum filter doesn't work with {type(upd)}") return bool(m.chat and m.chat.is_forum) forum = create(forum_filter) -"""Filter messages sent in forums.""" +"""Filter updates sent in forums.""" # endregion @@ -779,7 +815,11 @@ async def via_bot_filter(_, __, m: Message): # endregion # region admin_filter -async def admin_filter(_, __, m: Message): +async def admin_filter(_, __, upd: Update): + if isinstance(upd, Message): + m = upd + elif not (m := upd.message): + raise ValueError(f"Admin filter doesn't work with {type(upd)}") return bool(m.chat and m.chat.is_admin) @@ -812,12 +852,16 @@ async def video_chat_ended_filter(_, __, m: Message): # endregion # region business -async def business_filter(_, __, m: Message): +async def business_filter(_, __, upd: Update): + if isinstance(upd, Message): + m = upd + elif not (m := upd.message): + raise ValueError(f"Business filter doesn't work with {type(upd)}") return bool(m.business_connection_id) business = create(business_filter) -"""Filter messages sent via business bot""" +"""Filter updates sent via business bot""" # endregion @@ -910,7 +954,11 @@ async def paid_message_filter(_, __, m: Message): # endregion # region linked_channel_filter -async def linked_channel_filter(_, __, m: Message): +async def linked_channel_filter(_, __, upd: Update): + if isinstance(upd, Message): + m = upd + elif not (m := upd.message): + raise ValueError(f"LinkedChannel filter doesn't work with {type(upd)}") return bool( m.forward_origin and m.forward_origin.type == enums.MessageOriginType.CHANNEL and @@ -1047,7 +1095,7 @@ async def func(flt, _, update: Update): # noinspection PyPep8Naming class user(Filter, set): - """Filter messages coming from one or more users. + """Filter updates coming from one or more users. You can use `set bound methods `_ to manipulate the users container. @@ -1068,7 +1116,11 @@ def __init__(self, users: Optional[Union[int, str, List[Union[int, str]]]] = Non else u for u in users ) - async def __call__(self, _, message: Message): + async def __call__(self, _, update: Update): + if isinstance(update, Message): + message = update + elif not (message := update.message): + raise ValueError(f"User filter doesn't work with {type(update)}") return (message.from_user and (message.from_user.id in self or (message.from_user.username @@ -1079,7 +1131,7 @@ async def __call__(self, _, message: Message): # noinspection PyPep8Naming class chat(Filter, set): - """Filter messages coming from one or more chats. + """Filter updates coming from one or more chats. You can use `set bound methods `_ to manipulate the chats container. @@ -1100,7 +1152,11 @@ def __init__(self, chats: Optional[Union[int, str, List[Union[int, str]]]] = Non else c for c in chats ) - async def __call__(self, _, message: Message): + async def __call__(self, _, update: Update): + if isinstance(update, Message): + message = update + elif not (message := update.message): + raise ValueError(f"Chat filter doesn't work with {type(update)}") return (message.chat and (message.chat.id in self or (message.chat.username @@ -1113,7 +1169,7 @@ async def __call__(self, _, message: Message): # noinspection PyPep8Naming class topic(Filter, set): - """Filter messages coming from one or more topics. + """Filter updates coming from one or more topics. You can use `set bound methods `_ to manipulate the topics container. @@ -1131,5 +1187,9 @@ def __init__(self, topics: Optional[Union[int, List[int]]] = None): t for t in topics ) - async def __call__(self, _, message: Message): + async def __call__(self, _, update: Update): + if isinstance(update, Message): + message = update + elif not (message := update.message): + raise ValueError(f"Topic filter doesn't work with {type(update)}") return message.topic and message.topic.id in self