
    hT                    0   d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
Z
d dlZd dlZd dlZd dlmZ d dlmZmZ d dlmZ d dlmZ d dlmZmZ d dlmZ d d	lmZ d d
lmZmZ d dl Z d dl m!Z!m"Z"m#Z#m$Z$m%Z% d dl&m'Z' d dl(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z. d dl/m0Z0 d dl1m2Z2 d dl3m4Z4m5Z5 d dl6m7Z7m8Z8 d dl9m:Z:m;Z;m<Z< d dl=m>Z> ddl?m@Z@ ddlAmBZBmCZCmDZD ddlEmEZE ddlFmGZG ddlHmIZI erd dlJmKZK  ejL        eM          ZN G d de2          ZO G d d          ZPdS )    )annotationsN)ThreadPoolExecutor)datetime	timedelta)sha256)import_module)BytesIOStringIO)	MimeTypes)Path)TYPE_CHECKINGCallable)__license____version__enumsrawutils)aes)AuthBytesInvalid
BadRequestCDNFileHashMismatchChannelPrivateSessionPasswordNeededVolumeLocNotFound)Handler)Methods)AuthSession)BaseStorageSQLiteStorage)ListenerTypesTermsOfServiceUser)ainput   )
Dispatcher)FileIdFileTypeThumbnailSource)
mime_types)Parser)MsgId)AsyncGeneratorc                  n    e Zd ZdZde Z ej                     d ej                     Z	 ej
                     d ej                     ZdZ eej        d                   j        Z ej        d          Z ed ej                    pddz             ZeZd	Zd
Z e            Ze                     e e!                     ddee	eedddddddddde e"e          de#j$        j%        dde&j'        defdP fd0Z(d1 Z)d2 Z*d3 Z+dQd6Z,dRd8Z-dSd;Z.d< Z/d= Z0d> Z1d? Z2	 	 	 	 	 dTdUdKZ3dVdMZ4dWdOZ5 xZ6S )XClienta"  Hydrogram Client, the main means for interacting with Telegram.

    Parameters:
        name (``str``):
            A name for the client, e.g.: "my_account".

        api_id (``int`` | ``str``, *optional*):
            The *api_id* part of the Telegram API key, as integer or string.
            E.g.: 12345 or "12345".

        api_hash (``str``, *optional*):
            The *api_hash* part of the Telegram API key, as string.
            E.g.: "0123456789abcdef0123456789abcdef".

        app_version (``str``, *optional*):
            Application version.
            Defaults to "Hydrogram x.y.z".

        device_model (``str``, *optional*):
            Device model.
            Defaults to *platform.python_implementation() + " " + platform.python_version()*.

        system_version (``str``, *optional*):
            Operating System version.
            Defaults to *platform.system() + " " + platform.release()*.

        lang_code (``str``, *optional*):
            Code of the language used on the client, in ISO 639-1 standard.
            Defaults to "en".

        ipv6 (``bool``, *optional*):
            Pass True to connect to Telegram using IPv6.
            Defaults to False (IPv4).

        proxy (``dict``, *optional*):
            The Proxy settings as dict.
            E.g.: *dict(scheme="socks5", hostname="11.22.33.44", port=1234, username="user", password="pass")*.
            The *username* and *password* can be omitted if the proxy doesn't require authorization.

        test_mode (``bool``, *optional*):
            Enable or disable login to the test servers.
            Only applicable for new sessions and will be ignored in case previously created sessions are loaded.
            Defaults to False.

        bot_token (``str``, *optional*):
            Pass the Bot API token to create a bot session, e.g.: "123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11"
            Only applicable for new sessions.

        session_string (``str``, *optional*):
            Pass a session string to load the session in-memory.
            Implies ``in_memory=True``.

        session_storage_engine (:obj:`~hydrogram.storage.BaseStorage`, *optional*):
            Pass an instance of your own implementation of session storage engine.
            Useful when you want to store your session in databases like Mongo, Redis, etc.

        in_memory (``bool``, *optional*):
            Pass True to start an in-memory session that will be discarded as soon as the client stops.
            In order to reconnect again using an in-memory session without having to login again, you can use
            :meth:`~hydrogram.Client.export_session_string` before stopping the client to get a session string you can
            pass to the ``session_string`` parameter.
            Defaults to False.

        phone_number (``str``, *optional*):
            Pass the phone number as string (with the Country Code prefix included) to avoid entering it manually.
            Only applicable for new sessions.

        phone_code (``str``, *optional*):
            Pass the phone code as string (for test numbers only) to avoid entering it manually.
            Only applicable for new sessions.

        password (``str``, *optional*):
            Pass the Two-Step Verification password as string (if required) to avoid entering it manually.
            Only applicable for new sessions.

        workers (``int``, *optional*):
            Number of maximum concurrent workers for handling incoming updates.
            Defaults to ``min(32, os.cpu_count() + 4)``.

        workdir (``str``, *optional*):
            Define a custom working directory.
            The working directory is the location in the filesystem where Hydrogram will store the session files.
            Defaults to the parent directory of the main script.

        plugins (``dict``, *optional*):
            Smart Plugins settings as dict, e.g.: *dict(root="plugins")*.

        parse_mode (:obj:`~hydrogram.enums.ParseMode`, *optional*):
            Set the global parse mode of the client. By default, texts are parsed using both Markdown and HTML styles.
            You can combine both syntaxes together.

        no_updates (``bool``, *optional*):
            Pass True to disable incoming updates.
            When updates are disabled the client can't receive messages or other updates.
            Useful for batch programs that don't need to deal with updates.
            Defaults to False (updates enabled and received).

        takeout (``bool``, *optional*):
            Pass True to let the client use a takeout session instead of a normal one, implies *no_updates=True*.
            Useful for exporting Telegram data. Methods invoked inside a takeout session (such as get_chat_history,
            download_media, ...) are less prone to throw FloodWait exceptions.
            Only available for users, bots will ignore this parameter.
            Defaults to False (normal session).

        sleep_threshold (``int``, *optional*):
            Set a sleep threshold for flood wait exceptions happening globally in this client instance, below which any
            request that raises a flood wait will be automatically invoked again after sleeping for the required amount
            of time. Flood wait exceptions requiring higher waiting times will be raised.
            Defaults to 10 seconds.

        hide_password (``bool``, *optional*):
            Pass True to hide the password when typing it during the login.
            Defaults to False, because ``getpass`` (the library used) is known to be problematic in some
            terminal environments.

        max_concurrent_transmissions (``bool``, *optional*):
            Set the maximum amount of concurrent transmissions (uploads & downloads).
            A value that is too high may result in network related issues.
            Defaults to 1.
    z
Hydrogram  enr   zT^(?:https?://)?(?:www\.)?(?:t(?:elegram)?\.(?:org|me|dog)/(?:joinchat/|\+))([\w-]+)$       i  r%   NFnamestrapi_idint | str | Noneapi_hash
str | Noneapp_versiondevice_modelsystem_version	lang_codeipv6boolproxydict | None	test_mode	bot_tokensession_stringsession_storage_engineBaseStorage | None	in_memorybool | Nonephone_number
phone_codepasswordworkersintworkdirplugins
parse_modeenums.ParseMode
no_updatestakeoutsleep_thresholdhide_passwordmax_concurrent_transmissionsc                   t                                                       || _        |rt          |          nd | _        || _        || _        || _        || _        |	                                | _
        || _        |	| _        |
| _        || _        || _        || _        || _        || _        || _        || _        t+          |          | _        || _        || _        || _        || _        || _        || _        || _        t=          | j        d          | _        | j        r"tA          | j        | j        d          | _!        n_tE          |tF                    r|| _!        nB| j        rtA          | j        d          | _!        ntA          | j        | j                  | _!        tI          |           | _%        tL          | _'        tQ          |           | _)        d | _*        i | _+        tY          j-                    | _.        tY          j-                    | _/        tY          j0        | j                  | _1        tY          j0        | j                  | _2        d | _3        d | _4        d | _5        d | _6        d | _7        tq          d          | _9        d | _:        tY          j;                    | _<        t{          j>                    | _?        tY          j@                    | _A        d t          D             | _C        d S )Nr   )thread_name_prefixT)rD   
use_memory)rY   i'  c                    i | ]}|g S  r[   ).0listener_types     P/var/www/html/auto_sub_bot/venv/lib/python3.11/site-packages/hydrogram/client.py
<dictcomp>z#Client.__init__.<locals>.<dictcomp>A  s    OOO-OOO    )Dsuper__init__r4   rM   r6   r8   r:   r;   r<   lowerr=   r>   r@   rB   rC   rD   rG   rI   rJ   rK   rL   r   rN   rO   rP   rR   rS   rT   rU   rV   r   executorr    storage
isinstancer   r&   
dispatcherr,   rnd_idr+   parsersessionmedia_sessionsasyncioLockmedia_sessions_lock	file_lock	Semaphoresave_file_semaphoreget_file_semaphoreis_connectedis_initialized
takeout_iddisconnect_handlermeCachemessage_cacheupdates_watchdog_taskEventupdates_watchdog_eventr   nowlast_update_timeget_event_looploopr!   	listeners)selfr4   r6   r8   r:   r;   r<   r=   r>   r@   rB   rC   rD   rE   rG   rI   rJ   rK   rL   rN   rO   rP   rR   rS   rT   rU   rV   	__class__s                              r^   rb   zClient.__init__   s   : 		%+5c&kkk &(,"**	
"","($ G}}$$.*,H)*4<IVVV 		B(	$*=$  DLL .<< 	B1DLL^ 	B(tDDDDLL(DLAADL$T**Tll #*<>>  #*#4T5V#W#W ")"3D4U"V"V ""&#"5\\
 &*"&-moo# (*,,	OOOOOr`   c                :   K   |                                   d {V S N)startr   s    r^   
__aenter__zClient.__aenter__C  s&      ZZ\\!!!!!!!r`   c                   K   t          j        t                    5  |                                  d {V  d d d            d S # 1 swxY w Y   d S r   )
contextlibsuppressConnectionErrorstop)r   argss     r^   	__aexit__zClient.__aexit__F  s       11 	 	))++	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   AAAc                  K   	 	 t          j        | j                                        | j                   d {V  d S # t           j        $ r Y nw xY wt          j                    | j        z
  t          | j                  k    r<| 
                    t          j        j                                                   d {V  )NT)seconds)rl   wait_forr|   waitUPDATES_WATCHDOG_INTERVALTimeoutErrorr   r}   r~   r   invoker   	functionsupdatesGetStater   s    r^   updates_watchdogzClient.updates_watchdogJ  s      	D&/44668V          '   
 |~~ 55	69 9 9   kk#-"7"@"@"B"BCCCCCCCCC	Ds   7> AAreturnr#   c                	  K   | j         r |                     | j                    d {V S t          dt           d           t          dt           d           	 	 | j        sy	 t          d           d {V }|st          d| d           d {V                                 }|d	k    rnKd
|v r"|| _         |                     |           d {V S || _        |                     | j                   d {V }n:# t          $ r,}t          |j
                   d | _        d | _         Y d }~nd }~ww xY wt          j        j        dt          j        j        dt          j        j        dt          j        j        dt          j        j        dt          j        j        di}t          d||j                             	 | j        st          d           d {V | _        	 |                     | j        |j        | j                   d {V }n# t          $ r&}t          |j
                   d | _        Y d }~nd }~wt.          $ r}t          |j
                   	 t          d|                                  d {V             | j        s!t          d| j                   d {V | _        	 | j        r%|                     | j                   d {V cY d }~S t          d           d {V }|d	k    r|                                  d {V }t          d|            	 t          d           d {V }	 |                     |           d {V cY d }~S # t          $ r}t          |j
                   Y d }~n0d }~wt<          $ r }t>                               |            d }~ww xY wd | _        n2# t          $ r%}t          |j
                   d | _        Y d }~nd }~ww xY wd }~ww xY w5tC          |tD                    r|S 	 t          d           d {V }	t          d           d {V }
	 | #                    | j        |j        |	|
           d {V }n,# t          $ r}t          |j
                   Y d }~nd }~ww xY wtC          |tH                    r:t          d|j%        z   dz              | &                    |j'                   d {V  |S )NzWelcome to Hydrogram (version )zbHydrogram is free software and comes with ABSOLUTELY NO WARRANTY. Licensed
under the terms of the z.
Tz!Enter phone number or bot token: Is "" correct? (y/N): y:zTelegram appSMSz
phone callzphone flash callzFragment SMSz
email codez(The confirmation code has been sent via zEnter confirmation code: zPassword hint: z#Enter password (empty to recover): )hidez!Confirm password recovery (y/n): z#The recovery code has been sent to zEnter recovery code: zEnter first name: z!Enter last name (empty to skip): 
)(rC   sign_in_botprintr   r   rI   r$   rc   	send_coder   MESSAGEr   SentCodeTypeAPPr   CALL
FLASH_CALLFRAGMENT_SMS
EMAIL_CODEtyperJ   sign_inphone_code_hashr   get_password_hintrK   rU   check_passwordsend_recovery_coderecover_password	Exceptionlog	exceptionrf   r#   sign_upr"   textaccept_terms_of_serviceid)r   valueconfirm	sent_codeesent_code_descriptions	signed_inemail_patternrecovery_code
first_name	last_name	signed_ups               r^   	authorizezClient.authorizeZ  s     > 	:))$.999999999={===>>>7&17 7 7	
 	
 	

	( .	"&,-P&Q&Q Q Q Q Q Q Q$ %$)/0Pu0P0P0P)Q)Q#Q#Q#Q#Q#Q#Q"X"X"Z"Z"c>>!	" e||).%)%5%5e%<%<<<<<<<<(-D%"&..1B"C"CCCCCCC	   & & &ai   $(!!%&)	8 "N"E#\)+=+^)<"
 	a9OPYP^9_aabbb0	? L(./J(K(K"K"K"K"K"K"K,"&,,%y'@$/# #      	V Q  ' ' 'ai   "&( #- #- #-ai    -L$2H2H2J2J,J,J,J,J,J,JLLMMM= .4A!%!3/ / / ) ) ) ) ) )
-= L)-)<)<T])K)K#K#K#K#K#K#KKKKKKK(./R(S(S"S"S"S"S"S"S"c>>262I2I2K2K,K,K,K,K,K,KM!"W"W"WXXX	*6<=T6U6U0U0U0U0U0U0U!*151F1F}1U1U+U+U+U+U+U+U$U$U$U$U$U$U'1 !5 !5 !5$)!)$4$4$4$4$4$4$4$4'0 !* !* !*$'MM!$4$4$4$)!*	* -1DMM% - - -ai((((,-= -#-0	d i&& 		%&:;;;;;;;;J$%HIIIIIIIII"&,,%y'@*i# #      	   ! ! !ai        !	 i00 	=$'$.///..y|<<<<<<<<<s   A8C= 'C= =
D3"D..D3,H 
O-H88O-A'O(.&N4O-AN48MO-
N("M;6N4;N(N##N((N43O(4
O#>OO(O##O((O-5(Q 
R(RRenums.ParseMode | Nonec                    || _         dS )a  Set the parse mode to be used globally by the client.

        When setting the parse mode with this method, all other methods having a *parse_mode* parameter will follow the
        global value by default.

        Parameters:
            parse_mode (:obj:`~hydrogram.enums.ParseMode`):
                By default, texts are parsed using both Markdown and HTML styles.
                You can combine both syntaxes together.

        Example:
            .. code-block:: python

                from hydrogram import enums

                # Default combined mode: Markdown + HTML
                await app.send_message("me", "1. **markdown** and <i>html</i>")

                # Force Markdown-only, HTML is disabled
                app.set_parse_mode(enums.ParseMode.MARKDOWN)
                await app.send_message("me", "2. **markdown** and <i>html</i>")

                # Force HTML-only, Markdown is disabled
                app.set_parse_mode(enums.ParseMode.HTML)
                await app.send_message("me", "3. **markdown** and <i>html</i>")

                # Disable the parser completely
                app.set_parse_mode(enums.ParseMode.DISABLED)
                await app.send_message("me", "4. **markdown** and <i>html</i>")

                # Bring back the default combined mode
                app.set_parse_mode(enums.ParseMode.DEFAULT)
                await app.send_message("me", "5. **markdown** and <i>html</i>")
        N)rP   )r   rP   s     r^   set_parse_modezClient.set_parse_mode  s    H %r`   peers9list[raw.types.User | raw.types.Chat | raw.types.Channel]c                $  K   d}g }|D ]}t          |dd          rd}d }d }t          |t          j        j                  ro|j        }|j        }|j        r|j                                        n,|j	        r$|j	        d         j                                        nd }|j
        }|j        rdnd}	n"t          |t          j        j        t          j        j        f          r|j         }d}d}	nt          |t          j        j                  ryt          j        |j                  }|j        }|j        r|j                                        n,|j	        r$|j	        d         j                                        nd }|j        rdnd	}	nMt          |t          j        j                  r,t          j        |j                  }|j        }|j        rdnd	}	n|                    |||	||f           | j                            |           d {V  |S )
NFminTr   botusergroupchannel
supergroup)getattrrf   r   typesr#   r   access_hashusernamerc   	usernamesphoner   ChatChatForbiddenChannelr   get_channel_id	broadcastChannelForbiddenappendre   update_peers)
r   r   is_minparsed_peerspeerr   rI   peer_idr   	peer_types
             r^   fetch_peerszClient.fetch_peers  s4       *	[ *	[DtUE** HL$	//  '". }DM''))) ~*399;;;   $z%)X9EE6		D39>393J"KLL 7(#		D#)"344 .tw77". }DM''))) ~*399;;;  *.III\		D#)"<== .tw77".)-III\		+y(L YZZZZl''555555555r`   c                	  K   t          j                    | _        t          |t          j        j        t          j        j        f          rt          | 	                    |j
                   d {V | 	                    |j                   d {V f          }d |j
        D             }d |j        D             }|j        D ]I}t          t          t          |dd           dd           dd           pt          |dd           }t          |dd           }t          |dd           }t          |t          j        j                  rt                              |           t          |t          j        j                  ri|rf|j        }	t          |	t          j        j                  s?	 |                     t          j        j                            |                     t1          j        |                     d {V t          j                            t          j                            |j        j        |j        j                  g	          ||z
  |
                     d {V }
t          |
t          j        j        j                  sH|                    d |
j
        D                        |                    d |
j        D                        n# t>          $ r Y nw xY w| j         j!        "                    |||f           Kd S t          |t          j        j#        t          j        j$        f          r|                     t          j        j        %                    |j&        |j'        z
  |j(        d                     d {V }
|
j)        rw| j         j!        "                    t          j        *                    |
j)        d         |j&        |j'                  d |
j
        D             d |
j        D             f           d S |
j+        r/| j         j!        "                    |
j+        d         i i f           d S d S t          |t          j        j,                  r)| j         j!        "                    |j        i i f           d S t          |t          j        j-                  rt                              |           d S d S )Nc                    i | ]
}|j         |S r[   r   r\   us     r^   r_   z)Client.handle_updates.<locals>.<dictcomp>7      444QT1444r`   c                    i | ]
}|j         |S r[   r   r\   cs     r^   r_   z)Client.handle_updates.<locals>.<dictcomp>8  r   r`   messager   
channel_idpts	pts_count)min_idmax_id)ranges)r   filterr   limitc                    i | ]
}|j         |S r[   r   r   s     r^   r_   z)Client.handle_updates.<locals>.<dictcomp>a      -J-J-J!adA-J-J-Jr`   c                    i | ]
}|j         |S r[   r   r   s     r^   r_   z)Client.handle_updates.<locals>.<dictcomp>b  r   r`   )r   dateqtsr   )r   r   r   c                    i | ]
}|j         |S r[   r   r   s     r^   r_   z)Client.handle_updates.<locals>.<dictcomp>s      111QT1111r`   c                    i | ]
}|j         |S r[   r   r   s     r^   r_   z)Client.handle_updates.<locals>.<dictcomp>t  r  r`   ).r   r}   r~   rf   r   r   UpdatesUpdatesCombinedanyr   userschatsr   r   UpdateChannelTooLongr   infoUpdateNewChannelMessager   MessageEmptyr   r   GetChannelDifferenceresolve_peerr   r   ChannelMessagesFilterMessageRanger   ChannelDifferenceEmptyupdater   rg   updates_queue
put_nowaitUpdateShortMessageUpdateShortChatMessageGetDifferencer   r   r   new_messagesUpdateNewMessageother_updatesUpdateShortUpdatesTooLong)r   r   r   r  r  r  r   r   r   r   diffs              r^   handle_updateszClient.handle_updates.  s'      (g	 1393LMNN J	&&w}55555555&&w}55555555  F
 54gm444E44gm444E!/ *Q *Q$GFIt<<iNN   9 V\488	  feT22#FK>>	fci&DEE %HHV$$$fci&GHH LV L$nG%gsy/EFF LL)- # 5 J J262C2C(-(<Z(H(H3& 3& -& -& -& -& -& -& ,/9+J+J,/I,B,B7=~7H7=~7H -C -. -.0* ,K ,& ,& ),i*- !K !" !"* * $ $ $ $ $ $D( $.dCI4E4\#]#] L %-J-Jtz-J-J-J K K K %-J-Jtz-J-J-J K K K  . ! ! ! D! -88&%9OPPPPU*Q *QV #)">	@`!abb 	%33g&77glPR 4         D   Z-88I.. $ 1! 4#K")"3 /  
 21dj11111dj111:      # Z-88$:LQ:OQSUW9XYYYYYZ Z!677 	O)44gnb"5MNNNNN!9:: 	HHW	 	s   +CK
K&%K&c                D  K   | j                                          d {V  t          | j                                          d {V d u | j                                          d {V d u | j                                          d {V d u | j                                          d {V d u g          }|rj| j        r| j        st          d          | j                             | j                   d {V  | j         
                    d           d {V  | j                             d           d {V  | j                             | j                   d {V  | j                             t          | | j         
                                 d {V | j                                          d {V                                            d {V            d {V  | j                             d            d {V  | j                             d            d {V  d S | j                                          d {V s| j        r'| j                             | j                   d {V  d S 	 	 t          t          d           d {V           }|dk    rt!          d           :t          d| d           d {V                                 }|d	k    r"| j                             |           d {V  d S n&# t$          $ r}t!          |           Y d }~nd }~ww xY wd S )
NzoThe API key is required for new authorizations. More info: https://docs.hydrogram.org/en/latest/start/auth.html   r   Tz&Enter the api_id part of the API key: zInvalid valuer   r   r   )re   openr  rB   auth_keyuser_idis_botr6   r8   AttributeErrordc_idr   r   createrM   r$   r   rc   r   )r   session_emptyr   r   r   s        r^   load_sessionzClient.load_session}  s+     l!!!!!!!!!,((********d2,''))))))))T1,&&((((((((D0,%%''''''''4/	
    &	!; dm $V  
 ,%%dk222222222,$$Q''''''''',##A&&&&&&&&&,((888888888,'' 2 2 4 4444444DL<R<R<T<T6T6T6T6T6T6T &((             
 ,&&t,,,,,,,,,,%%d+++++++++++|**,,,,,,,, 	!{ !l))$+66666666666!! #&1Y*Z*Z$Z$Z$Z$Z$Z$Z [ [ A::!/222$)/0Pu0P0P0P)Q)Q#Q#Q#Q#Q#Q#Q"X"X"Z"Z"c>>"&,"5"5e"<"<<<<<<<<!E * % ! ! !a!!		! 	!s   -7K9 %AK9 9
LLLc                
   | j         sd S | j                                         }dD ]2}|                    |g           rd | j         |         D             ||<   3|                    dd          r|d         }|                    dg           }|                    dg           }d}|s\t          t	          |                    d	d
                                        d                    D ]}d	                    g |j        j	        |j
        R           }t          |          }	t          |	          D ]}
t          j        t                    5  t!          |	|
          j        D ]\  }}t%          |t&                    rft%          |t(                    rQ|                     ||           t,                              d| j        t3          |          j        |
||           |dz  }	 d d d            n# 1 swxY w Y   ːn}|D ]y\  }}| d	| }d}	 t          |          }	n1# t6          $ r$ t,                              d| j        |           Y Mw xY wdt;          |	          v r"t,                              d| j        |           |#t          |	                                          }d}|D ]}
	 t!          |	|
          j        D ]\  }}t%          |t&                    rft%          |t(                    rQ|                     ||           t,                              d| j        t3          |          j        |
||           |dz  }# t          $ r' |r"t,                              d| j        |
|           Y w xY w{|r}|D ]y\  }}| d	| }d}	 t          |          }	n1# t6          $ r$ t,                              d| j        |           Y Mw xY wdt;          |	          v r"t,                              d| j        |           |#t          |	                                          }d}|D ]}
	 t!          |	|
          j        D ]\  }}t%          |t&                    rft%          |t(                    rQ|                     ||           t,                              d| j        t3          |          j        |
||           |dz  }# t          $ r' |r"t,                              d| j        |
|           Y w xY w{|dk    r-t,                              d| j        ||dk    rdnd|           d S t,                              d| j        |           d S d S )N)includeexcludec                ~    g | ]:}|                                 d          |                                 dd         pdf;S )r   r%   N)split)r\   is     r^   
<listcomp>z'Client.load_plugins.<locals>.<listcomp>  sK     # # #>?QWWYYq\17799QRR=#8D9# # #r`   enabledTrootr+  r,  r   ./z*.pyz*[%s] [LOAD] %s('%s') in group %s from '%s'r%   z-[%s] [LOAD] Ignoring non-existent module "%s"__path__z#[%s] [LOAD] Ignoring namespace "%s"Fz9[%s] [LOAD] Ignoring non-existent function '%s' from '%s'z/[%s] [UNLOAD] Ignoring non-existent module "%s"z%[%s] [UNLOAD] Ignoring namespace "%s"z.[%s] [UNLOAD] %s('%s') from group '%s' in '%s'z;[%s] [UNLOAD] Ignoring non-existent function '%s' from '%s'z.[%s] Successfully loaded %s plugin%s from '%s' sz[%s] No plugin loaded from "%s") rO   copygetsortedr   replacerglobjoinparentpartsstemr   varsr   r   r   r   handlersrf   r   rM   add_handlerr   r
  r4   r   __name__ImportErrorwarningdirkeysremove_handler)r   rO   optionr2  r+  r,  countpathmodule_pathmoduler4   handlerr   rB  warn_non_existent_functionss                  r^   load_pluginszClient.load_plugins  s   | 	F,##%%, 	 	F{{62&& # #CG<PVCW# # # ;;y$'' M	P6?Dkk)R00Gkk)R00GE G""4S#(>(>#?#?#E#Ef#M#MNN / /D"%((+JT[->+J	+J+J"K"KK*;77F $V / /'0;; / /29&$2G2G2P / /#-gw#?#? !/JuVYDZDZ !/$($4$4We$D$D$D$'HH(T(,	(,W(>(,(-(3%& %& %& %*QJE// / / / / / / / / / / / / / //	/* '. 1" 1"ND(%)"2"2D"2"2K26/!!.{!;!;& ! ! !K I'  
 !! "S[[00A I'  
 !'#'<<#4#4#6#66;3 ( " ""29&$2G2G2P / /#-gw#?#? !/JuVYDZDZ !/$($4$4We$D$D$D$'HH(T(,	(,W(>(,(-(3%& %& %& %*QJE/  ) " " ": " #$_$(I$($/	!" !" !""!"2  2"&- 1" 1"ND(%)"2"2D"2"2K26/!!.{!;!;& ! ! !M I'  
 !! "S[[00C I'  
 !'#'<<#4#4#6#66;3 ( " ""29&$2G2G2P / /#-gw#?#? !/JuVYDZDZ !/$($7$7$G$G$G$'HH(X(,	(,W(>(,(-(3%& %& %& %*QJE/  ) " " ": " #$a$(I$($/	!" !" !""!"2 qyyDI1**BB#     =ty$OOOOO[M	P M	Ps]   BG44G8;G8H&&+II4BM.M<;M<N&&+OO4BS.S<;S<c                  K   |\  }}}}}}}|rd n#t          |                              dd           t          |                                          |z  }	d                    t	          j        t          j        t          j        z   d                    }
|		                    |	j
        dz   |
z   dz             }|rt                      n!t          |                              d          }	 |                     ||d	d	||          2 3 d {V }|                    |           6 	 |r	||_        |S |                                 | j        4 d {V  |	}d
}|                                r@|		                    |	j
         d| d|	j                   }|d
z  }|                                @t)          j        ||           d d d           d {V  n# 1 d {V swxY w Y   |S # t,          $ r}|s5|                                 t          |                                           t1          |t2          j                  r|t1          |t6          j        j                  r|Y d }~d S d }~ww xY w)NT)parentsexist_okr6     )k_z.tempwbr   r%   (r   )r   mkdirresolver=  randomchoicesstringascii_lettersdigits	with_namer@  r	   r!  get_filewriter4   closero   existssuffixshutilmoveBaseExceptionunlinkrf   rl   CancelledError	hydrogramerrors	FloodWait)r   packetfile_id	directory	file_namerG   	file_sizeprogressprogress_args	file_pathrandom_suffixtemp_file_pathfilechunkfinal_file_pathcounterr   s                    r^   handle_downloadzClient.handle_downloadI  s?      	
 QtI44TD4QQOO++--	9	v/Cfm/SWX Y Y YZZ",,Y^c-AM-QT[-[\\%Jwyyy4+?+?+D+DT+J+J!	##}}WiAxQ^__ " " " " " " "e

5!!!!  `_  %	JJLLL~ 	= 	= 	= 	= 	= 	= 	= 	=(1%,,.. !&/&9&9$>HHGHHi6FHH' 'O qLG	 &,,.. ! NO<<<	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= #"=  	 	 	 .

^$$++---!W344 !Y-788 44444	s8   /G' 	D&G' A.G
G!G'
I01A4I++I0r[   rp  r'   rs  r   offsetrt  Callable | Noneru  tupleAsyncGenerator[bytes, None]c                 K   | j         4 d {V  |j        }|t          j        k    r|j        dk    r,t
          j                            |j        |j                  }no|j        dk    r't
          j        	                    |j                   }n=t
          j        
                    t          j        |j                  |j                  }t
          j                            ||j        |j        t           j        k              }	n|t          j        k    r8t
          j                            |j        |j        |j        |j                  }	n7t
          j                            |j        |j        |j        |j                  }	d}
t1          |          pd}d}t1          |          |z  }|j        }	 | j                            |          }|s|| j                                         d {V k    rFt;          | || j                                         d {V                                            d {V n| j                                          d {V }tC          | ||| j                                         d {V d	
          x}| j        |<   |"                                 d {V  || j                                         d {V k    rtG          d          D ]}| $                    t
          j%        j&        '                    |                     d {V }	 |$                    t
          j%        j&        (                    |j)        |j*                             d {V   n# tV          $ r Y w xY wtV          	 |$                    t
          j%        j,        -                    |	||          d           d {V }t]          |t
          j        j,        j/                  r|j*        }|W V  |
dz  }
||z  }|ruta          j1        ||dk    rte          ||          n||g|R  }tg          j4        |          r |             d {V  n&| j5        6                    | j7        |           d {V  tq          |          |k     s|
|k    rnonkt]          |t
          j        j,        j9                  rFtC          | |j        t;          | |j        | j                                         d {V                                            d {V | j                                         d {V d	d	          }	 |"                                 d {V  	 |$                    t
          j%        j,        :                    |j;        ||                     d {V }t]          |t
          j        j,        j<                  r\	 |$                    t
          j%        j,        =                    |j;        |j>                             d {V  # t~          $ r Y nw xY w|j*        }t          jA        ||jB        t          |jD        d d         |dz  E                    dd          z                       }|$                    t
          j%        j,        F                    |j;        |                     d {V }t          |          D ]_\  }}||jH        |z  |jH        |dz   z           }t          jJ        |jK        t          |          M                                k    d           `|W V  |
dz  }
||z  }|ruta          j1        ||dk    rte          ||          n||g|R  }tg          j4        |          r |             d {V  n&| j5        6                    | j7        |           d {V  tq          |          |k     s|
|k    rnp|N                                 d {V  n# |N                                 d {V  w xY w}nT# t          jP        $ r  t          jQ        jR        $ r  t          $ r$}t          U                    |           Y d }~nd }~ww xY wd d d           d {V  d S # 1 d {V swxY w Y   d S )Nr   )r#  r   )chat_id)r   r   )r   photo_idbig)r   r   file_reference
thumb_sizeii   T)is_media   )r&  )r   bytes)locationr~  r      )rT   r%   )r  is_cdn)
file_tokenr~  r   )r  request_token   r3   r  )r  r~  z$h.hash == sha256(cdn_chunk).digest())Vrr   	file_typer(   
CHAT_PHOTOr  r   r   InputPeerUserchat_access_hashInputPeerChatInputPeerChannelr   r   InputPeerPhotoFileLocationmedia_idthumbnail_sourcer)   CHAT_PHOTO_BIGPHOTOInputPhotoFileLocationr   r  thumbnail_sizeInputDocumentFileLocationabsr&  rk   r9  re   r   rB   r'  r"  r   r   ranger   r   authExportAuthorizationImportAuthorizationr   r  r   uploadGetFilerf   File	functoolspartialr   inspectiscoroutinefunctionr   run_in_executorrd   lenFileCdnRedirect
GetCdnFiler  CdnFileReuploadNeededReuploadCdnFiler  r   r   ctr256_decryptencryption_key	bytearrayencryption_ivto_bytesGetCdnFileHashes	enumerater   r   checkhashr   digestr   rl  StopTransmissionrm  rn  r   r   r   )r   rp  rs  r   r~  rt  ru  r  r   r  currenttotal
chunk_sizeoffset_bytesr&  rj   r"  rW  exported_authrrz  funccdn_sessionr2decrypted_chunkhashesr/  h	cdn_chunkr   s                                 r^   rb  zClient.get_file  s0      * 	! 	! 	! 	! 	! 	! 	! 	!)IH///?Q&&922 'W=U 3  DD -22922GO;K2LLDD955#(#7#H#H$+$< 6  D 9??$-0O4RR @  
 hn,,9;;' ' 3#*#9&5	 <   9>>' ' 3#*#9&5	 ?   GJJ/-E$Jv;;3LMEW!-11%88 3 !$,*<*<*>*>$>$>$>$>$>$>>> #4dl6L6L6N6N0N0N0N0N0N0NOOVVXXXXXXXXX#'<#8#8#:#::::::: 
 <CeXT\5K5K5M5M/M/M/M/M/M/MX\< < < Gd1%8 "--//)))))))dl&8&8&:&: : : : : : :::!&q 3 3A26++ # 2 F FU F S S3 3 - - - - - -M)&-nn$'M$6$J$J+8+;=CV %K %& %&'" '" !" !" !" !" !" !" !"
 !&#3 ) ) ) () #32s5%nn,44%-l* 5   )+	 -        A "!SY%5%:;; k5 !#1$
2# U#,#4 (@IQL) < < <T` )$ "/	$ $ $D  ':8DD U&*dff&*i&?&?t&T&T T T T T T T Tu::
22g6F6F! 7G $Asy'7'GHH T5&- G"&tQWDL<R<R<T<T6T6T6T6T6T6T"U"U"\"\"^"^^^^^^^"&,"8"8":":::::::%)#'' ' 'J5"-"3"3"5"55555555E*+6+=+=$'M$8$C$C34</;.8 %D %& %&," ," &" &" &" &" &" &" $.b#)2B2X#Y#Y !1
%1.5nn,/M,@,P,P;<<>@>N -Q -. -./* /* )* )* )* )* )* )* )* )1 ,= %. %. %.(-%.
 )+ 362D$)$%$4$-()(<+72+=*G*G5*Q*Q)R%& %&3" 3" 07~~$'M$8$I$I34< %J %& %&0" 0" *" *" *" *" *" *" -6f,=,= !& !&DAq0?!agYZ]^Y^N_@_0`I$7$=()&2C2C2J2J2L2L(L(N%& %& %& %&
 '6 5 5 5 5 '1 ,
 :#+ !]+4+<(0+4>> ),L)(D(D(D-9(1,& *7,& ,& ,&D (/'B8'L'L %].2dff.2i.G.GW[.\.\(\(\(\(\(\(\(\#&u::
#:#:g>N>N$)KE*N #."2"2"4"444444444+"2"2"4"444444444gs5: "n -   #-    ! ! !a        !}	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	!s   F&a,7E,`$A	M/-`/
M<9`;M<<G `=B_#A	X_#
X_#XF._#`#_??`a,-a2aa,aa,,
a69a6filenamec                B    | j                             |          d         S )Nr   )	mimetypes
guess_type)r   r  s     r^   guess_mime_typezClient.guess_mime_typeI  s    ~((22155r`   	mime_typec                6    | j                             |          S r   )r  guess_extension)r   r  s     r^   r  zClient.guess_extensionL  s    ~--i888r`   )4r4   r5   r6   r7   r8   r9   r:   r5   r;   r5   r<   r5   r=   r5   r>   r?   r@   rA   rB   r?   rC   r9   rD   r9   rE   rF   rG   rH   rI   r9   rJ   r9   rK   r9   rL   rM   rN   r5   rO   rA   rP   rQ   rR   rH   rS   rH   rT   rM   rU   r?   rV   rM   )r   r#   )rP   r   )r   r   r   r?   )r   r   r   Nr[   )rp  r'   rs  rM   r   rM   r~  rM   rt  r  ru  r  r   r  )r  r5   r   r9   )r  r5   r   r9   )7rD  
__module____qualname____doc__r   APP_VERSIONplatformpython_implementationpython_versionDEVICE_MODELsystemreleaseSYSTEM_VERSION	LANG_CODEr   sysargvr>  
PARENT_DIRrecompileINVITE_LINK_REr   os	cpu_countWORKERSWORKDIRr   MAX_CONCURRENT_TRANSMISSIONSr   r  readfpr
   r*   r5   r   	ParseModeDEFAULTr   SLEEP_THRESHOLDrb   r   r   r   r   r   r   r  r)  rQ  r}  rb  r  r  __classcell__)r   s   @r^   r/   r/   I   s       w wr -{,,K4h466TT9P9P9R9RTTL'))@@,<H,<,>,>@@NIchqk"")JRZ_ N c"|r|~~*a/00GG !(#$ 	IXXj))***
 $(#&(,"! $%)59!%#'!%#s7||#&+o&="&#&6#,H7hP hP hP hP hP hP hPT" " "  D D D v v v vp$% $% $% $%L4 4 4 4lM M M^0! 0! 0!dXP XP XPt4# 4# 4#r $(!H! H! H! H! H!T6 6 6 69 9 9 9 9 9 9 9r`   r/   c                  "    e Zd ZddZd Zd ZdS )rx   capacityrM   c                "    || _         i | _        d S r   )r  store)r   r  s     r^   rb   zCache.__init__Q  s     


r`   c                8    | j                             |d           S r   )r  r9  )r   keys     r^   __getitem__zCache.__getitem__U  s    z~~c4(((r`   c                   || j         v r| j         |= || j         |<   t          | j                   | j        k    rDt          | j        dz  dz             D ]+}| j         t	          t          | j                             = *d S d S )Nr   r%   )r  r  r  r  nextiter)r   r  r   rW  s       r^   __setitem__zCache.__setitem__X  s    $*
3
3tz??T]**4=A-122 7 7JtD$4$45566 +*7 7r`   N)r  rM   )rD  r  r  rb   r  r  r[   r`   r^   rx   rx   P  sF           ) ) )7 7 7 7 7r`   rx   )Q
__future__r   rl   r   r  r  loggingr  r  r\  r  rg  r^  r  concurrent.futures.threadr   r   r   hashlibr   	importlibr   ior	   r
   r  r   pathlibr   typingr   r   rl  r   r   r   r   r   hydrogram.cryptor   hydrogram.errorsr   r   r   r   r   r   hydrogram.handlers.handlerr   hydrogram.methodsr   hydrogram.sessionr   r   hydrogram.storager   r    hydrogram.typesr!   r"   r#   hydrogram.utilsr$   rg   r&   rp  r'   r(   r)   r*   ri   r+   session.internalsr,   collections.abcr-   	getLoggerrD  r   r/   rx   r[   r`   r^   <module>r     sB  ( # " " " " "            				   				   



 8 8 8 8 8 8 ( ( ( ( ( ( ( (       # # # # # #                             * * * * * * * *     A A A A A A A A A A A A A A                            / . . . . . % % % % % % + + + + + + + + 8 8 8 8 8 8 8 8 ? ? ? ? ? ? ? ? ? ? " " " " " " " " " " " " 6 6 6 6 6 6 6 6 6 6 " " " " " "       $ $ $ $ $ $ /......g!!D9 D9 D9 D9 D9W D9 D9 D9N 7 7 7 7 7 7 7 7 7 7r`   