U
    h                     @   sl   d dl mZmZ ddl mZ ddlmZ zddlZW n ek
rH   Y nX ddl	Z	ddl
Z
G dd dZdS )	   )types	functions   password)BotResponseTimeoutError    Nc                   @   sd   e Zd ZdZdd Zedd Zedd Zedd	 Zed
d Z	edd Z
dddddZdS )MessageButtona+  
    .. note::

        `Message.buttons <telethon.tl.custom.message.Message.buttons>`
        are instances of this type. If you want to **define** a reply
        markup for e.g. sending messages, refer to `Button
        <telethon.tl.custom.button.Button>` instead.

    Custom class that encapsulates a message button providing
    an abstraction to easily access some commonly needed features
    (such as clicking the button itself).

    Attributes:

        button (:tl:`KeyboardButton`):
            The original :tl:`KeyboardButton` object.
    c                 C   s"   || _ || _|| _|| _|| _d S )N)button_bot_chat_msg_id_client)selfclientoriginalZchatbotmsg_id r   D/tmp/pip-unpacked-wheel-c81u5j2r/telethon/tl/custom/messagebutton.py__init__   s
    zMessageButton.__init__c                 C   s   | j S )zz
        Returns the `telethon.client.telegramclient.TelegramClient`
        instance that created this instance.
        )r   r   r   r   r   r   %   s    zMessageButton.clientc                 C   s   | j jS )zThe text string of the button.)r
   textr   r   r   r   r   -   s    zMessageButton.textc                 C   s   t | jtjr| jjS dS )z:The `bytes` data for :tl:`KeyboardButtonCallback` objects.N)
isinstancer
   r   KeyboardButtonCallbackdatar   r   r   r   r   2   s    zMessageButton.datac                 C   s   t | jtjr| jjS dS )z=The query `str` for :tl:`KeyboardButtonSwitchInline` objects.N)r   r
   r   KeyboardButtonSwitchInlinequeryr   r   r   r   inline_query8   s    zMessageButton.inline_queryc                 C   s   t | jtjr| jjS dS )z2The url `str` for :tl:`KeyboardButtonUrl` objects.N)r   r
   r   KeyboardButtonUrlurlr   r   r   r   r    >   s    zMessageButton.urlNr   c          	         sT  t | jtjr,| jj| j| jjddI dH S t | jtjr|dk	rd| t	j
 I dH }t||}t	jj| j| j| jj|d}z| |I dH W S  tk
r   Y dS X nt | jtjr| t	jj| j| j| jjdI dH S t | jtjrdtjkrPt| jjS n@t | jtjrdt	jj| j| jdd}z| |I dH W S  tk
r`   Y dS X nt | jtjr|std|dkst |t r| j! I dH }tj"|dkr|j#n||j$pd	|j%pd	d	d
}| j&| j|I dH S t | jtj'rP|stdt |t(t)fr:|\}}t*tj+||d}| j&| j|I dH S dS )a  
        Emulates the behaviour of clicking this button.

        If it's a normal :tl:`KeyboardButton` with text, a message will be
        sent, and the sent `Message <telethon.tl.custom.message.Message>` returned.

        If it's an inline :tl:`KeyboardButtonCallback` with text and data,
        it will be "clicked" and the :tl:`BotCallbackAnswer` returned.

        If it's an inline :tl:`KeyboardButtonSwitchInline` button, the
        :tl:`StartBotRequest` will be invoked and the resulting updates
        returned.

        If it's a :tl:`KeyboardButtonUrl`, the URL of the button will
        be passed to ``webbrowser.open`` and return `True` on success.

        If it's a :tl:`KeyboardButtonRequestPhone`, you must indicate that you
        want to ``share_phone=True`` in order to share it. Sharing it is not a
        default because it is a privacy concern and could happen accidentally.

        You may also use ``share_phone=phone`` to share a specific number, in
        which case either `str` or :tl:`InputMediaContact` should be used.

        If it's a :tl:`KeyboardButtonRequestGeoLocation`, you must pass a
        tuple in ``share_geo=(longitude, latitude)``. Note that Telegram seems
        to have some heuristics to determine impossible locations, so changing
        this value a lot quickly may not work as expected. You may also pass a
        :tl:`InputGeoPoint` if you find the order confusing.
        N)Z
parse_mode)peerr   r   r   )r   r!   Zstart_param
webbrowserT)r!   r   Zgamez5cannot click on phone buttons unless share_phone=True )Zphone_number
first_name	last_nameZvcardzBcannot click on geo buttons unless share_geo=(longitude, latitude))latlong),r   r
   r   ZKeyboardButtonr   send_messager   r   r   r   accountZGetPasswordRequestpwd_modZcompute_checkmessagesZGetBotCallbackAnswerRequestr   r   r   r   ZStartBotRequestr   r   r   sysmodulesr"   openr    ZKeyboardButtonGameZKeyboardButtonRequestPhone
ValueErrorstrZget_meZInputMediaContactZphoner$   r%   Z	send_fileZ KeyboardButtonRequestGeoLocationtuplelistZInputMediaGeoPointZInputGeoPoint)	r   Zshare_phoneZ	share_geor   pwdreqmer'   r&   r   r   r   clickD   st        
    


zMessageButton.click)NN)__name__
__module____qualname____doc__r   propertyr   r   r   r   r    r6   r   r   r   r   r	      s   




r	   )r#   r   r   r   r*   errorsr   r"   ModuleNotFoundErrorr,   osr	   r   r   r   r   <module>   s   