From 40b679a878a3e51490399ff73f558b5a4bff3ebc Mon Sep 17 00:00:00 2001 From: KurimuzonAkuma Date: Sat, 4 May 2024 23:24:17 +0300 Subject: [PATCH] pyrofork: Add topic filter Signed-off-by: wulan17 --- pyrogram/filters.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/pyrogram/filters.py b/pyrogram/filters.py index 5d1e3ac8..8fbfb1ad 100644 --- a/pyrogram/filters.py +++ b/pyrogram/filters.py @@ -1028,3 +1028,25 @@ class chat(Filter, set): and message.from_user and message.from_user.is_self and not message.outgoing))) + + +# noinspection PyPep8Naming +class topic(Filter, set): + """Filter messages coming from one or more topics. + You can use `set bound methods `_ to manipulate the + topics container. + Parameters: + topics (``int`` | ``list``): + Pass one or more topic ids to filter messages in specific topics. + Defaults to None (no topics). + """ + + def __init__(self, topics: Union[int, List[int]] = None): + topics = [] if topics is None else topics if isinstance(topics, list) else [topics] + + super().__init__( + t for t in topics + ) + + async def __call__(self, _, message: Message): + return message.topic and message.topic.id in self