U
    ;g                  	   @   s   d dl mZmZmZmZ d dlZd dlmZmZmZm	Z	 de	j
jd ddfeeef edeeeeef ed dd	d
ZG dd dZdS )    )UnionListAsyncGeneratorOptionalN)rawtypesutilsenums d   enums.MessagesFiltertypes.Message)chat_idqueryfilteroffsetlimit	from_userreturnc                    sp   | j tjjj| |I d H || ddd||dd|rD| |I d H nd ddddI d H }tj| |ddI d H S )Nr   )Zpeerqr   Zmin_dateZmax_dateZ	offset_idZ
add_offsetr   Zmin_idZmax_idZfrom_idhash<   )Zsleep_threshold)Zreplies)	Zinvoker   Z	functionsmessagesZSearchZresolve_peervaluer   Zparse_messages)clientr   r   r   r   r   r   r r   i/opt/bot/vods_filmes/script/venv/lib/python3.8/site-packages/pyrogram/methods/messages/search_messages.py	get_chunk   s(    	r   c                   @   sP   e Zd Zddejjddfdeeef eedeeeef e	e
d  ddd	ZdS )
SearchMessagesr
   r   Nzpyrogram.Clientr   )r   N)selfr   r   r   r   r   r   r   c              	   C  sv   d}t |pd}td|}t| ||||||dI dH }	|	s>dS |t|	7 }|	D ] }
|
V  |d7 }||krN dS qNqdS )a	  Search for text and media messages inside a specific chat.

        If you want to get the messages count only, see :meth:`~pyrogram.Client.search_messages_count`.

        .. include:: /_includes/usable-by/users.rst

        Parameters:
            chat_id (``int`` | ``str``):
                Unique identifier (int) or username (str) of the target chat.
                For your personal cloud (Saved Messages) you can simply use "me" or "self".
                For a contact that exists in your Telegram address book you can use his phone number (str).

            query (``str``, *optional*):
                Text query string.
                Required for text-only messages, optional for media messages (see the ``filter`` argument).
                When passed while searching for media messages, the query will be applied to captions.
                Defaults to "" (empty string).

            offset (``int``, *optional*):
                Sequential number of the first message to be returned.
                Defaults to 0.

            filter (:obj:`~pyrogram.enums.MessagesFilter`, *optional*):
                Pass a filter in order to search for specific kind of messages only.
                Defaults to any message (no filter).

            limit (``int``, *optional*):
                Limits the number of messages to be retrieved.
                By default, no limit is applied and all messages are returned.

            from_user (``int`` | ``str``, *optional*):
                Unique identifier (int) or username (str) of the target user you want to search for messages from.

        Returns:
            ``Generator``: A generator yielding :obj:`~pyrogram.types.Message` objects.

        Example:
            .. code-block:: python

                from pyrogram import enums

                # Search for text messages in chat. Get the last 120 results
                async for message in app.search_messages(chat_id, query="hello", limit=120):
                    print(message.text)

                # Search for pinned messages in chat
                async for message in app.search_messages(chat_id, filter=enums.MessagesFilter.PINNED):
                    print(message.text)

                # Search for messages containing "hello" sent by yourself in chat
                async for message in app.search_messages(chat, "hello", from_user="me"):
                    print(message.text)
        r   ir   )r   r   r   r   r   r   r   N   )absminr   len)r    r   r   r   r   r   r   currenttotalr   messager   r   r   search_messages>   s(    ?

zSearchMessages.search_messages)__name__
__module____qualname__r	   MessagesFilterEMPTYr   intstrr   r   r(   r   r   r   r   r   <   s   


r   )typingr   r   r   r   Zpyrogramr   r   r   r	   r,   r-   r.   r/   r   r   r   r   r   r   <module>   s"   

"