
    ;Si.F                     P    d dl mZmZmZ ddlmZ ddlmZ e G d de             Zy)   )EventBuilderEventCommonname_inner_event   )utils)typesc                   8    e Zd ZdZedd       Z G d de      Zy)
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                 
   t        |t        j                        rQ|j                  sE| j	                  t        j
                  |j                        |j                  |j                        S t        |t        j                        r>|j                  s2| j	                  |j                  |j                  |j                        S t        |t        j                        rI| j	                  t        j                  |j                        |j                  xs d|j                        S t        |t        j                        r;| j	                  t        j                  |j                        d|j                        S t        |t        j                   t        j"                  f      r t        |j$                  t        j&                        r|j$                  }|j$                  j(                  }t        |t        j*                        r| j	                  |d|j,                        S t        |t        j.                        rF|j0                  g|j2                  k(  xs |j,                  }| j	                  |||j2                        S t        |t        j4                        rI| j	                  ||j,                  rt7        j8                  |j,                        nd|j                        S t        |t        j:                        r)| j	                  ||j2                  d|j<                        S t        |t        j>                        r)| j	                  |d|j,                  |j<                        S t        |t        j@                        r(| j	                  ||j,                  |j<                        S t        |t        jB                        r(| j	                  ||j,                  |jD                        S t        |t        jF                        r| j	                  ||j,                  d      S t        |t        jH                        r*|jJ                  r| j	                  ||jL                  g	      S t        |t        jN                        r| j	                  ||jP                  
      S y t        |t        jR                        rtU        |jV                        tU        |jX                        k7  rq| j	                  t        j
                  |j                        |j                  |jV                  r|jZ                  nd |jX                  r|jZ                        S d       S y y )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   s          _/var/www/OnlineNewsSite/project/venv/lib/python3.12/site-packages/telethon/events/chataction.pybuildzChatAction.build"   su   
 fe??@99U..v/@/@A%+__!'  0 0  : :;FMM99V[[%+__!'  0 0  > >?99U^^FNN;&,&7&7&?4#)>>  3 3  A AB99U^^FNN;'+#)>>  3 3 &&(E(E"G HV^^U-A-AB..C^^**F&%"E"EFyy*.'*{{ ! 4 4 FE$B$BC ]]Ov||;Kyy*2'-|| ! 5 5 FE$E$EFyyMP[[5+<+<S[[+I^b'-~~ ! 7 7 FE$A$AByy'-||)-+1<< ! 9 9 FE$D$DEyy)-'*{{+1<< ! 9 9 FE$D$DEyy'*{{+1<< ! 9 9 FE$D$DEyy'*{{+1<< ! 9 9 FE$F$FGyy'*{{+/ ! 1 1 FE$A$ABs||yy*-*=*=)> ! @ @FE$@$@Ayy+1<< ! 9 9 B  > >?//0D9P9P4QQ
 99U..v/@/@A#)>>9?9O9OfooUY:@:Q:Qv  ] ] X\  ] ] R @    c                        e Zd ZdZ	 	 	 d fd	Z fdZd Zd Zd Zd Z	d Z
ed	        Zd
 Zed        Zd Zed        Zd Zed        Zd Zed        Zed        Zd Zed        Zd Zed        Z xZS )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.
        c                 4   t        |t        j                        r|| _        |j                  }nd | _        t
        |   ||r|d   nd        |d u| _        || _        d | _	        |d u| _
        t        |t        j                        r|nd | _        d | _        d | _        dx| _        x| _        x| _        x| _        | _        |du rd| _        n|rd| _        || _        |du s|||k(  rd| _        n|rd| _        || _        t)        |      | _        t        |t,              r)|D cg c]  }t/        j0                  |       c}| _        n%|rt/        j0                  |      g| _        ng | _        d | _        d | _        || _        |
| _        |	 | _        y c c}w )N    )	chat_peermsg_idFT)r   r   r'   action_messagepeer_idsuper__init__new_pin_pin_ids_pinned_messagesr   Photor4   	_added_by
_kicked_by
user_addeduser_joined	user_leftuser_kickedunpinr<   r   listr   r.   	_user_ids_users_input_usersr   r   )selfwherer   r   r   r   r   r   r   r   r   u	__class__s               rE   rQ   zChatAction.Event.__init__   s    %!5!56&+#&*# Gu7WQZPTU"$.DL#DM$(D!&d2DN'	5;;?	T J "DN"DO056DO 6d. 6 6 4:4#' "&!) D U%69;M!%#' "+=DL%&@E!F1%"3"3A"6!F"'"3"3E":!;!#DK $D&DN&DN DJ "Gs   &Fc                     t         |   |       | j                  r(| j                  j                  || j                  d        y y )N)rP   _set_clientrN   _finish_init	_entities)ra   clientrd   s     rE   rf   zChatAction.Event._set_client   s:    G'""##00N #rG   c                    K    | j                   j                  | j                          d{   g|i | d{   S 7 7 w)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ra   argskwargss      rE   respondzChatAction.Event.respond   sN      322))++>.2>6<> > >+>s   *AAAAAAc                   K   | j                   s | j                  |i | d{   S | j                   j                  |d<    | j                  j                  | j                          d{   g|i | d{   S 7 [7 7 w)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.
            Nr7   )rN   rq   idrk   rl   rm   rn   s      rE   replyzChatAction.Event.reply   s      &&)T\\4:6:::!%!4!4!7!7F:222))++>.2>6<> > > ; ,>s4   "BB AB+B,B;B<BBBc                    K   | j                   sy | j                  j                  | j                          d{   | j                   gg|i | d{   S 7  7 w)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)rN   rk   delete_messagesrm   rn   s      rE   deletezChatAction.Event.delete   se      &&555))++d.A.A-B  +s!   7AAAAAAc                    K   | j                   | j                          d{    | j                   r| j                   d   S y7  w)z
            If ``new_pin`` is `True`, this returns the `Message
            <telethon.tl.custom.message.Message>` object that was pinned.
            NrK   )rT   get_pinned_messagesra   s    rE   get_pinned_messagez#ChatAction.Event.get_pinned_message
  sJ     
 $$,..000$$,,Q// % 1s    AA!Ac                 
  K   | j                   s| j                   S | j                          d{   }|r>| j                  j                  | j                  | j                          d{   | _        | j
                  S 7 P7 w)z
            If ``new_pin`` is `True`, this returns a `list` of `Message
            <telethon.tl.custom.message.Message>` objects that were pinned.
            N)ids)rS   rm   rk   get_messages_input_chatrT   )ra   chats     rE   ry   z$ChatAction.Event.get_pinned_messages  sw     
 ==}}$,,..D.2ll.G.G$$$-- /H /9 )9% ((( /)9s!   ,BA?:B)B*BBc                     | j                   ret        | j                   t        j                        sA| j                  j                  t        j                  | j                               }|r|| _         | j                   S )zY
            The user who added ``users``, if applicable (`None` otherwise).
            )rV   r   r   Userrh   getr   r.   )ra   abys     rE   r   zChatAction.Event.added_by$  sS    
 ~~j&Lnn(():):4>>)JK%(DN>>!rG   c                    K   | j                   s>| j                  r2| j                  j                  | j                         d{   | _        | j                  S 7 w)zT
            Returns `added_by` but will make an API call if necessary.
            N)r   rV   rk   
get_entityrz   s    rE   get_added_byzChatAction.Event.get_added_by0  sB      ==T^^'+||'>'>t~~'N!N>>! "O   AAAAc                     | j                   ret        | j                   t        j                        sA| j                  j                  t        j                  | j                               }|r|| _         | j                   S )zZ
            The user who kicked ``users``, if applicable (`None` otherwise).
            )rW   r   r   r   rh   r   r   r.   )ra   kbys     rE   r   zChatAction.Event.kicked_by9  sS    
 z$//5::'Nnn(():):4??)KL&)DO??"rG   c                    K   | j                   s>| j                  r2| j                  j                  | j                         d{   | _        | j                  S 7 w)zU
            Returns `kicked_by` but will make an API call if necessary.
            N)r   rW   rk   r   rz   s    rE   get_kicked_byzChatAction.Event.get_kicked_byE  sB      >>doo(,(?(?(P"P??" #Qr   c                 :    | j                   r| j                  d   S y)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.
            rK   N)r   r_   rz   s    rE   userzChatAction.Event.userN  s     zz{{1~% rG   c                 v   K   | j                   s| j                          d{   r| j                  d   S y7 w)zP
            Returns `user` but will make an API call if necessary.
            NrK   )r   	get_usersr_   rz   s    rE   get_userzChatAction.Event.get_userY  s1      zz4>>#333{{1~% 4    979c                 :    | j                   r| j                  d   S y)zF
            Input version of the ``self.user`` property.
            rK   N)input_usersr`   rz   s    rE   
input_userzChatAction.Event.input_user`  s#    
 ((++  rG   c                 v   K   | j                   s| j                          d{   r| j                  d   S y7 w)zV
            Returns `input_user` but will make an API call if necessary.
            NrK   )r   get_input_usersr`   rz   s    rE   get_input_userzChatAction.Event.get_input_userh  s9      )=)=)?#?#?((++ $@r   c                 :    | j                   r| j                   d   S y)zQ
            Returns the marked signed ID of the first user, if any.
            rK   Nr^   rz   s    rE   r"   zChatAction.Event.user_ido  s    
 ~~~~a(( rG   c                     | j                   sg S | j                  :| j                   D cg c]  }|| j                  v r| j                  |   ! c}| _        | j                  S c c}w )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.
            )r^   r_   rh   ra   r"   s     rE   r   zChatAction.Event.usersw  s`     >>	{{" $(>>$..0 NN7+ ;;s   $A!c                   K   | j                   sg S | j                  +t        | j                        t        | j                         k7  r| j                  ru| j                  j                          d{    | j                  j                  D cg c].  }t        |t        j                  t        j                  f      r|0 c}| _        | j                  S 7 cc c}w w)zQ
            Returns `users` but will make an API call if necessary.
            N)r^   r   lenr_   rN   _reload_messageaction_entitiesr   r   r   	UserEmptyra   rc   s     rE   r   zChatAction.Event.get_users  s      >>	 

"c$++&6#dnn:M&MSWSfSf))99;;;#22BBE!!ejj%//%BC E ;; <Es$   A/C1C2C3CCCc                 
   | j                   `| j                  rTg | _         | j                  D ]>  }	 | j                   j                  t        j                  | j
                  |                @ | j                   xs g S # t        t        f$ r Y nw xY w	 | j                   j                  | j                  j                  j                  t        j                  |      d         j                                # t        $ r Y w xY w)zG
            Input version of the ``self.users`` property.
            rK   )r`   r^   appendr   get_input_peerrh   KeyError	TypeErrorrk   _mb_entity_cacher   
resolve_id_as_input_peerAttributeErrorr   s     rE   r   zChatAction.Event.input_users  s    
   (T^^$&!#~~ G))001E1EdnnU\F]1^_ 	  $$** %i0 ))001N1N1R1R!,,W5a82::H.:JL ) s$   ;A==BBA"C66	DDc                   K   | j                   sg S | j                  +t        | j                        t        | j                         k7  rr| j                  rf| j                  j
                  D cg c]A  }t        |t        j                  t        j                  f      rt        j                  |      C c}| _        | j                  xs g S c c}w w)zW
            Returns `input_users` but will make an API call if necessary.
            )r^   r   r   r`   rN   r   r   r   r   r   r   r   r   s     rE   r   z ChatAction.Event.get_input_users  s      >>	   (C0A0A,Bc$..FY,Y_c_r_r "00@@%E!!ejj%//%BC ((+%E!
 $$**%Es   A*C,AC
2Cc                 :    | j                   r| j                   dd S y)zL
            Returns the marked signed ID of the users, if any.
            Nr   rz   s    rE   user_idszChatAction.Event.user_ids  s    
 ~~~~a(( rG   )	NNNNNNNNN)__name__
__module____qualname____doc__rQ   rf   rq   rt   rw   r{   ry   propertyr   r   r   r   r   r   r   r   r"   r   r   r   r   r   __classcell__)rd   s   @rE   r   rI   z   s    '	R -1<@SW5	!n	O
	>	>	$		0	) 
		" 
		"	" 
		# 
		#	# 
	& 
	&	& 
	, 
	,	, 
	) 
	) 
	 
	&	  
	+ 
	+0	+  
	) 
	)rG   r   )NN)r   r   r   r   classmethodrF   r   r    rG   rE   r
   r
      s.    4 U] U]nP) P)rG   r
   N)	commonr   r   r    r   tlr   r
   r   rG   rE   <module>r      s/    ? ?   C) C) C)rG   