U
    ¯ªh  ã                   @   s*   d dl Z ddlmZ G dd„ de jƒZdS )é    Né   )Úutilsc                   @   s^   e Zd ZdZddddœdd„Zedd„ ƒZdd	„ Zed
d„ ƒZdd„ Z	edd„ ƒZ
dd„ ZdS )ÚSenderGetterzœ
    Helper base class that introduces the `sender`, `input_sender`
    and `sender_id` properties and `get_sender` and `get_input_sender`
    methods.
    N)ÚsenderÚinput_senderc                C   s   || _ || _|| _d | _d S )N)Ú
_sender_idÚ_senderÚ_input_senderÚ_client)ÚselfÚ	sender_idr   r   © r   úC/tmp/pip-unpacked-wheel-c81u5j2r/telethon/tl/custom/sendergetter.pyÚ__init__   s    zSenderGetter.__init__c                 C   s   | j S )aq  
        Returns the :tl:`User` or :tl:`Channel` that sent this object.
        It may be `None` if Telegram didn't send the sender.

        If you only need the ID, use `sender_id` instead.

        If you need to call a method which needs
        this chat, use `input_sender` instead.

        If you're using `telethon.events`, use `get_sender()` instead.
        )r   ©r   r   r   r   r      s    zSenderGetter.senderc                 Ã   s‚   | j dkst| j ddƒr||  ¡ I dH r|| j dks>t| j ddƒr|z| j | j¡I dH | _ W n" tk
rz   |  ¡ I dH  Y nX | j S )a  
        Returns `sender`, but will make an API call to find the
        sender unless it's already cached.

        If you only need the ID, use `sender_id` instead.

        If you need to call a method which needs
        this sender, use `get_input_sender()` instead.
        NÚmin)r   ÚgetattrÚget_input_senderr
   Z
get_entityr	   Ú
ValueErrorÚ_refetch_senderr   r   r   r   Ú
get_sender!   s    ÿÿzSenderGetter.get_senderc                 C   sV   | j dkrP| jrP| jrPz$| jj t | j¡d ¡ ¡ | _ W n tk
rN   Y nX | j S )a®  
        This :tl:`InputPeer` is the input version of the user/channel who
        sent the message. Similarly to `input_chat
        <telethon.tl.custom.chatgetter.ChatGetter.input_chat>`, this doesn't
        have things like username or similar, but still useful in some cases.

        Note that this might not be available if the library can't
        find the input chat, or if the message a broadcast on a channel.
        Nr   )	r	   r   r
   Z_mb_entity_cacheÚgetr   Z
resolve_idZ_as_input_peerÚAttributeErrorr   r   r   r   r   =   s    ÿzSenderGetter.input_senderc                 Ã   s*   | j dkr$| jr$| jr$|  ¡ I dH  | jS )z€
        Returns `input_sender`, but will make an API call to find the
        input sender unless it's already cached.
        N)r   r   r
   r   r	   r   r   r   r   r   P   s    zSenderGetter.get_input_senderc                 C   s   | j S )zÚ
        Returns the marked sender integer ID, if present.

        If there is a sender in the object, `sender_id` will *always* be set,
        which is why you should use it instead of `sender.id <sender>`.
        )r   r   r   r   r   r   Y   s    zSenderGetter.sender_idc                 Ã   s   dS )zD
        Re-fetches sender information through other means.
        Nr   r   r   r   r   r   c   s    zSenderGetter._refetch_sender)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úpropertyr   r   r   r   r   r   r   r   r   r   r      s   

	
	r   )ÚabcÚ r   ÚABCr   r   r   r   r   Ú<module>   s   