a
    /3eQ                    @   sB  d dl Z d dlZd dlZd dlZd dlmZ zd dlZW n eyR   d dlZY n0 d dl	Z	dZ
d dlmZ d dlmZ d dlZedZdZdZdZdZdZd	ZG d
d dZe ZdddZdd ZdddZdd Zdd Zdd Zdd Zdd Zdd Z dd  Z!dd!d"Z"dd#d$Z#dd%d&Z$dd'd(Z%ej&d)d*d+Z'dd,d-Z(dd.d/Z)d0d1 Z*d2d3 Z+d4d5 Z,d6d7 Z-d8d9 Z.d:d; Z/d<d= Z0ej1d)d>d?Z2d@dA Z3ddBdCZ4ddDdEZ5ddFdGZ6d dHdIZ7d!dJdKZ8d"dLdMZ9d#dNdOZ:d$dPdQZ;d%dRdSZ<d&dTdUZ=d'dVdWZ>d(dXdYZ?d)dZd[Z@d*d\d]ZAd+d^d_ZBd,d`daZCd-dbdcZDddde ZEd.dfdgZFdhdi ZGd/djdkZHd0dldmZIdndo ZJdpdq ZKdrds ZLd1dtduZMdvdw ZNdxdy ZOdzd{ ZPd|d} ZQd~d ZRdd ZSdd ZTdd ZUdd ZVd2ddZWd3ddZXd4ddZYd5ddZZd6ddZ[d7ddZ\d8ddZ]d9ddZ^d:ddZ_d;ddZ`d<ddZad=ddZbd>ddZcdd Zdd?ddZedd Zfdd Zgd@ddZhdAddZidBddZjdCddZkdDddZldEddZmdFddZndGddZodHddZpdIddZqdJddZrdd ZsdKddÄZtdLddńZuddǄ ZvddɄ ZwdMdd˄ZxdNdd̈́Zyddτ Zzddф Z{ddӄ Z|dOddՄZ}ddׄ Z~dPddلZddۄ Zdd݄ Zdd߄ ZdQddZdRddZdSddZdTddZdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zdd Zdd Zdd Zdd ZdUd	d
ZG dd deZG dd deZG dd deZG dd deZG dd deZdS (V      N)typesz#https://api.telegram.org/bot{0}/{1})datetime)utilZTeleBoti,     2   c                   @   s*   e Zd ZddddZdd Zdd ZdS )	SessionManagerN)returnc                 C   s   d | _ tjt d| _d S )N)cafile)sessionsslcreate_default_contextcertifiwheressl_contextself r   I/home/pi/bot/my_env/lib/python3.9/site-packages/telebot/asyncio_helper.py__init__    s    zSessionManager.__init__c                    s    t jt jt| jdd| _| jS )N)limitr   )Z	connector)aiohttpZClientSessionZTCPConnectorREQUEST_LIMITr   r
   r   r   r   r   create_session%   s
    zSessionManager.create_sessionc                    sj   | j d u r |  I d H | _ | j S | j jr8|  I d H | _ | j j sd| j  I d H  |  I d H | _ | j S N)r
   r   closedZ_loopZ
is_runningcloser   r   r   r   get_session,   s    
zSessionManager.get_session)__name__
__module____qualname__r   r   r   r   r   r   r   r      s   r   getc                    s  d|v r| d}n|r$| dd nd }|d u r4tn|}t||}tj|d}d}d}	t I d H }
|s|	td k r|	d7 }	z|
j|t	
| |||td4 I d H }d}td	
||||||	| | d
d d  t||I d H }|r|d W  d   I d H  W S W d   I d H  q>1 I d H s40    Y  W n tttfyp } z|W Y d }~n|d }~0  tjy } z td
|jj W Y d }~nBd }~0  ty } z td|jj  W Y d }~n
d }~0 0 |sdtd
||||||	qdd S )Nrequest_timeouttimeout)totalFr      )methodurldatar"   proxyTzTRequest: method={0} url={1} params={2} files={3} request_timeout={4} current_try={5}:z:{TOKEN}resultzAiohttp ClientError: {0}zUnknown error: zURequest timeout. Request: method={0} url={1} params={2} files={3} request_timeout={4})popREQUEST_TIMEOUT_prepare_datar   ZClientTimeoutsession_managerr   MAX_RETRIESrequestAPI_URLformatr(   loggerdebugreplacesplit_check_resultApiTelegramExceptionApiInvalidJSONExceptionApiHTTPExceptionZClientErrorerror	__class__r   	ExceptionRequestTimeout)tokenr&   r%   paramsfileskwargsr!   r"   Z
got_resultZcurrent_tryr
   respZjson_resulter   r   r   _process_request=   s4    
&0P(*rE   c                 C   sB   t | dd}|r>t|tr>|d dkr>|d dkr>tj|S dS )z#
    Prepares file for upload.
    nameNr   <>)getattr
isinstancestrospathbasename)objrF   r   r   r   _prepare_filek   s    &rQ   c                 C   s   t jjdd}| r4|  D ]\}}||t| q|r| D ]n\}}t|trrt|dkrh|\}}qt	dn,t|t
jr|j}|j}nt|p|| }}|j|||d q@|S )zj
    Adds the parameters and files to the request.

    :param params:
    :param files:
    :return:
    F)Zquote_fields   z5Tuple must have exactly 2 elements: filename, fileobj)filename)r   ZformdataZFormDataitemsZ	add_fieldrL   rK   tuplelen
ValueErrorr   Z	InputFile	file_namefilerQ   )r@   rA   r'   keyvaluefrX   rY   r   r   r   r-   s   s     


r-   c                    s   t | tjr|  S | S r   )rK   r   JsonSerializableto_json)Zmarkupr   r   r   _convert_markup   s    r_   c                    s   d}t | |I d H S )NZgetMerE   r?   
method_urlr   r   r   get_me   s    rc   c                    s   d}t | |I d H S )NZlogOutr`   ra   r   r   r   log_out   s    rd   c                    s   d}t | |I d H S )Nr   r`   ra   r   r   r   r      s    r   c                    s   d}t | |d|idI d H S )NZgetFilefile_idr@   r`   )r?   re   rb   r   r   r   get_file   s    rg   c                    sD   t d u r$d| t| |I d H d S t | t| |I d H d S d S )N(https://api.telegram.org/file/bot{0}/{1}	file_path)FILE_URLr2   rg   )r?   re   r   r   r   get_file_url   s    rk   c              	      s   t d u rd| |}nt | |}t I d H }|j|td4 I d H 8}|jdkr\td|| I d H }W d   I d H  q1 I d H s0    Y  |S )Nrh   )r(      zDownload file)	rj   r2   r.   r   r    r(   statusr:   read)r?   ri   r&   r
   responser*   r   r   r   download_file   s    

8rp   c	                    s   d}	d|r|ndi}
d }|r$d|i}|r0||
d< |d urFt ||
d< |d urV||
d< |d urf||
d< |rr||
d	< |r~||
d
< t| |	|
|dI d H S )NZ
setWebhookr&    certificatemax_connectionsallowed_updates
ip_addressdrop_pending_updatesr"   secret_tokenr@   rA   jsondumpsrE   )r?   r&   rr   rs   rt   ru   rv   r"   rw   rb   payloadrA   r   r   r   set_webhook   s&    r}   c                    s8   d}i }|d ur||d< |r$||d< t | ||dI d H S )NZdeleteWebhookrv   r"   rf   r`   )r?   rv   r"   rb   r|   r   r   r   delete_webhook   s    r~   c                    s(   d}i }|r||d< t | ||dI d H S )NZgetWebhookInfor"   rf   r`   )r?   r"   rb   r|   r   r   r   get_webhook_info   s
    r   c                    sX   d}i }|r||d< |r ||d< |r,||d< |d urBt ||d< t| |||dI d H S )NZ
getUpdatesoffsetr   r"   rt   )r@   r!   ry   )r?   r   r   r"   rt   r!   method_namer@   r   r   r   get_updates   s    r   r*   c                    s`   z|j ddI dH }W n,   |jdkr4t| |n
t| |Y n0 |d sXt| |||S dS )a  
    Checks whether `result` is a valid API response.
    A result is considered invalid if:
        - The server returned an HTTP response code other than 200
        - The content of the result is invalid JSON.
        - The method call was unsuccessful (The JSON 'ok' field equals False)

    :raises ApiException: if one of the above listed cases is applicable
    :param method_name: The name of the method called
    :param result: The returned result of the method request
    :return: The result parsed to a JSON dictionary.
    zutf-8)encodingNrl   ok)rz   rm   r:   r9   r8   )r   r*   result_jsonr   r   r   r7      s    
r7   c                    s   d}t ||d}|d ur"||d< |r.||d< |rDt|I d H |d< |rP||d< |d ur`||d< |rl||d< |	rttj|	|d	< |
d ur|
|d
< |d ur||d< |r||d< t| ||dI d H S )NZsendMessage)chat_idtextdisable_web_page_previewreply_to_message_idreply_markup
parse_modedisable_notificationr"   entitiesallow_sending_without_replyprotect_contentmessage_thread_idrf   )rL   r_   rz   r{   r   MessageEntityto_list_of_dictsrE   )r?   r   r   r   r   r   r   r   r"   r   r   r   r   r   r@   r   r   r   send_message  s.    r   c                    s8   d}d|i}|r||d< |r$||d< t | ||dI d H S )NZgetUserProfilePhotosuser_idr   r   rf   r`   )r?   r   r   r   rb   r|   r   r   r   get_user_profile_photos8  s    r   c                    s    d}d|i}t | ||dI d H S )NZgetChatr   rf   r`   r?   r   rb   r|   r   r   r   get_chatB  s    r   c                    s    d}d|i}t | ||dI d H S )NZ	leaveChatr   rf   r`   r   r   r   r   
leave_chatH  s    r   c                    s    d}d|i}t | ||dI d H S )NZgetChatAdministratorsr   rf   r`   r   r   r   r   get_chat_administratorsN  s    r   c                    s    d}d|i}t | ||dI d H S )NZgetChatMemberCountr   rf   r`   r   r   r   r   get_chat_member_countT  s    r   c                    sL   d}||d}i }|r2t |ts*||d< n||d< t| |||p@d dI d H S )NZsetStickerSetThumbnail)rF   r   	thumbnailrx   )rK   rL   rE   )r?   rF   r   r   rb   r|   rA   r   r   r   set_sticker_set_thumbnailZ  s    


r   c                    s"   d}||d}t | ||dI d H S )NZsetChatStickerSet)r   sticker_set_namerf   r`   )r?   r   r   rb   r|   r   r   r   set_chat_sticker_setf  s    
r   c                    s    d}d|i}t | ||dI d H S )NZdeleteChatStickerSetr   rf   r`   r   r   r   r   delete_chat_sticker_setl  s    r   c                    s(   d}||  d}t| ||ddI d H S )NZanswerWebAppQuery)web_app_query_idr*   postr@   r%   r^   rE   )r?   r   r*   rb   r|   r   r   r   answer_web_app_queryr  s    r   c                    s"   d}||d}t | ||dI d H S )NZgetChatMemberr   r   rf   r`   r?   r   r   rb   r|   r   r   r   get_chat_memberx  s    
r   c           
         s\   d}|||d}	|d ur ||	d< |r,||	d< |d ur<||	d< |rH||	d< t | ||	dI d H S )NZforwardMessager   from_chat_id
message_idr   r"   r   r   rf   r`   )
r?   r   r   r   r   r"   r   r   rb   r|   r   r   r   forward_message~  s    r   c                    s   d}|||d}|d ur ||d< |r,||d< |d urFt |I d H |d< |d urV||d< |rb||d< |
d ur|t|
I d H |d< |	d ur|	|d	< |r||d
< |d ur||d< |r||d< t| ||dI d H S )NZcopyMessager   captionr   caption_entitiesr   r   r   r   r"   r   r   rf   )_convert_entitesr_   rE   )r?   r   r   r   r   r   r   r   r   r   r   r"   r   r   rb   r|   r   r   r   copy_message  s.    r   c
                    s   d}
d|i}|r||d< |d ur(||d< |r4||d< |rJt |I d H |d< |rV||d< |d urf||d< |d urv||d	< |	r|	|d
< t| |
|dI d H S )NZsendDicer   emojir   r   r   r"   r   r   r   rf   r_   rE   )r?   r   r   r   r   r   r"   r   r   r   rb   r|   r   r   r   	send_dice  s&    r   c                    s
  d}d|i}d }t |r$||d< n"t |r>dt |i}nd|i}|rR||d< |r^||d< |rtt|I d H |d< |r||d< |d ur||d< |r||d	< |	rttj	|	|d
< |
d ur|
|d< |d ur||d< |r||d< |d ur||d< t
| |||ddI d H S )NZ	sendPhotor   photor   r   r   r   r   r"   r   r   r   r   has_spoilerr   r@   rA   r%   )r   	is_stringis_pil_imagepil_image_to_filer_   rz   r{   r   r   r   rE   )r?   r   r   r   r   r   r   r   r"   r   r   r   r   r   rb   r|   rA   r   r   r   
send_photo  s>    


r   c	                    s   d}	t |I d H \}
}||
d}|d ur0||d< |r<||d< |rH||d< |d urX||d< |d urh||d< |rt||d< t| |	||rd	nd
|r|nd dI d H S )NZsendMediaGroup)r   mediar   r   r"   r   r   r   r   r    )r@   r%   rA   )convert_input_media_arrayrE   )r?   r   r   r   r   r"   r   r   r   rb   
media_jsonrA   r|   r   r   r   send_media_group  s(    


r   c                    s   d}|||d}|r||d< |	r(|	|d< |
r4|
|d< |r@||d< |rL||d< |d ur\||d< |rrt |I d H |d	< |d ur||d
< |r||d< |d ur||d< |r||d< t| ||dI d H S )NZsendLocation)r   latitude	longitudelive_periodhorizontal_accuracyheadingproximity_alert_radiusr   r   r   r   r"   r   r   rf   r   )r?   r   r   r   r   r   r   r   r"   r   r   r   r   r   r   rb   r|   r   r   r   send_location  s2    r   c                    s   d}||d}|r||d< |r&||d< |r2||d< |	r>|	|d< |
rJ|
|d< |rV||d< |rlt |I d H |d	< |rx||d
< t| ||dI d H S )NZeditMessageLiveLocation)r   r   r   r   r   r   r   inline_message_idr   r"   rf   r   )r?   r   r   r   r   r   r   r"   r   r   r   rb   r|   r   r   r   edit_message_live_location'  s&    
r   c                    sb   d}i }|r||d< |r ||d< |r,||d< |rBt |I d H |d< |rN||d< t| ||dI d H S )NZstopMessageLiveLocationr   r   r   r   r"   rf   r   )r?   r   r   r   r   r"   rb   r|   r   r   r   stop_message_live_location@  s    r   c                    s   d}|||||d}|r ||d< |r,||d< |d ur<||d< |	rH|	|d< |
r^t |
I d H |d< |rj||d< |d urz||d	< |r||d
< |r||d< |d ur||d< |r||d< t| ||dI d H S )NZ	sendVenue)r   r   r   titleaddressfoursquare_idfoursquare_typer   r   r   r"   r   google_place_idgoogle_place_typer   r   rf   r   )r?   r   r   r   r   r   r   r   r   r   r   r"   r   r   r   r   r   rb   r|   r   r   r   
send_venueR  s2    r   c                    s   d}|||d}|r||d< |r(||d< |d ur8||d< |rD||d< |rZt |I d H |d< |	rf|	|d< |
d urv|
|d	< |d ur||d
< |r||d< t| ||dI d H S )NZsendContact)r   phone_number
first_name	last_namevcardr   r   r   r"   r   r   r   rf   r   )r?   r   r   r   r   r   r   r   r   r"   r   r   r   rb   r|   r   r   r   send_contacts  s*    r   c                    s:   d}||d}|r||d< |r&||d< t | ||dI d H S )NZsendChatAction)r   actionr"   r   rf   r`   )r?   r   r   r"   r   rb   r|   r   r   r   send_chat_action  s    
r   c                    sZ  d}d|i}d }t |s$d|i}n||d< |r8||d< |rD||d< |rP||d< |rft|I d H |d< |rr||d< |d ur||d	< |	d ur|	|d
< |
r|
|d< |rt |s|r||d< qd|i}n||d< |r||d< |r||d< |rttj||d< |d ur||d< |d ur"||d< |r0||d< |d urB||d< t| |||ddI d H S )NZ	sendVideor   videodurationr   r   r   r   supports_streamingr   r"   r   widthheightr   r   r   r   r   r   r   	r   r   r_   rz   r{   r   r   r   rE   )r?   r   r'   r   r   r   r   r   r   r   r"   r   r   r   r   r   r   r   r   rb   r|   rA   r   r   r   
send_video  sV    







r   c                    sH  d}d|i}d }t |s$d|i}n||d< |r8||d< |rD||d< |rP||d< |rft|I d H |d< |rr||d< |d ur||d	< |	r|	|d
< |
rt |
s|r|
|d< qd|
i}n|
|d< |rttj||d< |d ur||d< |r||d< |r||d< |d ur||d< |r||d< |d ur0||d< t| |||ddI d H S )NZsendAnimationr   Z	animationr   r   r   r   r   r   r"   r   r   r   r   r   r   r   r   r   r   r   )r?   r   r'   r   r   r   r   r   r   r"   r   r   r   r   r   r   r   r   rb   r|   rA   r   r   r   send_animation  sR    






r   c                    s   d}d|i}d }t |s$d|i}n||d< |r8||d< |rD||d< |rP||d< |rft|I d H |d< |rr||d< |d ur||d	< |	r|	|d
< |
rttj|
|d< |d ur||d< |d ur||d< |r||d< t| |||ddI d H S )NZ	sendVoicer   voicer   r   r   r   r   r   r"   r   r   r   r   r   r   r   )r?   r   r   r   r   r   r   r   r   r"   r   r   r   r   rb   r|   rA   r   r   r   
send_voice  s:    

r   c                    s  d}d|i}d }t |s$d|i}n||d< |r8||d< |r^t| r^t|dkr^||d< nd|d< |rr||d< |rt|I d H |d< |d ur||d	< |r||d
< |	rt |	s|r|	|d< qd|	i}n|	|d< |
d ur|
|d< |d ur||d< |r||d< t| |||ddI d H S )NZsendVideoNoter   Z
video_noter   i  lengthr   r   r   r"   r   r   r   r   r   r   )r   r   rL   isdigitintr_   rE   )r?   r   r'   r   r   r   r   r   r"   r   r   r   r   rb   r|   rA   r   r   r   send_video_note"  s@    





r   c                    s6  d}d|i}d }t |s$d|i}n||d< |r8||d< |rD||d< |rP||d< |r\||d< |rh||d< |r~t|I d H |d	< |	r|	|d
< |
d ur|
|d< |r||d< |rt |s|r||d< qd|i}n||d< |rttj||d< |d ur||d< |d ur||d< |r||d< t| |||ddI d H S )NZ	sendAudior   audior   r   	performerr   r   r   r   r   r"   r   r   r   r   r   r   r   r   )r?   r   r   r   r   r   r   r   r   r   r   r"   r   r   r   r   r   rb   r|   rA   r   r   r   
send_audioK  sN    





r   c                    s^  t |I d H }d|i}d }t|s>|}|r4||f}||i}n|||< |rR||d< |rht|I d H |d< |r||dkr|||d< |d ur||d< |r||d< |	r|	|d< |
rt|
s|r|
|d	< qd	|
i}n|
|d	< |rttj||d
< |d ur||d< |d ur||d< |dkr*|d ur*||d< |r8||d< |rF||d< t	| |||ddI d H S )Nr   r   r   documentr   r   r"   r   r   r   r   r   sendDocumentdisable_content_type_detectionr   r   r   r   )
get_method_by_typer   r   r_   rz   r{   r   r   r   rE   )r?   r   r'   	data_typer   r   r   r   r"   r   r   r   r   r   Zvisible_file_namer   r   r   rb   r|   rA   Z	file_datar   r   r   	send_dataz  sP    





r   c                    s   | dkrdS | dkrdS d S )Nr   r   stickerZsendStickerr   )r   r   r   r   r     s    r   c                    sT   d}||d}t |tr&| |d< n||d< |d ur>||d< t| ||ddI d H S )NZbanChatMemberr   
until_daterevoke_messagesr   r   rK   r   	timestamprE   )r?   r   r   r   r   rb   r|   r   r   r   ban_chat_member  s    

r   c                    s4   d}||d}|d ur||d< t | ||ddI d H S )NZunbanChatMemberr   only_if_bannedr   r   r`   )r?   r   r   r   rb   r|   r   r   r   unban_chat_member  s
    
r   c                    sb   d}|||  d}|d ur$||d< |d urLt|trD| |d< n||d< t| ||ddI d H S )NZrestrictChatMember)r   r   permissions use_independent_chat_permissionsr   r   r   )r^   rK   r   r   rE   )r?   r   r   r   r   r   rb   r|   r   r   r   restrict_chat_member  s    
r   c                    s  d}||d}|d ur||d< |d ur.||d< |d ur>||d< |d urN||d< |d ur^||d< |d urn||d< |	d ur~|	|d	< |
d ur|
|d
< |d ur||d< |d ur||d< |d ur||d< |d ur||d< |d ur||d< |d ur||d< |d ur||d< t | ||ddI d H S )NZpromoteChatMemberr   can_change_infocan_post_messagescan_edit_messagescan_delete_messagescan_invite_userscan_restrict_memberscan_pin_messagescan_promote_membersis_anonymouscan_manage_chatcan_manage_video_chatscan_manage_topicscan_post_storiescan_edit_storiescan_delete_storiesr   r   r`   )r?   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r  rb   r|   r   r   r   promote_chat_member  sB    
r  c                    s&   d}|||d}t | ||ddI d H S )NZsetChatAdministratorCustomTitle)r   r   custom_titler   r   r`   )r?   r   r   r	  rb   r|   r   r   r   #set_chat_administrator_custom_title  s    r
  c                    s$   d}||d}t | ||ddI d H S )NZbanChatSenderChatr   sender_chat_idr   r   r`   r?   r   r  rb   r|   r   r   r   ban_chat_sender_chat  s    
r  c                    s$   d}||d}t | ||ddI d H S )NZunbanChatSenderChatr  r   r   r`   r  r   r   r   unban_chat_sender_chat  s    
r  c                    s8   d}||  d}|d ur"||d< t| ||ddI d H S )NZsetChatPermissions)r   r   r   r   r   r   )r?   r   r   r   rb   r|   r   r   r   set_chat_permissions  s    r  c                    sr   d}d|i}|d ur4t |tr,| |d< n||d< |r@||d< |d urP||d< |r\||d< t| ||ddI d H S )	NZcreateChatInviteLinkr   expire_datemember_limitcreates_join_requestrF   r   r   r   )r?   r   rF   r  r  r  rb   r|   r   r   r   create_chat_invite_link  s    
r  c           	         sx   d}||d}|d ur6t |tr.| |d< n||d< |d urF||d< |rR||d< |d urb||d< t| ||ddI d H S )	NZeditChatInviteLinkr   invite_linkr  r  rF   r  r   r   r   )	r?   r   r  rF   r  r  r  rb   r|   r   r   r   edit_chat_invite_link2  s    
r  c                    s$   d}||d}t | ||ddI d H S )NZrevokeChatInviteLinkr  r   r   r`   )r?   r   r  rb   r|   r   r   r   revoke_chat_invite_linkH  s
    r  c                    s"   d}d|i}t | ||ddI d H S )NZexportChatInviteLinkr   r   r   r`   r   r   r   r   export_chat_invite_linkQ  s    r  c                    s$   d}||d}t | ||ddI d H S )NZapproveChatJoinRequestr   r   r   r`   r   r   r   r   approve_chat_join_requestV  s
    r  c                    s$   d}||d}t | ||ddI d H S )NZdeclineChatJoinRequestr   r   r   r`   r   r   r   r   decline_chat_join_request_  s
    r  c                    s^   d}d|i}d }t |r$||d< n"t |r>dt |i}nd|i}t| |||ddI d H S )NZsetChatPhotor   r   r   r   )r   r   r   r   rE   )r?   r   r   rb   r|   rA   r   r   r   set_chat_photoh  s    


r  c                    s"   d}d|i}t | ||ddI d H S )NZdeleteChatPhotor   r   r   r`   r   r   r   r   delete_chat_photou  s    r  c                    s$   d}||d}t | ||ddI d H S )NZsetChatTitle)r   r   r   r   r`   )r?   r   r   rb   r|   r   r   r   set_chat_title{  s    
r  c                    s>   d}i }|d ur||d< |d ur(||d< t | ||ddI d H S )NZsetMyDescriptiondescriptionlanguage_coder   r   r`   )r?   r  r   rb   r|   r   r   r   set_my_description  s    r!  c                    s(   d}i }|r||d< t | ||dI d H S )NZgetMyDescriptionr   rf   r`   r?   r   rb   r|   r   r   r   get_my_description  s
    r#  c                    s>   d}i }|d ur||d< |d ur(||d< t | ||ddI d H S )NZsetMyShortDescriptionshort_descriptionr   r   r   r`   )r?   r$  r   rb   r|   r   r   r   set_my_short_description  s    r%  c                    s(   d}i }|r||d< t | ||dI d H S )NZgetMyShortDescriptionr   rf   r`   r"  r   r   r   get_my_short_description  s
    r&  c                    s8   d}i }|r|  |d< |r$||d< t| ||dI d H S )NZgetMyCommandsscoper   rf   r   r?   r'  r   rb   r|   r   r   r   get_my_commands  s    r)  c                    s>   d}i }|d ur||d< |d ur(||d< t | ||ddI d H S )NZ	setMyNamerF   r   r   r   r`   )r?   rF   r   rb   r|   r   r   r   set_my_name  s    r*  c                    s,   d}i }|d ur||d< t | ||dI d H S )NZ	getMyNamer   rf   r`   r"  r   r   r   get_my_name  s
    r+  c                    s:   d}i }|r||d< |r$|  |d< t| ||ddI d H S )NZsetChatMenuButtonr   menu_buttonr   r   r   )r?   r   r,  rb   r|   r   r   r   set_chat_menu_button  s    r-  c                    s*   d}i }|r||d< t | ||ddI d H S )NZgetChatMenuButtonr   r   r   r`   r   r   r   r   get_chat_menu_button  s
    r.  c                    s>   d}i }|r|  |d< |d ur(||d< t| ||ddI d H S )NZsetMyDefaultAdministratorRightsrightsfor_channelsr   r   r   )r?   r/  r0  rb   r|   r   r   r   #set_my_default_administrator_rights  s    r1  c                    s*   d}i }|r||d< t | ||ddI d H S )NZgetMyDefaultAdministratorRightsr0  r   r   r`   )r?   r0  rb   r|   r   r   r   #get_my_default_administrator_rights  s
    r2  c                    sH   d}dt |I d H i}|r&| |d< |r2||d< t| ||ddI d H S )NZsetMyCommandscommandsr'  r   r   r   _convert_list_json_serializabler^   rE   )r?   r3  r'  r   rb   r|   r   r   r   set_my_commands  s    r6  c                    s:   d}i }|r|  |d< |r$||d< t| ||ddI d H S )NZdeleteMyCommandsr'  r   r   r   r   r(  r   r   r   delete_my_commands  s    r7  c                    s2   d}d|i}|d ur||d< t | ||ddI d H S )NZsetChatDescriptionr   r  r   r   r`   )r?   r   r  rb   r|   r   r   r   set_chat_description  s
    r8  c                    s4   d}||d}|d ur||d< t | ||ddI d H S )NZpinChatMessager   r   r   r   r   r`   )r?   r   r   r   rb   r|   r   r   r   pin_chat_message  s
    
r:  c                    s.   d}d|i}|r||d< t | ||ddI d H S )NZunpinChatMessager   r   r   r   r`   )r?   r   r   rb   r|   r   r   r   unpin_chat_message  s
    r;  c                    s"   d}d|i}t | ||ddI d H S )NZunpinAllChatMessagesr   r   r   r`   r   r   r   r   unpin_all_chat_messages  s    r<  c	                    s   d}	d|i}
|r||
d< |r$||
d< |r0||
d< |r<||
d< |rVt tj||
d< |d urf||
d< |r|t|I d H |
d	< t| |	|
d
dI d H S )NZeditMessageTextr   r   r   r   r   r   r   r   r   r   rz   r{   r   r   r   r_   rE   )r?   r   r   r   r   r   r   r   r   rb   r|   r   r   r   edit_message_text  s"    r>  c           
         s   d}d|i}	|r||	d< |r$||	d< |r0||	d< |r<||	d< |rVt tj||	d< |rlt|I d H |	d< t| ||	d	d
I d H S )NZeditMessageCaptionr   r   r   r   r   r   r   r   r   r=  )
r?   r   r   r   r   r   r   r   rb   r|   r   r   r   edit_message_caption(  s    r?  c           
         sx   d}t |I d H \}}d|i}	|r*||	d< |r6||	d< |rB||	d< |rXt|I d H |	d< t| ||	||rjdndd	I d H S )
NZeditMessageMediar   r   r   r   r   r   r    r   )convert_input_mediar_   rE   )
r?   r   r   r   r   r   rb   r   rY   r|   r   r   r   edit_message_media;  s    rA  c                    sX   d}i }|r||d< |r ||d< |r,||d< |rBt |I d H |d< t| ||ddI d H S )NZeditMessageReplyMarkupr   r   r   r   r   r   r   )r?   r   r   r   r   rb   r|   r   r   r   edit_message_reply_markupJ  s    rB  c                    s0   d}||d}|r||d< t | ||ddI d H S )NZdeleteMessager9  r"   r   r   r`   )r?   r   r   r"   rb   r|   r   r   r   delete_messageX  s
    
rC  c
                    s   d}
||d}|d ur||d< |r*||d< |r@t |I d H |d< |rL||d< |d ur\||d< |d url||d< |	rx|	|d	< t| |
|d
I d H S )NZsendGame)r   game_short_namer   r   r   r"   r   r   r   rf   r   )r?   r   rD  r   r   r   r"   r   r   r   rb   r|   r   r   r   	send_gameb  s"    
rE  c           
         sf   d}||d}	|dur||	d< |r*||	d< |r6||	d< |rB||	d< |durR||	d< t | ||	d	I dH S )
ay  
    Use this method to set the score of the specified user in a game. On success, if the message was sent by the bot, returns the edited Message, otherwise returns True. Returns an error, if the new score is not greater than the user's current score in the chat.
    :param token: Bot's token (you don't need to fill this)
    :param user_id: User identifier
    :param score: New score, must be non-negative
    :param force: (Optional) Pass True, if the high score is allowed to decrease. This can be useful when fixing mistakes or banning cheaters
    :param disable_edit_message: (Optional) Pass True, if the game message should not be automatically edited to include the current scoreboard
    :param chat_id: (Optional, required if inline_message_id is not specified) Unique identifier for the target chat (or username of the target channel in the format @channelusername)
    :param message_id: (Optional, required if inline_message_id is not specified) Unique identifier of the sent message
    :param inline_message_id: (Optional, required if chat_id and message_id are not specified) Identifier of the inline message
    :return:
    ZsetGameScore)r   scoreNforcer   r   r   disable_edit_messagerf   r`   )
r?   r   rF  rG  rH  r   r   r   rb   r|   r   r   r   set_game_scorez  s    
rI  c                    sD   d}d|i}|r||d< |r$||d< |r0||d< t | ||dI dH S )a  
    Use this method to get data for high score tables. Will return the score of the specified user and several of his neighbors in a game. On success, returns an Array of GameHighScore objects.
    This method will currently return scores for the target user, plus two of his closest neighbors on each side. Will also return the top three users if the user and his neighbors are not among them. Please note that this behavior is subject to change.
    :param token: Bot's token (you don't need to fill this)
    :param user_id: Target user id
    :param chat_id: (Optional, required if inline_message_id is not specified) Unique identifier for the target chat (or username of the target channel in the format @channelusername)
    :param message_id: (Optional, required if inline_message_id is not specified) Unique identifier of the sent message
    :param inline_message_id: (Optional, required if chat_id and message_id are not specified) Identifier of the inline message
    :return:
    ZgetGameHighScoresr   r   r   r   rf   Nr`   )r?   r   r   r   r   rb   r|   r   r   r   get_game_high_scores  s    rJ  c                     s  d}||||||t |I dH d}|r.||d< |	r:|	|d< |
rF|
|d< |rR||d< |r^||d< |durn||d	< |dur~||d
< |dur||d< |dur||d< |dur||d< |dur||d< |dur||d< |dur||d< |r||d< |rt|I dH |d< |r||d< |r||d< |dur0||d< |durB||d< |durZt||d< |durl||d< |rz||d< t| ||dI dH S )aJ  
    Use this method to send invoices. On success, the sent Message is returned.
    :param token: Bot's token (you don't need to fill this)
    :param chat_id: Unique identifier for the target private chat
    :param title: Product name
    :param description: Product description
    :param invoice_payload: Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use for your internal processes.
    :param provider_token: Payments provider token, obtained via @Botfather
    :param currency: Three-letter ISO 4217 currency code, see https://core.telegram.org/bots/payments#supported-currencies
    :param prices: Price breakdown, a list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.)
    :param start_parameter: Unique deep-linking parameter that can be used to generate this invoice when used as a start parameter
    :param photo_url: URL of the product photo for the invoice. Can be a photo of the goods or a marketing image for a service. People like it better when they see what they are paying for.
    :param photo_size: Photo size
    :param photo_width: Photo width
    :param photo_height: Photo height
    :param need_name: Pass True, if you require the user's full name to complete the order
    :param need_phone_number: Pass True, if you require the user's phone number to complete the order
    :param need_email: Pass True, if you require the user's email to complete the order
    :param need_shipping_address: Pass True, if you require the user's shipping address to complete the order
    :param is_flexible: Pass True, if the final price depends on the shipping method
    :param send_phone_number_to_provider: Pass True, if user's phone number should be sent to provider
    :param send_email_to_provider: Pass True, if user's email address should be sent to provider
    :param disable_notification: Sends the message silently. Users will receive a notification with no sound.
    :param reply_to_message_id: If the message is a reply, ID of the original message
    :param reply_markup: A JSON-serialized object for an inline keyboard. If empty, one 'Pay total price' button will be shown. If not empty, the first button must be a Pay button
    :param provider_data: A JSON-serialized data about the invoice, which will be shared with the payment provider. A detailed description of required fields should be provided by the payment provider.
    :param timeout:
    :param allow_sending_without_reply:
    :param max_tip_amount: The maximum accepted amount for tips in the smallest units of the currency
    :param suggested_tip_amounts: A JSON-serialized array of suggested amounts of tips in the smallest units of the currency.
        At most 4 suggested tip amounts can be specified. The suggested tip amounts must be positive, passed in a strictly increased order and must not exceed max_tip_amount.
    :param protect_content: Protects the contents of the sent message from forwarding and saving
    :param message_thread_id: Unique identifier for the target message thread (topic) of the forum; for forum supergroups only
    :return:
    ZsendInvoiceN)r   r   r  r|   provider_tokencurrencypricesstart_parameter	photo_url
photo_sizephoto_widthphoto_height	need_nameneed_phone_number
need_emailneed_shipping_addresssend_phone_number_to_providersend_email_to_provideris_flexibler   r   r   provider_datar"   r   max_tip_amountsuggested_tip_amountsr   r   rf   )r5  r_   rz   r{   rE   ) r?   r   r   r  Zinvoice_payloadrK  rL  rM  rN  rO  rP  rQ  rR  rS  rT  rU  rV  rW  rX  rY  r   r   r   rZ  r"   r   r[  r\  r   r   rb   r|   r   r   r   send_invoice  sd    +



r]  c                    sD   d}||d}|r$t |I dH |d< |r0||d< t| ||dI dH S )a  
    If you sent an invoice requesting a shipping address and the parameter is_flexible was specified, the Bot API will send an Update with a shipping_query field to the bot. Use this method to reply to shipping queries. On success, True is returned.
    :param token: Bot's token (you don't need to fill this)
    :param shipping_query_id: Unique identifier for the query to be answered
    :param ok: Specify True if delivery to the specified address is possible and False if there are any problems (for example, if delivery to the specified address is not possible)
    :param shipping_options: Required if ok is True. A JSON-serialized array of available shipping options.
    :param error_message: Required if ok is False. Error message in human readable form that explains why it is impossible to complete the order (e.g. "Sorry, delivery to your desired address is unavailable'). Telegram will display this message to the user.
    :return:
    ZanswerShippingQuery)shipping_query_idr   Nshipping_optionserror_messagerf   )r5  rE   )r?   r^  r   r_  r`  rb   r|   r   r   r   answer_shipping_query  s    

ra  c                    s.   d}||d}|r||d< t | ||dI dH S )a   
    Once the user has confirmed their payment and shipping details, the Bot API sends the final confirmation in the form of an Update with the field pre_checkout_query. Use this method to respond to such pre-checkout queries. On success, True is returned. Note: The Bot API must receive an answer within 10 seconds after the pre-checkout query was sent.
    :param token: Bot's token (you don't need to fill this)
    :param pre_checkout_query_id: Unique identifier for the query to be answered
    :param ok: Specify True if everything is alright (goods are available, etc.) and the bot is ready to proceed with the order. Use False if there are any problems.
    :param error_message: Required if ok is False. Error message in human readable form that explains the reason for failure to proceed with the checkout (e.g. "Sorry, somebody just bought the last of our amazing black T-shirts while you were busy filling out your payment details. Please choose a different color or garment!"). Telegram will display this message to the user.
    :return:
    ZanswerPreCheckoutQuery)pre_checkout_query_idr   r`  rf   Nr`   )r?   rb  r   r`  rb   r|   r   r   r   answer_pre_checkout_query!  s
    	
rc  c                    s"   d}d|i}t | ||ddI d H S )NZ!unpinAllGeneralForumTopicMessagesr   r   r   r`   r   r   r   r   &unpin_all_general_forum_topic_messages1  s    rd  c                    sZ   d}d|i}|r||d< |dur(||d< |r4||d< |durD||d< t | ||dd	I dH S )
u  
    Use this method to send answers to callback queries sent from inline keyboards. The answer will be displayed to the user as a notification at the top of the chat screen or as an alert. On success, True is returned.
    Alternatively, the user can be redirected to the specified Game URL. For this option to work, you must first create a game for your bot via BotFather and accept the terms. Otherwise, you may use links like telegram.me/your_bot?start=XXXX that open your bot with a parameter.
    :param token: Bot's token (you don't need to fill this)
    :param callback_query_id: Unique identifier for the query to be answered
    :param text: (Optional) Text of the notification. If not specified, nothing will be shown to the user, 0-200 characters
    :param show_alert: (Optional) If true, an alert will be shown by the client instead of a notification at the top of the chat screen. Defaults to false.
    :param url: (Optional) URL that will be opened by the user's client. If you have created a Game and accepted the conditions via @Botfather, specify the URL that opens your game – note that this will only work if the query comes from a callback_game button.
    Otherwise, you may use links like telegram.me/your_bot?start=XXXX that open your bot with a parameter.
    :param cache_time: (Optional) The maximum amount of time in seconds that the result of the callback query may be cached client-side. Telegram apps will support caching starting in version 3.14. Defaults to 0.
    :return:
    ZanswerCallbackQuerycallback_query_idr   N
show_alertr&   
cache_timer   r   r`   )r?   re  r   rf  r&   rg  rb   r|   r   r   r   answer_callback_query8  s    rh  c           	         sr   d}|t |I d H d}|d ur(||d< |d ur8||d< |d urH||d< |d ur\| |d< t| ||ddI d H S )	NZanswerInlineQuery)inline_query_idresultsrg  is_personalnext_offsetbuttonr   r   r4  )	r?   ri  rj  rg  rk  rl  rm  rb   r|   r   r   r   answer_inline_queryR  s    rn  c                    s   d}t | |d|idI d H S )NZgetStickerSetrF   rf   r`   )r?   rF   rb   r   r   r   get_sticker_setc  s    ro  c                    s"   d}t | |dt|idI d H S )NZgetCustomEmojiStickerscustom_emoji_idsrf   )rE   rz   r{   )r?   rp  rb   r   r   r   get_custom_emoji_stickersg  s    rq  c                    s4   d}d|i}|rt ||d< t| ||ddI d H S )NZsetStickerKeywordsr   keywordsr   r   ry   )r?   r   rr  rb   r|   r   r   r   set_sticker_keywordsk  s
    rs  c                    s2   d}d|i}|r|  |d< t| ||ddI d H S )NZsetStickerMaskPositionr   mask_positionr   r   r   )r?   r   rt  rb   r|   r   r   r   set_sticker_mask_positions  s
    ru  c                    s.   d}||d}d|i}t | |||ddI d H S )NZuploadStickerFile)r   sticker_formatr   r   r   r`   )r?   r   r   rv  rb   r|   rA   r   r   r   upload_sticker_filez  s    
rw  c                    s*   d}|t |d}t| ||ddI d H S )NZsetStickerEmojiList)r   
emoji_listr   r   ry   )r?   r   rx  rb   r|   r   r   r   set_sticker_emoji_list  s    ry  c                    s"   d}d|i}t | ||ddI d H S )NZdeleteStickerSetrF   r   r   r`   )r?   rF   rb   r|   r   r   r   delete_sticker_set  s    rz  c                    s2   d}d|i}|d ur||d< t | ||ddI d H S )NZ!setCustomEmojiStickerSetThumbnailrF   custom_emoji_idr   r   r`   )r?   rF   r{  rb   r|   r   r   r   &set_custom_emoji_sticker_set_thumbnail  s
    r|  c                    s$   d}||d}t | ||ddI d H S )NZsetStickerSetTitle)rF   r   r   r   r`   )r?   rF   r   rb   r|   r   r   r   set_sticker_set_title  s    
r}  c                    s   d}||||d}	|r||	d< |r*||	d< i }
g }|D ]F}|  \}}| }|rrt| }||d  |
|d < || q6t||	d< t| ||	|
ddI d H S )	NZcreateNewStickerSet)r   rF   r   rv  sticker_typeneeds_repaintingr   stickersr   r   )convert_input_stickerto_dictlistkeysappendrz   r{   rE   )r?   r   rF   r   r  rv  r~  r  rb   r|   rA   lstr   	json_dictrY   Z	list_keysr   r   r   create_new_sticker_set  s"    r  c                    s4   d}|  \}}|||d}t| |||ddI d H S )NZaddStickerToSet)r   rF   r   r   r   )r  rE   )r?   r   rF   r   rb   r  rA   r|   r   r   r   add_sticker_to_set  s    r  c                    s$   d}||d}t | ||ddI d H S )NZsetStickerPositionInSet)r   positionr   r   r`   )r?   r   r  rb   r|   r   r   r   set_sticker_position_in_set  s    
r  c                    s"   d}d|i}t | ||ddI d H S )NZdeleteStickerFromSetr   r   r   r`   )r?   r   rb   r|   r   r   r   delete_sticker_from_set  s    r  c                    s   d}|||||t |I d H d}|r,||d< |r>t||d< |	rJ|	|d< |
rV|
|d< |rb||d< |rn||d< |rz||d	< |d ur||d
< |d ur||d< |d ur||d< |d ur||d< |d ur||d< |d ur||d< |d ur||d< t| ||ddI d H S )NZcreateInvoiceLink)r   r  r|   rK  rL  rM  r[  r\  rZ  rO  rP  rQ  rR  rS  rT  rU  rV  rW  rX  rY  r   r   )r5  rz   r{   rE   )r?   r   r  r|   rK  rL  rM  r[  r\  rZ  rO  rP  rQ  rR  rS  rT  rU  rV  rW  rX  rY  rb   r   r   r   create_invoice_link  sB    r  Fc                    sn  d}t ||tt|I d H d}|d ur4||d< |d urD||d< |d urT||d< |d urd||d< |d urt||d< |	d ur|	|d< |
d ur|
|d	< |d urt|tr| |d
< n||d
< |d ur||d< |r||d< |d ur||d< |d ur||d< |d urt|I d H |d< |r"||d< |r>ttj	
||d< |rL||d< |rZ||d< t| ||dI d H S )NZsendPoll)r   questionoptionsr  typeallows_multiple_answerscorrect_option_idexplanationexplanation_parse_modeopen_period
close_date	is_closedr   r   r   r   r"   explanation_entitiesr   r   rf   )rL   rz   r{   _convert_poll_optionsrK   r   r   r_   r   r   r   rE   )r?   r   r  r  r  r  r  r  r  r  r  r  r  r   r   r   r   r"   r  r   r   rb   r|   r   r   r   	send_poll  sX    


r  c                    s:   d}||d}|r||d< |r&||d< t | ||dI d H S )NZcreateForumTopicr   rF   
icon_coloricon_custom_emoji_idrf   r`   )r?   r   rF   r  r  rb   r|   r   r   r   create_forum_topic(  s    
r  c                    sB   d}||d}|d ur||d< |d ur.||d< t | ||dI d H S )NZeditForumTopicr   r   rF   r  rf   r`   )r?   r   r   rF   r  rb   r|   r   r   r   edit_forum_topic1  s    
r  c                    s"   d}||d}t | ||dI d H S )NZcloseForumTopicr  rf   r`   r?   r   r   rb   r|   r   r   r   close_forum_topic:  s    
r  c                    s"   d}||d}t | ||dI d H S )NZreopenForumTopicr  rf   r`   r  r   r   r   reopen_forum_topic?  s    
r  c                    s"   d}||d}t | ||dI d H S )NZdeleteForumTopicr  rf   r`   r  r   r   r   delete_forum_topicD  s    
r  c                    s"   d}||d}t | ||dI d H S )NZunpinAllForumTopicMessagesr  rf   r`   r  r   r   r   unpin_all_forum_topic_messagesI  s    
r  c                    s   d}t | |I d H S )NZgetForumTopicIconStickersr`   ra   r   r   r   get_forum_topic_icon_stickersN  s    r  c                    s"   d}||d}t | ||dI d H S )NZeditGeneralForumTopicr  rf   r`   )r?   r   rF   rb   r|   r   r   r   edit_general_forum_topicR  s    
r  c                    s    d}d|i}t | ||dI d H S )NZcloseGeneralForumTopicr   rf   r`   r   r   r   r   close_general_forum_topicW  s    r  c                    s    d}d|i}t | ||dI d H S )NZreopenGeneralForumTopicr   rf   r`   r   r   r   r   reopen_general_forum_topic\  s    r  c                    s    d}d|i}t | ||dI d H S )NZhideGeneralForumTopicr   rf   r`   r   r   r   r   hide_general_forum_topica  s    r  c                    s    d}d|i}t | ||dI d H S )NZunhideGeneralForumTopicr   rf   r`   r   r   r   r   unhide_general_forum_topicf  s    r  c                    sN   d}| D ] }t |tjr||  d }qt|dkrB|d d }d| d S )Nrq   ,r   rH   [])rK   r   r]   r^   rV   )rj  retrr   r   r   r5  k  s    r5  c                    sB   | d u rd S t | dkrg S t| d tjr:dd | D S | S d S )Nr   c                 S   s   g | ]}|  qS r   )r^   ).0entityr   r   r   
<listcomp>|      z$_convert_entites.<locals>.<listcomp>)rV   rK   r   r]   )Zentitesr   r   r   r   v  s    r   c                    sT   | d u rd S t | dkrg S t| d tr.| S t| d tjrLdd | D S | S d S )Nr   c                 S   s   g | ]
}|j qS r   )r   )r  optionr   r   r   r    r  z)_convert_poll_options.<locals>.<listcomp>)rV   rK   rL   r   Z
PollOption)Zpoll_optionsr   r   r   r    s    r  c                    s   t | tjr|  S dS )N)NN)rK   r   
InputMediar@  )r   r   r   r   r@    s    r@  c                    sf   g }i }| D ]J}t |tjr| }|d drL|d dd}|j||< || qt	||fS )Nr   z	attach://rq   )
rK   r   r  r  
startswithr5   r   r  rz   r{   )arrayr   rA   Zinput_mediaZ
media_dictrZ   r   r   r   r     s    
r   c                    s    fdd}|S )Nc                    s"   | dkrd | |S  | |S d S )NrS   z{0}={1})r2   )rZ   valfuncr   r   wrapper  s    z_no_encode.<locals>.wrapperr   )r  r  r   r  r   
_no_encode  s    r  c                    s<   d}t ||d}|r(t|I d H |d< t| ||dI d H S )NZstopPollr9  r   rf   )rL   r_   rE   )r?   r   r   r   rb   r|   r   r   r   	stop_poll  s
    r  c                       s    e Zd ZdZ fddZ  ZS )ApiExceptionaK  
    This class represents a base Exception thrown when a call to the Telegram API fails.
    In addition to an informative message, it has a `function_name` and a `result` attribute, which respectively
    contain the name of the failed function and the returned result that made the function to be considered  as
    failed.
    c                    s&   t t| d| || _|| _d S )Nz3A request to the Telegram API was unsuccessful. {0})superr  r   r2   function_namer*   )r   msgr  r*   r<   r   r   r     s    zApiException.__init__r   r   r   __doc__r   __classcell__r   r   r  r   r    s   r  c                       s(   e Zd ZdZejd fddZ  ZS )r:   z
    This class represents an Exception thrown when a call to the 
    Telegram API server returns HTTP code that is not 200.
    r   c                    s(   t t| d|j|j|j|| d S )Nz6The server returned HTTP {0} {1}. Response body:
[{2}])r  r:   r   r2   rm   reasonZrequest_infor   r  r*   r  r   r   r     s    
zApiHTTPException.__init__)r   r   r   r  r   ClientResponser   r  r   r   r  r   r:     s   r:   c                       s    e Zd ZdZ fddZ  ZS )r9   zu
    This class represents an Exception thrown when a call to the 
    Telegram API server returns invalid json.
    c                    s   t t| d||| d S )NzBThe server returned an invalid JSON response. Response body:
[{0}])r  r9   r   r2   r  r  r   r   r     s    
z ApiInvalidJSONException.__init__r  r   r   r  r   r9     s   r9   c                       s    e Zd ZdZ fddZ  ZS )r8   z[
    This class represents an Exception thrown when a Telegram API returns error code.
    c                    sB   t t| d|d |d || || _|d | _|d | _d S )Nz!Error code: {0}. Description: {1}
error_coder  )r  r8   r   r2   r   r  r  )r   r  r*   r   r  r   r   r     s    

zApiTelegramException.__init__r  r   r   r  r   r8     s   r8   c                   @   s   e Zd ZdZdS )r>   z2
    This class represents a request timeout.
    N)r   r   r   r  r   r   r   r   r>     s   r>   )r    NN)NN)NNNNNNNN)NN)N)NNNNN)
NNNNNNNNNN)NN)NNNN)
NNNNNNNNNN)NNNNNNNN)NNNNNNNNNNN)NNNNNN)NNNNNNNNNNN)NNNNNNNN)NNNNN)NNNNNNNNNNN)	NNNNNNNNN)NN)NNNNNNNNNNNNNNNN)NNNNNNNNNNNNNNN)NNNNNNNNNNN)
NNNNNNNNNN)NNNNNNNNNNNNNN)NNNNNNNNNNNNNN)NN)NN)NNNNNNNNNNNNNNN)N)NN)N)NN)N)NN)NN)N)NN)N)NN)N)NN)NN)N)NNNNNNN)NNNNNN)NNNN)NNNN)N)NNNNNNN)NNNNN)NNN)NNNNNNNNNNNNNNNNNNNNNN)NN)N)NNNN)NNNN)N)N)N)NN)NNNNNNNNNNNNNN)NNNNNNNNNFNNNNNNN)NN)NN)N)Zasyncior   r   r   Ztelebotr   Zujsonrz   ImportErrorrM   r1   r   r   logging	getLoggerr3   r(   r
   rj   r,   r/   r   r   r.   rE   rQ   r-   r_   rc   rd   r   rg   rk   rp   r}   r~   r   r   r  r7   r   r   r   r   r   r   r   r   r   ZInlineQueryResultBaser   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r
  r  r  r  r  r  r  r  r  r  r  r  r  r!  r#  r%  r&  r)  r*  r+  r-  r.  r1  r2  r6  r7  r8  r:  r;  r<  r>  r?  rA  rB  rC  rE  rI  rJ  r]  ra  rc  rd  rh  rn  ro  rq  rs  ru  rw  ry  rz  r|  r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r5  r   r  r@  r   r  r  r=   r  r:   r9   r8   r>   r   r   r   r   <module>   s  
. 

	 
   
!
 
  
  
   
* 
   
"  
 
   
"  

   
5   
3  
#  
)  
/   
1	 
    
)					
	
	


 
 
 
 
     
^ 

	   
,   
7		
	