o
    Xzj.F  ã                   @   sD   d dl mZmZmZ ddlmZ ddlmZ eG dd„ deƒƒZdS )é   )ÚEventBuilderÚEventCommonÚname_inner_eventé   )Úutils)Útypesc                   @   s.   e Zd ZdZeddd„ƒZG dd„ deƒZdS )Ú
ChatActionaO  
    Occurs on certain chat actions:

    * Whenever a new chat is created.
    * Whenever a chat's title or photo is changed or removed.
    * Whenever a new message is pinned.
    * Whenever a user scores in a game.
    * Whenever a user joins or is added to the group.
    * Whenever a user is removed or leaves a group if it has
      less than 50 members or the removed user was a bot.

    Note that "chat" refers to "small group, megagroup and broadcast
    channel", whereas "group" refers to "small group and megagroup" only.

    Example
        .. code-block:: python

            from telethon import events

            @client.on(events.ChatAction)
            async def handler(event):
                # Welcome every new user
                if event.user_joined:
                    await event.reply('Welcome to the group!')
    Nc                 C   s®  t |tjƒr|js| jt |j¡|j|jd�S t |tjƒr+|js+| j|j	|j|jd�S t |tj
ƒrA| jt |j¡|jp<d|jd�S t |tjƒrT| jt |j¡d|jd�S t |tjtjfƒ�r#t |jtjƒ�r#|j}|jj}t |tjƒr|| j|d|jd�S t |tjƒr•|jg|jkp‹|j}| j|||jd�S t |tjƒr­| j||jr§t |j¡nd|jd�S t |tjƒr¾| j||jd|jd�S t |tjƒrÏ| j|d|j|jd�S t |tj ƒrß| j||j|jd�S t |tj!ƒrï| j||j|j"d�S t |tj#ƒrþ| j||jdd�S t |tj$ƒ�r|j%�r| j||j&gd	�S t |tj'ƒ�r!| j||j(d
�S d S t |tj)ƒ�rSt*|j+ƒt*|j,ƒk�rU| jt |j¡|j|j+�rE|j-nd |j,�rO|j-d�S d d�S d S d S )N)Úpin_idsÚpinT)Úadded_byÚusers)Ú	kicked_byr   )r   ÚcreatedÚ	new_title)r   r   r   )r   r   )r   Ú	new_photo)r	   )Ú	new_score)r   r   r   ).Ú
isinstancer   ÚUpdatePinnedChannelMessagesÚpinnedÚEventÚPeerChannelÚ
channel_idÚmessagesÚUpdatePinnedMessagesÚpeerÚUpdateChatParticipantAddÚPeerChatÚchat_idÚ
inviter_idÚuser_idÚUpdateChatParticipantDeleteÚUpdateNewMessageÚUpdateNewChannelMessageÚmessageÚMessageServiceÚactionÚMessageActionChatJoinedByLinkÚfrom_idÚMessageActionChatAddUserÚ	sender_idr   ÚMessageActionChatDeleteUserr   Úget_peer_idÚMessageActionChatCreateÚtitleÚMessageActionChannelCreateÚMessageActionChatEditTitleÚMessageActionChatEditPhotoÚphotoÚMessageActionChatDeletePhotoÚMessageActionPinMessageÚreply_toÚreply_to_msg_idÚMessageActionGameScoreÚscoreÚUpdateChannelParticipantÚboolÚnew_participantÚprev_participantÚactor_id)ÚclsÚupdateÚothersÚself_idÚmsgr%   r   © rB   úU/var/www/kodo/tsheker/venv/lib/python3.10/site-packages/telethon/events/chataction.pyÚbuild"   s´   þþþþÿþþþþýýþþþÿÿÿýýúzChatAction.buildc                       sì   e Zd ZdZ			d-‡ fdd„	Z‡ fdd„Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
edd„ ƒZdd„ Zedd„ ƒZ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d%d&„ Zed'd(„ ƒZd)d*„ Zed+d,„ ƒZ‡  ZS ).zChatAction.Eventa  
        Represents the event of a new chat action.

        Members:
            action_message  (`MessageAction <https://tl.telethon.dev/types/message_action.html>`_):
                The message invoked by this Chat Action.

            new_pin (`bool`):
                `True` if there is a new pin.

            new_photo (`bool`):
                `True` if there's a new chat photo (or it was removed).

            photo (:tl:`Photo`, optional):
                The new photo (or `None` if it was removed).

            user_added (`bool`):
                `True` if the user was added by some other.

            user_joined (`bool`):
                `True` if the user joined on their own.

            user_left (`bool`):
                `True` if the user left on their own.

            user_kicked (`bool`):
                `True` if the user was kicked by some other.

            created (`bool`, optional):
                `True` if this chat was just created.

            new_title (`str`, optional):
                The new title string for the chat, if applicable.

            new_score (`str`, optional):
                The new score string for the game, if applicable.

            unpin (`bool`):
                `True` if the existing pin gets unpinned.
        Nc                    sP  t |tjƒr|| _|j}nd | _tƒ j||r|d nd d� |d u| _|| _d | _	|d u| _
t |tjƒr6|nd | _d | _d | _d | _ | _ | _ | _| _|du rVd| _n|r^d| _|| _|du sj|d urn||krnd| _n|rvd| _|| _t|ƒ| _t |tƒr‰dd„ |D ƒ| _n|r“t |¡g| _ng | _d | _d | _|| _|
| _|	 | _d S )Né    )Ú	chat_peerÚmsg_idFTc                 S   s   g | ]}t  |¡‘qS rB   )r   r+   ©Ú.0ÚurB   rB   rC   Ú
<listcomp>Ï   s    z-ChatAction.Event.__init__.<locals>.<listcomp>)r   r   r$   Úaction_messageÚpeer_idÚsuperÚ__init__Únew_pinÚ_pin_idsÚ_pinned_messagesr   ÚPhotor1   Ú	_added_byÚ
_kicked_byÚ
user_addedÚuser_joinedÚ	user_leftÚuser_kickedÚunpinr9   r   ÚlistÚ	_user_idsr   r+   Ú_usersÚ_input_usersr   r   )ÚselfÚwherer   r   r   r   r   r   r	   r
   r   ©Ú	__class__rB   rC   rO   ¤   sJ   

ÿÿ

zChatAction.Event.__init__c                    s,   t ƒ  |¡ | jr| j || jd ¡ d S d S )N)rN   Ú_set_clientrL   Ú_finish_initÚ	_entities)r_   Úclientra   rB   rC   rc   Û   s   ÿzChatAction.Event._set_clientc                 Ï   s,   �| j j|  ¡ I dH g|¢R i |¤ŽI dH S )zÉ
            Responds to the chat action message (not as a reply). Shorthand for
            `telethon.client.messages.MessageMethods.send_message` with
            ``entity`` already set.
            N)Ú_clientÚsend_messageÚget_input_chat©r_   ÚargsÚkwargsrB   rB   rC   Úrespondà   s   €ÿÿÿzChatAction.Event.respondc                 Ï   sT   �| j s| j|i |¤ŽI dH S | j j|d< | jj|  ¡ I dH g|¢R i |¤ŽI dH S )a   
            Replies to the chat action message (as a reply). Shorthand for
            `telethon.client.messages.MessageMethods.send_message` with
            both ``entity`` and ``reply_to`` already set.

            Has the same effect as `respond` if there is no message.
            Nr4   )rL   rm   Úidrg   rh   ri   rj   rB   rB   rC   Úreplyé   s   €ÿÿÿzChatAction.Event.replyc                 Ï   s<   �| j sdS | jj|  ¡ I dH | j gg|¢R i |¤ŽI dH S )a”  
            Deletes the chat action message. You're responsible for checking
            whether you have the permission to do so, or to except the error
            otherwise. Shorthand for
            `telethon.client.messages.MessageMethods.delete_messages` with
            ``entity`` and ``message_ids`` already set.

            Does nothing if no message action triggered this event.
            N)rL   rg   Údelete_messagesri   rj   rB   rB   rC   Údeleteø   s   €
ÿþþzChatAction.Event.deletec                 Ã   s.   �| j du r|  ¡ I dH  | j r| j d S dS )z—
            If ``new_pin`` is `True`, this returns the `Message
            <telethon.tl.custom.message.Message>` object that was pinned.
            NrE   )rR   Úget_pinned_messages©r_   rB   rB   rC   Úget_pinned_message
  s   €

ÿz#ChatAction.Event.get_pinned_messagec                 Ã   sB   �| j s| j S |  ¡ I dH }|r| jj| j| j d�I dH | _| jS )z¡
            If ``new_pin`` is `True`, this returns a `list` of `Message
            <telethon.tl.custom.message.Message>` objects that were pinned.
            N)Úids)rQ   ri   rg   Úget_messagesÚ_input_chatrR   )r_   ÚchatrB   rB   rC   rr     s   €ÿz$ChatAction.Event.get_pinned_messagesc                 C   ó8   | j rt| j tjƒs| j t | j ¡¡}|r|| _ | j S )zY
            The user who added ``users``, if applicable (`None` otherwise).
            )rT   r   r   ÚUserre   Úgetr   r+   )r_   ÚabyrB   rB   rC   r   $  ó
   zChatAction.Event.added_byc                 Ã   ó*   �| j s| jr| j | j¡I dH | _| jS )zT
            Returns `added_by` but will make an API call if necessary.
            N)r   rT   rg   Ú
get_entityrs   rB   rB   rC   Úget_added_by0  ó   €zChatAction.Event.get_added_byc                 C   ry   )zZ
            The user who kicked ``users``, if applicable (`None` otherwise).
            )rU   r   r   rz   re   r{   r   r+   )r_   ÚkbyrB   rB   rC   r   9  r}   zChatAction.Event.kicked_byc                 Ã   r~   )zU
            Returns `kicked_by` but will make an API call if necessary.
            N)r   rU   rg   r   rs   rB   rB   rC   Úget_kicked_byE  r�   zChatAction.Event.get_kicked_byc                 C   ó   | j r| jd S dS )zÑ
            The first user that takes part in this action. For example, who joined.

            Might be `None` if the information can't be retrieved or
            there is no user taking part.
            rE   N)r   r]   rs   rB   rB   rC   ÚuserN  s   
ÿzChatAction.Event.userc                 Ã   ó$   �| j s|  ¡ I dH r| jd S dS )zP
            Returns `user` but will make an API call if necessary.
            NrE   )r   Ú	get_usersr]   rs   rB   rB   rC   Úget_userY  ó   €
ÿzChatAction.Event.get_userc                 C   r„   )zF
            Input version of the ``self.user`` property.
            rE   N)Úinput_usersr^   rs   rB   rB   rC   Ú
input_user`  ó   
ÿzChatAction.Event.input_userc                 Ã   r†   )zV
            Returns `input_user` but will make an API call if necessary.
            NrE   )rŠ   Úget_input_usersr^   rs   rB   rB   rC   Úget_input_userh  r‰   zChatAction.Event.get_input_userc                 C   s   | j r| j d S dS )zQ
            Returns the marked signed ID of the first user, if any.
            rE   N©r\   rs   rB   rB   rC   r   o  rŒ   zChatAction.Event.user_idc                    s0   ˆ j sg S ˆ jdu r‡ fdd„ˆ j D ƒˆ _ˆ jS )zÒ
            A list of users that take part in this action. For example, who joined.

            Might be empty if the information can't be retrieved or there
            are no users taking part.
            Nc                    s    g | ]}|ˆ j v rˆ j | ‘qS rB   )re   )rI   r   rs   rB   rC   rK   ƒ  s
    
þz*ChatAction.Event.users.<locals>.<listcomp>)r\   r]   rs   rB   rs   rC   r   w  s   

þzChatAction.Event.usersc                 Ã   sZ   �| j sg S | jdu st| jƒt| j ƒkr*| jr*| j ¡ I dH  dd„ | jjD ƒ| _| jS )zQ
            Returns `users` but will make an API call if necessary.
            Nc                 S   s"   g | ]}t |tjtjfƒr|‘qS rB   )r   r   rz   Ú	UserEmptyrH   rB   rB   rC   rK   •  s    þÿz.ChatAction.Event.get_users.<locals>.<listcomp>)r\   r   Úlenr]   rL   Ú_reload_messageÚaction_entitiesrs   rB   rB   rC   r‡   ‹  s   €$ÿzChatAction.Event.get_usersc              
   C   sš   | j du rH| jrHg | _ | jD ]9}z| j  t | j| ¡¡ W q ttfy)   Y nw z| j  | jj	 
t |¡d ¡ ¡ ¡ W q tyG   Y qw | j pLg S )zG
            Input version of the ``self.users`` property.
            NrE   )r^   r\   Úappendr   Úget_input_peerre   ÚKeyErrorÚ	TypeErrorrg   Ú_mb_entity_cacher{   Ú
resolve_idÚ_as_input_peerÚAttributeError)r_   r   rB   rB   rC   rŠ   ›  s(   
ÿÿÿÿ
zChatAction.Event.input_usersc                 Ã   sN   �| j sg S | jdu st| jƒt| j ƒkr"| jr"dd„ | jjD ƒ| _| jp&g S )zW
            Returns `input_users` but will make an API call if necessary.
            Nc                 S   s(   g | ]}t |tjtjfƒrt |¡‘qS rB   )r   r   rz   r�   r   r•   rH   rB   rB   rC   rK   ½  s    ýÿz4ChatAction.Event.get_input_users.<locals>.<listcomp>)r\   rŠ   r‘   r^   rL   r“   rs   rB   rB   rC   r�   ´  s   €$þ
z ChatAction.Event.get_input_usersc                 C   s   | j r
| j dd… S dS )zL
            Returns the marked signed ID of the users, if any.
            Nr�   rs   rB   rB   rC   Úuser_idsÄ  s   ÿzChatAction.Event.user_ids)	NNNNNNNNN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rO   rc   rm   ro   rq   rt   rr   Úpropertyr   r€   r   rƒ   r…   rˆ   r‹   rŽ   r   r   r‡   rŠ   r�   rœ   Ú__classcell__rB   rB   ra   rC   r   z   sD    )þ7	
	
	





r   )NN)r�   rž   rŸ   r    ÚclassmethodrD   r   r   rB   rB   rB   rC   r      s
    Wr   N)	Úcommonr   r   r   Ú r   Útlr   r   rB   rB   rB   rC   Ú<module>   s
    