Skip to content

Commit

Permalink
Add self_destruction filter
Browse files Browse the repository at this point in the history
  • Loading branch information
KurimuzonAkuma committed Jul 5, 2024
1 parent a177af3 commit 1e0f5f8
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions pyrogram/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import inspect
import re
from typing import Callable, Union, List, Pattern
from typing import Callable, Union, List, Pattern, Optional

import pyrogram
from pyrogram import enums
Expand Down Expand Up @@ -261,6 +261,16 @@ async def caption_filter(_, __, m: Message):

# endregion

# region self_destruction_filter
async def self_destruction_filter(_, __, m: Message):
return bool(m.media and getattr(getattr(m, m.media.value, None), "ttl_seconds", None))


self_destruction = create(self_destruction_filter)
"""Filter self-destruction media messages."""


# endregion

# region audio_filter
async def audio_filter(_, __, m: Message):
Expand Down Expand Up @@ -971,7 +981,7 @@ async def func(flt, _, update: Update):
elif isinstance(update, InlineQuery):
value = update.query
elif isinstance(update, PreCheckoutQuery):
value = update.payload
value = update.invoice_payload
else:
raise ValueError(f"Regex filter doesn't work with {type(update)}")

Expand Down Expand Up @@ -1001,7 +1011,7 @@ class user(Filter, set):
Defaults to None (no users).
"""

def __init__(self, users: Union[int, str, List[Union[int, str]]] = None):
def __init__(self, users: Optional[Union[int, str, List[Union[int, str]]]] = None):
users = [] if users is None else users if isinstance(users, list) else [users]

super().__init__(
Expand Down Expand Up @@ -1033,7 +1043,7 @@ class chat(Filter, set):
Defaults to None (no chats).
"""

def __init__(self, chats: Union[int, str, List[Union[int, str]]] = None):
def __init__(self, chats: Optional[Union[int, str, List[Union[int, str]]]] = None):
chats = [] if chats is None else chats if isinstance(chats, list) else [chats]

super().__init__(
Expand Down Expand Up @@ -1066,7 +1076,7 @@ class topic(Filter, set):
Defaults to None (no topics).
"""

def __init__(self, topics: Union[int, List[int]] = None):
def __init__(self, topics: Optional[Union[int, List[int]]] = None):
topics = [] if topics is None else topics if isinstance(topics, list) else [topics]

super().__init__(
Expand Down

0 comments on commit 1e0f5f8

Please sign in to comment.