o
    Xzj«  ã                   @   sz   d dl Z d dlZd dlZddlmZ ddlmZmZ ddlm	Z	 dd„ Z
G dd	„ d	e jƒZG d
d„ de	e jƒZdd„ ZdS )é    Né   )Úutils)ÚTLObjectÚtypes)Ú
ChatGetterc              
   Ã   sê   �|du rdS t  |¡s|f}tƒ }|D ]^}t|tƒr@|dk r%| |¡ q| t  t 	|¡¡t  t 
|¡¡t  t |¡¡h¡ qt|tƒrS|jdkrS| t  |¡¡ q|  |¡I dH }t|tjƒrj| jdd�I dH }| t  |¡¡ q|S )z>Helper util to turn the input chat or chats into a set of IDs.Nr   i‡VÔT)Ú
input_peer)r   Úis_list_likeÚsetÚ
isinstanceÚintÚaddÚupdateÚget_peer_idr   ÚPeerUserÚPeerChatÚPeerChannelr   ÚSUBCLASS_OF_IDÚget_input_entityÚInputPeerSelfÚget_me)ÚclientÚchatsÚresultÚchat© r   úQ/var/www/kodo/tsheker/venv/lib/python3.10/site-packages/telethon/events/common.pyÚ_into_id_set
   s,   €

ýr   c                   @   sN   e Zd ZdZddddœdd„Zeejddd„ƒƒZd	d
„ Z	dd„ Z
dd„ ZdS )ÚEventBuilderaH  
    The common event builder, with builtin support to filter per chat.

    Args:
        chats (`entity`, optional):
            May be one or more entities (username/peer/etc.), preferably IDs.
            By default, only matching chats will be handled.

        blacklist_chats (`bool`, optional):
            Whether to treat the chats as a blacklist instead of
            as a whitelist (default). This means that every chat
            will be handled *except* those specified in ``chats``
            which will be ignored if ``blacklist_chats=True``.

        func (`callable`, optional):
            A callable (async or not) function that should accept the event as input
            parameter, and return a value indicating whether the event
            should be dispatched or not (any truthy value will do, it
            does not need to be a `bool`). It works like a custom filter:

            .. code-block:: python

                @client.on(events.NewMessage(func=lambda e: e.is_private))
                async def handler(event):
                    pass  # code here
    NF)Úblacklist_chatsÚfuncc                C   s&   || _ t|ƒ| _d| _|| _d | _d S )NF)r   Úboolr   Úresolvedr   Ú_resolve_lock)Úselfr   r   r   r   r   r   Ú__init__D   s
   

zEventBuilder.__init__c                 C   s   dS )aO  
        Builds an event for the given update if possible, or returns None.

        `others` are the rest of updates that came in the same container
        as the current `update`.

        `self_id` should be the current user's ID, since it is required
        for some events which lack this information but still need it.
        Nr   )Úclsr   ÚothersÚself_idr   r   r   ÚbuildK   s    zEventBuilder.buildc              	   Ã   sx   �| j rdS | jst ¡ | _| j4 I dH š | j s$|  |¡I dH  d| _ W d  ƒI dH  dS 1 I dH s5w   Y  dS )zAHelper method to allow event builders to be resolved before usageNT)r!   r"   ÚasyncioÚLockÚ_resolve©r#   r   r   r   r   ÚresolveY   s   €
.ýzEventBuilder.resolvec                 Ã   s   �t || jƒI d H | _d S ©N)r   r   r,   r   r   r   r+   f   s   €zEventBuilder._resolvec                 C   sB   | j sdS | jdur|j| jv }|| jkrdS | jsdS |  |¡S )zç
        Returns a truthy value if the event passed the filter and should be
        used, or falsy otherwise. The return value may need to be awaited.

        The events must have been resolved before this can be called.
        NT)r!   r   Úchat_idr   r   )r#   ÚeventÚinsider   r   r   Úfilteri   s   


zEventBuilder.filterr.   )NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r$   ÚclassmethodÚabcÚabstractmethodr(   r-   r+   r2   r   r   r   r   r   )   s    r   c                       sR   e Zd ZdZdZd‡ fdd„	Zdd„ Zedd	„ ƒZd
d„ Z	dd„ Z
dd„ Z‡  ZS )ÚEventCommonaR  
    Intermediate class with common things to all events.

    Remember that this class implements `ChatGetter
    <telethon.tl.custom.chatgetter.ChatGetter>` which
    means you have access to all chat properties and methods.

    In addition, you can access the `original_update`
    field which contains the original :tl:`Update`.
    ÚEventNc                    s,   t ƒ j||d� i | _d | _|| _d | _d S )N)Ú	broadcast)Úsuperr$   Ú	_entitiesÚ_clientÚ_message_idÚoriginal_update)r#   Ú	chat_peerÚmsg_idr<   ©Ú	__class__r   r   r$   �   s
   
zEventCommon.__init__c                 C   s<   || _ | jrt | j| j|j¡\| _| _dS d | _| _dS )zR
        Setter so subclasses can act accordingly when the client is set.
        N)	r?   Ú
_chat_peerr   Ú_get_entity_pairr/   r>   Ú_mb_entity_cacheÚ_chatÚ_input_chatr,   r   r   r   Ú_set_client–   s   ÿzEventCommon._set_clientc                 C   s   | j S )zH
        The `telethon.TelegramClient` that created this event.
        )r?   ©r#   r   r   r   r   ¡   s   zEventCommon.clientc                 C   s   t  |  ¡ ¡S r.   ©r   Úpretty_formatÚto_dictrL   r   r   r   Ú__str__¨   s   zEventCommon.__str__c                 C   s   t j|  ¡ dd�S )Nr   )ÚindentrM   rL   r   r   r   Ú	stringify«   s   zEventCommon.stringifyc                 C   s"   dd„ | j  ¡ D ƒ}| j|d< |S )Nc                 S   s"   i | ]\}}|d  dkr||“qS )r   Ú_r   )Ú.0ÚkÚvr   r   r   Ú
<dictcomp>¯   s   " z'EventCommon.to_dict.<locals>.<dictcomp>rS   )Ú__dict__ÚitemsÚ_event_name)r#   Údr   r   r   rO   ®   s   
zEventCommon.to_dict)NNN)r3   r4   r5   r6   rZ   r$   rK   Úpropertyr   rP   rR   rO   Ú__classcell__r   r   rD   r   r:   ‚   s    

r:   c                 C   s2   t | dƒrd | j¡| j_| S t d | ¡¡ | S )z4Decorator to rename cls.Event 'Event' as 'cls.Event'r;   z{}.Eventz$Class {} does not have a inner Event)ÚhasattrÚformatr3   r;   rZ   ÚwarningsÚwarn)r%   r   r   r   Úname_inner_event´   s
   
ÿrb   )r8   r)   r`   Ú r   Útlr   r   Útl.custom.chatgetterr   r   ÚABCr   r:   rb   r   r   r   r   Ú<module>   s    Y2