
    $ShL)                     P   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mZmZmZ d dlZd dlmZmZ d dlmZ d dlmZmZmZmZ dEd
ddedefdZ	 	 dFdedededed         fdZ	 dGdddeded         fdZded         fdZdHdZ deddfd Z!d!Z"d"Z#d#Z$d$Z%d%Z&d&ej'        j(        dee         fd'Z)d&ej'        j(        defd(Z*d)edefd*Z+d)edefd+Z,d,e-defd-Z.d.ede-fd/Z/d0e-de-fd1Z0d2e-d,e-de-fd3Z1d4ej        j2        d5ede-fd6Z3d7ej        j4        j5        d5edej        j6        fd8Z7d9d:d;ed<ej8        d=ed>         deeeeeej'        j9                 f         f         f
d?Z:defd@Z;dAee         dee         fdBZ<dCee         dee         fdDZ=dS )I    N)ThreadPoolExecutor)datetimetimezone)getpass)UnionListDictOptional)rawenums)types)FileIdFileTypePHOTO_TYPESDOCUMENT_TYPES F)hidepromptr   c                   K   t          d          5 }t          j        |rt          nt          |           }t          j                                        ||           d{V cddd           S # 1 swxY w Y   dS )z'Just like the built-in input, but async   N)r   	functoolspartialr   inputasyncioget_event_looprun_in_executor)r   r   executorfuncs       T/var/www/html/movieo_spanner_bot/venv/lib/python3.11/site-packages/pyrogram/utils.pyainputr    $   s      	A		 N( D!;eVDD+--==hMMMMMMMMN N N N N N N N N N N N N N N N N Ns   AA//A36A3file_idexpected_file_typettl_secondsreturn)zraw.types.InputMediaPhotozraw.types.InputMediaDocumentc                    	 t          j        |           }n!# t          $ r t          d|  d          w xY w|j        }|&||k    r t          d|j         d|j         d          |t          j        t          j        fv rt          d|            |t          v rPt          j                            t          j                            |j        |j        |j                  |          S |t"          v rPt          j                            t          j                            |j        |j        |j                  |          S t          d	|            )
NzFailed to decode "zS". The value does not represent an existing local file, HTTP URL, or valid file id.z	Expected z, got z file id insteadz,This file id can only be used for download: )idaccess_hashfile_reference)r&   r#   zUnknown file id: )r   decode	Exception
ValueError	file_typenamer   	THUMBNAIL
CHAT_PHOTOr   r   r   InputMediaPhoto
InputPhotomedia_idr'   r(   r   InputMediaDocumentInputDocument)r!   r"   r#   decodedr,   s        r   get_input_media_from_file_idr6   +   s   

-(( 
 
 
+ + + +
 
 	

 !I%)7I*I*Id%7%<ddINdddeeeX')<===QQQRRRKy((y####/&5 $  
 $ ) 
 
 	
 N""y++y&&##/&5 '  
 $ , 
 
 	
 222
3
33s    5r   messageszraw.types.messages.Messagesrepliesztypes.Messagec           
      n  K   d |j         D             }d |j        D             }|j        st          j                    S g }|j        D ]?}|                    t          j                            | |||d           d {V            @|rd |j        D             }|r|D ]}|j        r|j        j	        }	 nd}	| 
                    |	|                                |dz
             d {V }
|D ]4}|                    |j	        d           }|
D ]}|j	        |k    r||_        5t          j        |          S )Nc                     i | ]
}|j         |S  r&   .0is     r   
<dictcomp>z"parse_messages.<locals>.<dictcomp>\       ---QT1---    c                     i | ]
}|j         |S r;   r<   r=   s     r   r@   z"parse_messages.<locals>.<dictcomp>]   rA   rB   r   )r8   c                 ~    i | ]:}t          |t          j        j                  !|j        (|j        |j        j        ;S r;   )
isinstancer   r   MessageEmptyreply_tor&   reply_to_msg_idr=   s     r   r@   z"parse_messages.<locals>.<dictcomp>h   sR     !
 !
 !
a!788!
 >?Z!
D!*,!
 !
 !
rB   r   )reply_to_message_idsr8   )userschatsr7   r   r   appendMessage_parsechatr&   get_messageskeysgetreply_to_message)clientr7   r8   rJ   rK   parsed_messagesmessagemessages_with_repliesmchat_idreply_messagesreply_idreplys                r   parse_messagesr]   W   s     
 .-hn---E--hn---E z||O$ e eU]%9%9&'5RWab%9%c%cccccccdddd 9!
 !
&!
 !
 !
 ! 	9 %  6 fiGE #)#6#6%:%?%?%A%A! $7 $ $      N + 9 9044WZFF+ 9 9Ex8++3809 :o&&&rB   c                 &   |j         }t          |dd           }g }|D ]a}|                    t          j        ||3t          j        t          |          t          j        j	        |           nd |                      bt          j
        |          S )N
channel_id)r&   typerT   )r&   rO   rT   )r7   getattrrL   r   rM   Chatget_channel_idr   ChatTypeCHANNELr   )rT   updater7   r_   rU   rV   s         r   parse_deleted_messagesrg      s    Ht44JO 
 
M
  +	 Z%j11/!    26  
	
 
	
 
	
 
	
 :o&&&rB   msg_id raw.base.InputBotInlineMessageIDc                 X   t          | t          j        j                  r't	          j        d| j        | j        | j                  }n,t	          j        d| j        | j	        | j        | j                  }t          j        |                                                              d          S )N<iqq<iqiq=)rE   r   r   InputBotInlineMessageIDstructpackdc_idr&   r'   owner_idbase64urlsafe_b64encoder)   rstrip)rh   inline_message_id_packeds     r   pack_inline_message_idrw      s    &#);<< 
#);LI	$
 $
   $*;LOI$
 $
  #$<==DDFFMMcRRRrB   inline_message_idc                    | dt          |            dz  z  z   }t          j        |          }t          |          dk    rIt          j        d|          }t
          j                            |d         |d         |d                   S t          j        d	|          }t
          j                            |d         |d         |d         |d
                   S )Nrm         rk   r   r      )rq   r&   r'   rl      )rq   rr   r&   r'   )	lenrs   urlsafe_b64decodero   unpackr   r   rn   InputBotInlineMessageID64)rx   paddedr5   unpackeds       r   unpack_inline_message_idr      s    ->)?)?(?!(C!DDF&v..G
7||r=11y001+{  1 
 
 	
 ='22y221+a[{ 	 3 
 
 	
rB   lJ)l J)i  il   J)peerc                     t          | t          j        j                  r| j        S t          | t          j        j                  r| j        S t          | t          j        j                  r| j        S dS )z&Get the raw peer id from a Peer objectN)	rE   r   r   PeerUseruser_idPeerChatrY   PeerChannelr_   r   s    r   get_raw_peer_idr      sd    $	*++ |$	*++ |$	-.. 4rB   c                    t          | t          j        j                  r| j        S t          | t          j        j                  r| j         S t          | t          j        j                  rt          | j	        z
  S t          d|            )z*Get the non-raw peer id from a Peer objectzPeer type invalid: )rE   r   r   r   r   r   rY   r   MAX_CHANNEL_IDr_   r+   r   s    r   get_peer_idr      s}    $	*++ |$	*++ }$	-.. 0//
1411
2
22rB   peer_idc                     | dk     r*t           | k    rdS t          | cxk    rt          k     rn ndS nd| cxk     rt          k    rn ndS t	          d|            )Nr   rO   channeluserzPeer id invalid: )MIN_CHAT_IDMIN_CHANNEL_IDr   MAX_USER_IDr+   r   s    r   get_peer_typer      s    {{'!!6W5555~555559 6	
W	#	#	#	#	#	#	#	#	#v
222
3
33rB   c                     t           | z
  S N)r   r   s    r   rc   rc      s    G##rB   bc                 8    t                               | d          S )Nbig)int
from_bytes)r   s    r   btoir      s    >>!U###rB   r?   c                 .    |                      dd          S )N   r   )to_bytes)r?   s    r   itobr     s    ::c5!!!rB   datac                 N    t          j        |                                           S r   )hashlibsha256digest)r   s    r   r   r     s    >$&&(((rB   ac                 P    t          d t          | |          D                       S )Nc              3   &   K   | ]\  }}||z  V  d S r   r;   )r>   r?   js      r   	<genexpr>zxor.<locals>.<genexpr>
  s*      --41aQ------rB   )byteszip)r   r   s     r   xorr   	  s'    --3q!99------rB   algopasswordc                    t          | j        |                                z   | j        z             }t          | j        |z   | j        z             }t	          j        d|| j        d          }t          | j        |z   | j        z             S )Nsha512i )r   salt1encodesalt2r   pbkdf2_hmac)r   r   hash1hash2hash3s        r   compute_password_hashr     sx     4: 1 11DJ>??E4:%
233E%VDDE$*u$tz1222rB   rc                    | j         }|j        }t          |j                  }t          |j                  }|j        }| j        }t          |          }| j        }	t          ||          }
t          |
          }t          |||          }t          ||z             }t          |          }||z  |z  }	 t          j        d          }t          |          }t          |||          }t          |          }t          t          ||z                       }|dk    rnj||z
  |z  }||z  }||z   }t          |||          }t          |          }t          |          }t          t          t          |          t          |                    t          |j                  z   t          |j                  z   |z   |z   |z             }t          j                            |	||          S )NTr   r   )srp_idAM1)current_algopr   r   gsrp_Br   r   powr   osurandomr   r   r   r   r   InputCheckPasswordSRP)r   r   r   p_bytesr   g_bytesr   B_bytesBr   x_bytesxg_xk_byteskkg_xa_bytesr   r   A_bytesug_buxa_uxSS_bytesK_bytesM1_bytess                               r   compute_password_checkr     s    >DfGTVA46llGAgGWAXF#D(33GWA
aA,,CWw&''GWAGq=D
*S//MM1aLLq''')**++q55
 t8q.C	
QBr6DCqA1ggGWooGF7OOVG__--


	


	 	 		
 	 H 9**&G*QQQrB   rT   zpyrogram.Clienttext
parse_modeentitiesztypes.MessageEntityc                    K   |r#|D ]	}| |_         
|d |D              d {V pd }}n6| j                            ||           d {V                                 \  }}||dS )Nc                 F   K   g | ]}|                                  d {V S r   )write)r>   entitys     r   
<listcomp>z'parse_text_entities.<locals>.<listcomp>`  s6      LLLfllnn 4 4 4 4 4 4LLLrB   )rV   r   )_clientparserparsevalues)rT   r   r   r   r   s        r   parse_text_entitiesr   U  s        P 	$ 	$F#FNNLL8LLLLLLLLLTPTh & 3 3D* E EEEEEEEMMOOh   rB   c                  @    t          j        dt          j                  S )Nr   )r   fromtimestampr   utcr;   rB   r   zero_datetimer   j  s    !!X\222rB   tsc                 2    | rt          j        |           nd S r   )r   r   )r   s    r   timestamp_to_datetimer   n  s    )+58!"%%%5rB   dtc                 L    | r!t          |                                           nd S r   )r   	timestamp)r   s    r   datetime_to_timestampr   r  s"    "$.3r||~~$.rB   )r   )NN)r   )rh   ri   )>r   rs   r   r   r   ro   concurrent.futures.threadr   r   r   r   typingr   r   r	   r
   pyrogramr   r   r   pyrogram.file_idr   r   r   r   strboolr    r   r6   r]   rg   rw   r   r   r   r   MAX_USER_ID_OLDr   basePeerr   r   r   rc   r   r   r   r   r   APasswordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPowr   accountPasswordr   r   	ParseModeMessageEntityr   r   r   r   r;   rB   r   <module>r     s  &        				  8 8 8 8 8 8 ' ' ' ' ' ' ' '       . . . . . . . . . . . .                J J J J J J J J J J J JN5 N N N ND N N N N $()4 )4)4 )4 )4 FG	)4 )4 )4 )4^ .' .'+.' .' 
/	.' .' .' .'b'd?.C ' ' ' ',S S S S(
 
8Z 
 
 
 
.  #(- HSM    3chm 3 3 3 3 3
43 
43 
4 
4 
4 
4$C $C $ $ $ $$E $c $ $ $ $"C "E " " " ") )5 ) ) ) ).5 .U .u . . . .3
)
U33 3 3 3 39R
y!9R9R 	Y$9R 9R 9R 9Rx
  ()	
 
#uS$sx5667
78   *3x 3 3 3 36hsm 60B 6 6 6 6/hx0 /Xc] / / / / / /rB   