U
    h0                     @   s*   d dl mZ ddl mZ G dd dZdS )   )types   )utilsc                   @   s   e Zd ZdZdd Zedd Zed$ddZed%ddZed&ddZ	ed'dd
ddddZ
eddddddZeddddddZeddddddZed
ddddddZed(ddZed)ddZed d! Zed"d# ZdS )*Buttonu  
    .. note::

        This class is used to **define** reply markups, e.g. when
        sending a message or replying to events. When you access
        `Message.buttons <telethon.tl.custom.message.Message.buttons>`
        they are actually `MessageButton
        <telethon.tl.custom.messagebutton.MessageButton>`,
        so you might want to refer to that class instead.

    Helper class to allow defining ``reply_markup`` when
    sending a message with inline or keyboard buttons.

    You should make use of the defined class methods to create button
    instances instead making them yourself (i.e. don't do ``Button(...)``
    but instead use methods line `Button.inline(...) <inline>` etc.

    You can use `inline`, `switch_inline`, `url`, `auth`, `buy` and `game`
    together to create inline buttons (under the message).

    You can use `text`, `request_location`, `request_phone` and `request_poll`
    together to create a reply markup (replaces the user keyboard).
    You can also configure the aspect of the reply with these.
    The latest message with a reply markup will be the one shown to the user
    (messages contain the buttons, not the chat itself).

    You **cannot** mix the two type of buttons together,
    and it will error if you try to do so.

    The text for all buttons may be at most 142 characters.
    If more characters are given, Telegram will cut the text
    to 128 characters and add the ellipsis (…) character as
    the 129.
    c                C   s   || _ || _|| _|| _d S )N)buttonresize
single_use	selective)selfr   r   r   r	    r   =/tmp/pip-unpacked-wheel-c81u5j2r/telethon/tl/custom/button.py__init__(   s    zButton.__init__c              
   C   s*   t | tjtjtjtjtjtjtjtj	fS )zM
        Returns `True` if the button belongs to an inline keyboard.
        )

isinstancer   ZKeyboardButtonCopyKeyboardButtonBuyKeyboardButtonCallbackKeyboardButtonGameKeyboardButtonSwitchInlineKeyboardButtonUrlInputKeyboardButtonUrlAuthZKeyboardButtonWebView)r   r   r   r   
_is_inline.   s    zButton._is_inlineNc                 C   sN   |s|  d}nt|tttfs.t| d}t|dkrBtdt	| |S )a  
        Creates a new inline button with some payload data in it.

        If `data` is omitted, the given `text` will be used as `data`.
        In any case `data` should be either `bytes` or `str`.

        Note that the given `data` must be less or equal to 64 bytes.
        If more than 64 bytes are passed as data, ``ValueError`` is raised.
        If you need to store more than 64 bytes, consider saving the real
        data in a database and a reference to that data inside the button.

        When the user clicks this button, `events.CallbackQuery
        <telethon.events.callbackquery.CallbackQuery>` will trigger with the
        same data that the button contained, so that you can determine which
        button was pressed.
        zutf-8@   zToo many bytes for the data)
encoder   bytes	bytearray
memoryviewstrlen
ValueErrorr   r   )textdatar   r   r   inline>   s    zButton.inline Fc                 C   s   t | ||S )aH  
        Creates a new inline button to switch to inline query.

        If `query` is given, it will be the default text to be used
        when making the inline query.

        If ``same_peer is True`` the inline query will directly be
        set under the currently opened chat. Otherwise, the user will
        have to select a different dialog to make the query.

        When the user clicks this button, after a chat is selected, their
        input field will be filled with the username of your bot followed
        by the query text, ready to make inline queries.
        )r   r   )r   queryZ	same_peerr   r   r   switch_inlineZ   s    zButton.switch_inlinec                 C   s   t | |p| S )a  
        Creates a new inline button to open the desired URL on click.

        If no `url` is given, the `text` will be used as said URL instead.

        You cannot detect that the user clicked this button directly.

        When the user clicks this button, a confirmation box will be shown
        to the user asking whether they want to open the displayed URL unless
        the domain is trusted, and once confirmed the URL will open in their
        device.
        )r   r   )r   urlr   r   r   r$   l   s    z
Button.url)botwrite_accessfwd_textc                C   s&   t j| |p| t|pt  ||dS )a  
        Creates a new inline button to authorize the user at the given URL.

        You should set the `url` to be on the same domain as the one configured
        for the desired `bot` via `@BotFather <https://t.me/BotFather>`_ using
        the ``/setdomain`` command.

        For more information about letting the user login via Telegram to
        a certain domain, see https://core.telegram.org/widgets/login.

        If no `url` is specified, it will default to `text`.

        Args:
            bot (`hints.EntityLike`):
                The bot that requires this authorization. By default, this
                is the bot that is currently logged in (itself), although
                you may pass a different input peer.

                .. note::

                    For now, you cannot use ID or username for this argument.
                    If you want to use a different bot than the one currently
                    logged in, you must manually use `client.get_input_entity()
                    <telethon.client.users.UserMethods.get_input_entity>`.

            write_access (`bool`):
                Whether write access is required or not.
                This is `False` by default (read-only access).

            fwd_text (`str`):
                The new text to show in the button if the message is
                forwarded. By default, the button text will be the same.

        When the user clicks this button, a confirmation box will be shown
        to the user asking whether they want to login to the specified domain.
        )r   r$   r%   Zrequest_write_accessr'   )r   r   r   Zget_input_userZInputUserSelf)r   r$   r%   r&   r'   r   r   r   auth|   s    &zButton.authr   r   r	   c                C   s   | t ||||dS )aE  
        Creates a new keyboard button with the given text.

        Args:
            resize (`bool`):
                If present, the entire keyboard will be reconfigured to
                be resized and be smaller if there are not many buttons.

            single_use (`bool`):
                If present, the entire keyboard will be reconfigured to
                be usable only once before it hides itself.

            selective (`bool`):
                If present, the entire keyboard will be reconfigured to
                be "selective". The keyboard will be shown only to specific
                users. It will target users that are @mentioned in the text
                of the message or to the sender of the message you reply to.

        When the user clicks this button, a text message with the same text
        as the button will be sent, and can be handled with `events.NewMessage
        <telethon.events.newmessage.NewMessage>`. You cannot distinguish
        between a button press and the user typing and sending exactly the
        same text on their own.
        r)   )r   ZKeyboardButtonclsr   r   r   r	   r   r   r   r      s
    
  zButton.textc                C   s   | t ||||dS )a  
        Creates a new keyboard button to request the user's location on click.

        ``resize``, ``single_use`` and ``selective`` are documented in `text`.

        When the user clicks this button, a confirmation box will be shown
        to the user asking whether they want to share their location with the
        bot, and if confirmed a message with geo media will be sent.
        r)   )r   Z KeyboardButtonRequestGeoLocationr*   r   r   r   request_location   s
    
  zButton.request_locationc                C   s   | t ||||dS )a  
        Creates a new keyboard button to request the user's phone on click.

        ``resize``, ``single_use`` and ``selective`` are documented in `text`.

        When the user clicks this button, a confirmation box will be shown
        to the user asking whether they want to share their phone with the
        bot, and if confirmed a message with contact media will be sent.
        r)   )r   ZKeyboardButtonRequestPhoner*   r   r   r   request_phone   s
    
  zButton.request_phone)
force_quizr   r   r	   c                C   s   | t j||d|||dS )a  
        Creates a new keyboard button to request the user to create a poll.

        If `force_quiz` is `False`, the user will be allowed to choose whether
        they want their poll to be a quiz or not. Otherwise, the user will be
        forced to create a quiz when creating the poll.

        If a poll is a quiz, there will be only one answer that is valid, and
        the votes cannot be retracted. Otherwise, users can vote and retract
        the vote, and the pol might be multiple choice.

        ``resize``, ``single_use`` and ``selective`` are documented in `text`.

        When the user clicks this button, a screen letting the user create a
        poll will be shown, and if they do create one, the poll will be sent.
        )Zquizr)   )r   ZKeyboardButtonRequestPoll)r+   r   r.   r   r   r	   r   r   r   request_poll   s
      zButton.request_pollc                 C   s   t j| dS )z
        Clears all keyboard buttons after sending a message with this markup.
        When used, no other button should be present or it will be ignored.

       ``selective`` is as documented in `text`.

        r	   )r   ZReplyKeyboardHider0   r   r   r   clear   s    	zButton.clearc                 C   s   t j| ||dS )u  
        Forces a reply to the message with this markup. If used,
        no other button should be present or it will be ignored.

        ``single_use`` and ``selective`` are as documented in `text`.

        Args:
            placeholder (str):
                text to show the user at typing place of message.

                If the placeholder is too long, Telegram applications will
                crop the text (for example, to 64 characters and adding an
                ellipsis (…) character as the 65th).
        r   r	   placeholder)r   ZReplyKeyboardForceReplyr2   r   r   r   force_reply  s
    zButton.force_replyc                 C   s
   t | S )a  
        Creates a new inline button to buy a product.

        This can only be used when sending files of type
        :tl:`InputMediaInvoice`, and must be the first button.

        If the button is not specified, Telegram will automatically
        add the button to the message. See the
        `Payments API <https://core.telegram.org/api/payments>`__
        documentation for more information.
        )r   r   r   r   r   r   buy  s    z
Button.buyc                 C   s
   t | S )aC  
        Creates a new inline button to start playing a game.

        This should be used when sending files of type
        :tl:`InputMediaGame`, and must be the first button.

        See the
        `Games <https://core.telegram.org/api/bots/games>`__
        documentation for more information on using games.
        )r   r   r5   r   r   r   game*  s    zButton.game)N)r!   F)N)N)N)NNN)__name__
__module____qualname____doc__r   staticmethodr   r    r#   r$   r(   classmethodr   r,   r-   r/   r1   r4   r6   r7   r   r   r   r   r      sL   "
-      

r   N)r!   r   r   r   r   r   r   r   <module>   s   