
    ;SiZ2                         d dl Z d dlZd dlZddlmZmZmZ ddlmZ ddl	m
Z
 ddlmZ dZd	Zi Zd
Z G d d      Ze G d de             Zy)    N   )EventBuilderEventCommonname_inner_event   )utils)types)SenderGetterd      g      ?c                   "    e Zd ZdZd Zd Zd Zy)	AlbumHacka  
    When receiving an album from a different data-center, they will come in
    separate `Updates`, so we need to temporarily remember them for a while
    and only after produce the event.

    Of course events are not designed for this kind of wizardy, so this is
    a dirty hack that gets the job done.

    When cleaning up the code base we may want to figure out a better way
    to do this, or just leave the album problem to the users; the update
    handling code is bad enough as it is.
    c                     t        j                  |      | _        || _        |j                  j                         t        z   | _        |j                  j                  | j                                y N)
weakrefref_client_eventlooptime_HACK_DELAY_duecreate_taskdeliver_event)selfclientevents      Z/var/www/OnlineNewsSite/project/venv/lib/python3.12/site-packages/telethon/events/album.py__init__zAlbumHack.__init__#   sO     {{6*KK$$&4	 2 2 45    c                     | j                         }|rL| j                  j                  j                  |       |j                  j                         t        z   | _        y y r   )r   r   messagesextendr   r   r   r   )r   r"   r   s      r   r#   zAlbumHack.extend,   sF    KK  ''1((*[8DI r    c                   K   	 | j                         }|y | j                  |j                  j                         z
  }|dk  r$|j	                  | j
                         d {    y ~t        j                  |       d {    7 $7 w)Nr   )r   r   r   r   _dispatch_eventr   asynciosleep)r   r   diffs      r   r   zAlbumHack.deliver_event2   s     \\^F~99v{{//11Dqy ,,T[[999--%%%  : &s$   AB
!B"B
 BB
B
N)__name__
__module____qualname____doc__r   r#   r    r    r   r   r      s    69&r    r   c                   b     e Zd ZdZ	 d
ddd fdZedd       Z fdZ G d d	ee	      Z
 xZS )Albuma  
    Occurs whenever you receive an album. This event only exists
    to ease dealing with an unknown amount of messages that belong
    to the same album.

    Example
        .. code-block:: python

            from telethon import events

            @client.on(events.Album)
            async def handler(event):
                # Counting how many photos or videos the album has
                print('Got an album with', len(event), 'items')

                # Forwarding the album as a whole to some chat
                event.forward_to(chat)

                # Printing the caption
                print(event.text)

                # Replying to the fifth item in the album
                await event.messages[4].reply('Cool!')
    NFblacklist_chatsfuncc                *    t         |   |||       y )Nr0   )superr   )r   chatsr1   r2   	__class__s       r   r   zAlbum.__init__^   s    dKr    c           
      b   |g}t        |t        j                  t        j                  f      rvt        |j                  t        j
                        sy |j                  j                  }|y t        j                  t        |      d       ry t        j                         }t        t              t        kD  r@t        j                         D cg c]  \  }}||z
  t        kD  s| c}}D ]	  }t        |=  |D ]  }||us|t        t        |      <    | j                  |D cg c]u  }t        |t        j                  t        j                  f      rIt        |j                  t        j
                        r%|j                  j                  |k(  r|j                  w c}      S y c c}}w c c}w r   )
isinstancer	   UpdateNewMessageUpdateNewChannelMessagemessageMessage
grouped_id_IGNORE_DICTpopidr   len_IGNORE_MAX_SIZEitems_IGNORE_MAX_AGEEvent)	clsupdateothersself_idgroupnowitus	            r   buildzAlbum.buildb   sf   
 f--u/L/LMOfnnemm<NN--E}
 6
D1 ))+C< #33(4(:(:(<Z1a/@Y!Z (A$Q(  .F?*-LA'.
 99#)q5#9#95;X;X"YZ"199emm<		,,5 		  9O& [s   F&#F&$A:F,c                 T    t        |j                        dkD  rt        |   |      S y Nr   )rA   r"   r4   filter)r   r   r6   s     r   rR   zAlbum.filter   s(    u~~"7>%(( #r    c                        e Zd ZdZ fdZ fdZed        Zed        Zed        Z	ed        Z
ed        Zd	 Zd
 Zd Zd Zd Zd Zd ZdddZd Zd Zd Z xZS )Album.Eventz
        Represents the event of a new album.

        Members:
            messages (Sequence[`Message <telethon.tl.custom.message.Message>`]):
                The list of messages belonging to the same album.
        c                     |d   }t         |   |j                  |j                  t	        |j
                               t        j                  | |j                         || _        y )Nr   )	chat_peermsg_id	broadcast)	r4   r   peer_idr@   boolpostr
   	sender_idr"   )r   r"   r;   r6   s      r   r   zAlbum.Event.__init__   sT    qkGGw$+JJ$w||:L  N!!$(9(9:$DMr    c                    t         |   |       t        j                  | j                  | j
                  |j                        \  | _        | _        | j                  D ]  }|j                  || j
                  d        ! t        | j                        dk(  rg|j                  j                  | j                        }|$t        ||       |j                  | j                  <   y |j!                  | j                         y y rQ   )r4   _set_clientr   _get_entity_pairr\   	_entities_mb_entity_cache_sender_input_senderr"   _finish_initrA   _albumsgetr=   r   r#   )r   r   msghackr6   s       r   r^   zAlbum.Event._set_client   s    G'/4/E/E0G0G0I,DL$, }} ?  >? 4==!Q&~~))$//:<6?6MFNN4??3KK. 'r    c                 4    | j                   d   j                  S )zM
            The shared ``grouped_id`` between all the messages.
            r   )r"   r=   r   s    r   r=   zAlbum.Event.grouped_id   s    
 ==#...r    c                 <    t        d | j                  D        d      S )z
            The message text of the first photo with a caption,
            formatted using the client's default parse mode.
            c              3   N   K   | ]  }|j                   s|j                     y wr   )text.0ms     r   	<genexpr>z#Album.Event.text.<locals>.<genexpr>   s     AA!&&A   %% nextr"   rj   s    r   rm   zAlbum.Event.text   s     AA2FFr    c                 <    t        d | j                  D        d      S )zv
            The raw message text of the first photo
            with a caption, ignoring any formatting.
            c              3   N   K   | ]  }|j                   s|j                     y wr   )raw_textrn   s     r   rq   z'Album.Event.raw_text.<locals>.<genexpr>   s     IajjIrr   rs   rt   rj   s    r   rx   zAlbum.Event.raw_text   s     IT]]I2NNr    c                 4    | j                   d   j                  S )a  
            `True` if the album is a reply to some other message.

            Remember that you can access the ID of the message
            this one is replying to through `reply_to_msg_id`,
            and the `Message` object with `get_reply_message()`.
            r   )r"   is_replyrj   s    r   rz   zAlbum.Event.is_reply   s     ==#,,,r    c                 4    | j                   d   j                  S )z
            The `Forward <telethon.tl.custom.forward.Forward>`
            information for the first message in the album if it was forwarded.
            r   )r"   forwardrj   s    r   r|   zAlbum.Event.forward   s     ==#+++r    c                 X   K   | j                   d   j                          d{   S 7 w)z
            The `Message <telethon.tl.custom.message.Message>`
            that this album is replying to, or `None`.

            The result will be cached after its first use.
            r   N)r"   get_reply_messagerj   s    r   r~   zAlbum.Event.get_reply_message   s&      q);;====s   !*(*c                 \   K    | j                   d   j                  |i | d{   S 7 w)z
            Responds to the album (not as a reply). Shorthand for
            `telethon.client.messages.MessageMethods.send_message`
            with ``entity`` already set.
            r   N)r"   respondr   argskwargss      r   r   zAlbum.Event.respond   s/      2q)114B6BBBB   #,*,c                 \   K    | j                   d   j                  |i | d{   S 7 w)z
            Replies to the first photo in the album (as a reply). Shorthand
            for `telethon.client.messages.MessageMethods.send_message`
            with both ``entity`` and ``reply_to`` already set.
            r   N)r"   replyr   s      r   r   zAlbum.Event.reply   s/      0q)//@@@@@r   c                    K   | j                   rN| j                  |d<   | j                          d{   |d<    | j                   j                  |i | d{   S y7 ,7 w)z
            Forwards the entire album. Shorthand for
            `telethon.client.messages.MessageMethods.forward_messages`
            with both ``messages`` and ``from_peer`` already set.
            r"   N	from_peer)r   r"   get_input_chatforward_messagesr   s      r   
forward_tozAlbum.Event.forward_to   s^      ||%)]]z",0,?,?,A&A{#:T\\::DKFKKK &AKs!   /A"A&A"A A" A"c                    K   | j                   D ]*  }|j                  s |j                  |i | d{   c S   | j                   d   j                  |i | d{   S 7 .7 w)a  
            Edits the first caption or the message, or the first messages'
            caption if no caption is set, iff it's outgoing. Shorthand for
            `telethon.client.messages.MessageMethods.edit_message`
            with both ``entity`` and ``message`` already set.

            Returns `None` if the message was incoming,
            or the edited `Message` otherwise.

            .. note::

                This is different from `client.edit_message
                <telethon.client.messages.MessageMethods.edit_message>`
                and **will respect** the previous state of the message.
                For example, if the message didn't have a link preview,
                the edit won't add one by default, and you should force
                it by setting it to `True` if you want it.

                This is generally the most desired and convenient behaviour,
                and will work for link previews and message buttons.
            Nr   )r"   rx   edit)r   r   r   rg   s       r   r   zAlbum.Event.edit  sj     , }} ;<<!)4!:6!:::; /q)..???? ;?s&   A'A'A#)A'A%A'%A'c                    K   | j                   rI | j                   j                  | j                          d{   | j                  g|i | d{   S y7  7 w)aH  
            Deletes the entire album. 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.
            N)r   delete_messagesr   r"   r   s      r   deletezAlbum.Event.delete   s`      ||9T\\99--//#   /s!   6AAAAAAc                    K   | j                   rS| j                   j                  | j                          d{   | j                  d   j                         d{    yy7 +7 w)z
            Marks the entire album as read. Shorthand for
            `client.send_read_acknowledge()
            <telethon.client.messages.MessageMethods.send_read_acknowledge>`
            with both ``entity`` and ``message`` already set.
            N)max_id)r   send_read_acknowledger   r"   r@   rj   s    r   	mark_readzAlbum.Event.mark_read.  sb      ||ll88--//b8I8L8L 9 N N N /Ns!   5A'A#$A'A%A'%A'Fnotifyc                \   K   | j                   d   j                  |       d{   S 7 w)z
            Pins the first photo in the album. Shorthand for
            `telethon.client.messages.MessageMethods.pin_message`
            with both ``entity`` and ``message`` already set.
            r   r   N)r"   pin)r   r   s     r   r   zAlbum.Event.pin9  s+      q)--V-<<<<r   c                 ,    t        | j                        S )zx
            Return the amount of messages in the album.

            Equivalent to ``len(self.messages)``.
            )rA   r"   rj   s    r   __len__zAlbum.Event.__len__A  s     t}}%%r    c                 ,    t        | j                        S )zu
            Iterate over the messages in the album.

            Equivalent to ``iter(self.messages)``.
            )iterr"   rj   s    r   __iter__zAlbum.Event.__iter__I  s     &&r    c                      | j                   |   S )zq
            Access the n'th message in the album.

            Equivalent to ``event.messages[n]``.
            )r"   )r   ns     r   __getitem__zAlbum.Event.__getitem__Q  s     ==##r    )r)   r*   r+   r,   r   r^   propertyr=   rm   rx   rz   r|   r~   r   r   r   r   r   r   r   r   r   r   __classcell__r6   s   @r   rE   rT      s    		%	/  
	/ 
	/ 
	G 
	G 
	O 
	O 
		- 
		- 
	, 
	,	>	C	A		L	@8			N ', 	=	&	'	$r    rE   r   )NN)r)   r*   r+   r,   r   classmethodrO   rR   r   r
   rE   r   r   s   @r   r/   r/   C   sN    4 L16TL ' 'R)
F$\ F$ F$r    r/   )r&   r   r   commonr   r   r   rs   r   tlr	   tl.custom.sendergetterr
   rB   rD   r>   r   r   r/   r-   r    r   <module>r      s_       ? ?   1 
  *& *&Z S$L S$ S$r    