o
    Xzjœ  ã                   @   s:   d dl Z ddlmZmZ ddlmZ G dd„ de jƒZdS )é    Né   )ÚerrorsÚutils)Útypesc                   @   s„   e Zd ZdZd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
edd„ ƒZedd„ ƒZedd„ ƒZdd„ ZdS )Ú
ChatGetterz’
    Helper base class that introduces the `chat`, `input_chat`
    and `chat_id` properties and `get_chat` and `get_input_chat`
    methods.
    N)Ú
input_chatÚchatÚ	broadcastc                C   s"   || _ || _|| _|| _d | _d S ©N)Ú
_chat_peerÚ_input_chatÚ_chatÚ
_broadcastÚ_client)ÚselfÚ	chat_peerr   r   r	   © r   úX/var/www/kodo/tsheker/venv/lib/python3.10/site-packages/telethon/tl/custom/chatgetter.pyÚ__init__   s
   
zChatGetter.__init__c                 C   s   | j S )a|  
        Returns the :tl:`User`, :tl:`Chat` or :tl:`Channel` where this object
        belongs to. It may be `None` if Telegram didn't send the chat.

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

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

        If you're using `telethon.events`, use `get_chat()` instead.
        )r   ©r   r   r   r   r      s   zChatGetter.chatc                 Ã   sr   �| j du st| j ddƒr6|  ¡ I dH r6z| j | j¡I dH | _ W | j S  ty5   |  ¡ I dH  Y | j S w | j S )a  
        Returns `chat`, but will make an API call to find the
        chat unless it's already cached.

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

        If you need to call a method which needs
        this chat, use `get_input_chat()` instead.
        NÚmin)r   ÚgetattrÚget_input_chatr   Ú
get_entityr   Ú
ValueErrorÚ_refetch_chatr   r   r   r   Úget_chat#   s   €ÿÿþþzChatGetter.get_chatc                 C   s\   | j du r+| jr+| jr+z| jj tj| jdd�¡ ¡ | _ W | j S  ty*   Y | j S w | j S )a   
        This :tl:`InputPeer` is the input version of the chat where the
        message was sent. Similarly to `input_sender
        <telethon.tl.custom.sendergetter.SenderGetter.input_sender>`, 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 doesn't
        have enough information available.
        NF)Úadd_mark)	r   r   r   Ú_mb_entity_cacheÚgetr   Úget_peer_idÚ_as_input_peerÚAttributeErrorr   r   r   r   r   7   s   ÿÿýýzChatGetter.input_chatc                 Ã   s†   �| j du r@| jr@| jr@z'| j}| j d¡2 z3 dH W }|j|kr.|j| _|j| _ W | jS q6 W | jS  t	j
y?   Y | jS w | jS )z|
        Returns `input_chat`, but will make an API call to find the
        input chat unless it's already cached.
        Néd   )r   Úchat_idr   Úiter_dialogsÚidÚentityr   Úinput_entityr   r   ÚRPCError)r   ÚtargetÚdr   r   r   r   L   s$   €
ùÿýýzChatGetter.get_input_chatc                 C   s   | j r	t | j ¡S dS )aæ  
        Returns the marked chat integer ID. Note that this value **will
        be different** from ``peer_id`` for incoming private messages, since
        the chat *to* which the messages go is to your own person, but
        the *chat* itself is with the one who sent the message.

        TL;DR; this gets the ID that you expect.

        If there is a chat in the object, `chat_id` will *always* be set,
        which is why you should use it instead of `chat.id <chat>`.
        N)r   r   r    r   r   r   r   r$   _   s   zChatGetter.chat_idc                 C   s   | j r
t| j tjƒS dS )zÛ
        `True` if the message was sent as a private message.

        Returns `None` if there isn't enough information
        (e.g. on `events.MessageDeleted <telethon.events.messagedeleted.MessageDeleted>`).
        N)r   Ú
isinstancer   ÚPeerUserr   r   r   r   Ú
is_privaten   s   zChatGetter.is_privatec                 C   sV   | j du rt| jdƒrt| jjƒ| _ t| jtjƒr$| j du r dS | j  S t| jtj	ƒS )zÜ
        True if the message was sent on a group or megagroup.

        Returns `None` if there isn't enough information
        (e.g. on `events.MessageDeleted <telethon.events.messagedeleted.MessageDeleted>`).
        Nr	   )
r   Úhasattrr   Úboolr	   r,   r   r   ÚPeerChannelÚPeerChatr   r   r   r   Úis_groupx   s   	
zChatGetter.is_groupc                 C   s   t | jtjƒS )z9`True` if the message was sent on a megagroup or channel.)r,   r   r   r1   r   r   r   r   Ú
is_channelŒ   s   zChatGetter.is_channelc                 Ã   s   �dS )zB
        Re-fetches chat information through other means.
        Nr   r   r   r   r   r   “   s    zChatGetter._refetch_chatr
   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úpropertyr   r   r   r   r$   r.   r3   r4   r   r   r   r   r   r      s$    



	

r   )ÚabcÚ r   r   Útlr   ÚABCr   r   r   r   r   Ú<module>   s    