U
    g}                     @   s   d Z ddlmZmZmZmZ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 dd	lmZmZmZ erdd
lmZmZmZmZmZmZmZm Z  G dd deZ!dS )zGThis module contains an object that represents a Telegram CallbackQuery    )TYPE_CHECKINGFinalOptionalSequenceTupleUnion)	constants)Location)MaybeInaccessibleMessageMessage)TelegramObject)User)DEFAULT_NONE)JSONDictODVInputReplyMarkup)BotGameHighScoreInlineKeyboardMarkup
InputMediaLinkPreviewOptionsMessageEntity	MessageIdReplyParametersc                       s  e Zd ZU dZdZdAddeeeee ee ee ee ee	 d fddZ
edBee	 ed ed  d	 fd
dZdCeeeeddee ee ee ee ee ee ee ee ee	 ed
ddZdDeedddZeddefdeeeeddeee ed eed  ed ee ee ee ee ee ee	 eeef dddZddeddfeeeeddee ed ee eed  ee ee ee ee ee ee	 eeef dddZdEeeeedded ee ee ee ee ee	 eeef ddd ZdFeeeeddd!ed ee ee ee ee ee	 eeef d"d#d$ZdGdeeeedd%ee ee ed ee ee ee ee ee ee ee ee ee ee	 eeef d&d'd(ZdHeeeedded ee ee ee ee ee	 eeef dd)d*ZdIeeeeddeeee ee ee ee ee ee ee	 eeef d+
d,d-Zeeeeddeee ee ee ee ee	 ed. d/d0d1Z eeeeddee ee ee ee ee	 ed2d3d4Z!efeeeeddee ee ee ee ee ee	 ed5d6d7Z"eeeeddee ee ee ee ee	 ed2d8d9Z#dedededddf	edeeeedd:eeef ee ee eed  ee ee$ ee ee ed; ee ee ee ee ee ee ee ee	 d<d=d>d?Z%e&j'j(Z)e*e e+d@<   Z,S )JCallbackQuerya(  
    This object represents an incoming callback query from a callback button in an inline keyboard.

    If the button that originated the query was attached to a message sent by the bot, the field
    :attr:`message` will be present. If the button was attached to a message sent via the bot (in
    inline mode), the field :attr:`inline_message_id` will be present.

    Objects of this class are comparable in terms of equality. Two objects of this class are
    considered equal, if their :attr:`id` is equal.

    Note:
        * In Python :keyword:`from` is a reserved word. Use :paramref:`from_user` instead.
        * Exactly one of the fields :attr:`data` or :attr:`game_short_name` will be present.
        * After the user presses an inline button, Telegram clients will display a progress bar
          until you call :attr:`answer`. It is, therefore, necessary to react
          by calling :attr:`telegram.Bot.answer_callback_query` even if no notification to the user
          is needed (e.g., without specifying any of the optional parameters).
        * If you're using :attr:`telegram.ext.ExtBot.callback_data_cache`, :attr:`data` may be
          an instance
          of :class:`telegram.ext.InvalidCallbackData`. This will be the case, if the data
          associated with the button triggering the :class:`telegram.CallbackQuery` was already
          deleted or if :attr:`data` was manipulated by a malicious client.

          .. versionadded:: 13.6

    Args:
        id (:obj:`str`): Unique identifier for this query.
        from_user (:class:`telegram.User`): Sender.
        chat_instance (:obj:`str`): Global identifier, uniquely corresponding to the chat to which
            the message with the callback button was sent. Useful for high scores in games.
        message (:class:`telegram.MaybeInaccessibleMessage`, optional): Message sent by the bot
            with the callback button that originated the query.

            .. versionchanged:: 20.8
               Accept objects of type :class:`telegram.MaybeInaccessibleMessage` since Bot API 7.0.
        data (:obj:`str`, optional): Data associated with the callback button. Be aware that the
            message, which originated the query, can contain no callback buttons with this data.
        inline_message_id (:obj:`str`, optional): Identifier of the message sent via the bot in
            inline mode, that originated the query.
        game_short_name (:obj:`str`, optional): Short name of a Game to be returned, serves as
            the unique identifier for the game.

    Attributes:
        id (:obj:`str`): Unique identifier for this query.
        from_user (:class:`telegram.User`): Sender.
        chat_instance (:obj:`str`): Global identifier, uniquely corresponding to the chat to which
            the message with the callback button was sent. Useful for high scores in games.
        message (:class:`telegram.MaybeInaccessibleMessage`): Optional. Message sent by the bot
            with the callback button that originated the query.

            .. versionchanged:: 20.8
               Objects may be of type :class:`telegram.MaybeInaccessibleMessage` since Bot API
               7.0.
        data (:obj:`str` | :obj:`object`): Optional. Data associated with the callback button.
            Be aware that the message, which originated the query, can contain no callback buttons
            with this data.

            Tip:
                The value here is the same as the value passed in
                :paramref:`telegram.InlineKeyboardButton.callback_data`.
        inline_message_id (:obj:`str`): Optional. Identifier of the message sent via the bot in
            inline mode, that originated the query.
        game_short_name (:obj:`str`): Optional. Short name of a Game to be returned, serves as
            the unique identifier for the game.


    )chat_instancedata	from_usergame_short_nameidinline_message_idmessageN
api_kwargs)r   r   r   r!   r   r    r   r#   c          	         sN   t  j|d || _|| _|| _|| _|| _|| _|| _| jf| _	| 
  d S )Nr"   )super__init__r   r   r   r!   r   r    r   Z	_id_attrsZ_freeze)	selfr   r   r   r!   r   r    r   r#   	__class__ ;/tmp/pip-unpacked-wheel-swnnwir2/telegram/_callbackquery.pyr%   {   s    
zCallbackQuery.__init__r   )r   botreturnc                    sP   |  |}|sdS t|dd||d< t|d||d< t j||dS )z,See :meth:`telegram.TelegramObject.de_json`.Nfromr   r!   )r   r+   )Z_parse_datar   de_jsonpopr   getr$   )clsr   r+   r'   r)   r*   r.      s    
zCallbackQuery.de_jsonread_timeoutwrite_timeoutconnect_timeoutpool_timeoutr#   )
text
show_alerturl
cache_timer3   r4   r5   r6   r#   r,   c          
         s*   |   j| j|||||||||	d
I dH S )a1  Shortcut for::

             await bot.answer_callback_query(update.callback_query.id, *args, **kwargs)

        For the documentation of the arguments, please see
        :meth:`telegram.Bot.answer_callback_query`.

        Returns:
            :obj:`bool`: On success, :obj:`True` is returned.

        )
Zcallback_query_idr7   r8   r9   r:   r3   r4   r5   r6   r#   N)get_botZanswer_callback_queryr   )
r&   r7   r8   r9   r:   r3   r4   r5   r6   r#   r)   r)   r*   answer   s    zCallbackQuery.answeredit)actionr,   c                 C   s"   t | jtstd| d| jS )zHelper method to get the message for the shortcut methods. Must be called only
        if :attr:`inline_message_id` is *not* set.
        zCannot z an inaccessible message)
isinstancer!   r   	TypeError)r&   r>   r)   r)   r*   _get_message   s    zCallbackQuery._get_message)disable_web_page_previewr3   r4   r5   r6   r#   r   r   r   )r7   
parse_modereply_markupentitieslink_preview_optionsrB   r3   r4   r5   r6   r#   r,   c                   sd   | j r:|  j| j ||||||||	|
||ddddI dH S |  j||||||||	|
||dI dH S )a  Shortcut for either::

            await update.callback_query.message.edit_text(*args, **kwargs)

        or::

            await bot.edit_message_text(
                inline_message_id=update.callback_query.inline_message_id, *args, **kwargs,
            )

        For the documentation of the arguments, please see
        :meth:`telegram.Bot.edit_message_text` and :meth:`telegram.Message.edit_text`.

        .. versionchanged:: 20.8
           Raises :exc:`TypeError` if :attr:`message` is not accessible.

        Returns:
            :class:`telegram.Message`: On success, if edited message is sent by the bot, the
            edited Message is returned, otherwise :obj:`True` is returned.

        Raises:
            :exc:`TypeError` if :attr:`message` is not accessible.

        N)r    r7   rC   rB   rF   rD   r3   r4   r5   r6   r#   rE   chat_id
message_idbusiness_connection_id)r7   rC   rB   rF   rD   r3   r4   r5   r6   r#   rE   )r    r;   edit_message_textrA   Z	edit_text)r&   r7   rC   rD   rE   rF   rB   r3   r4   r5   r6   r#   r)   r)   r*   rJ      s>    'zCallbackQuery.edit_message_text)captionrD   rC   caption_entitiesshow_caption_above_mediar3   r4   r5   r6   r#   r,   c                   s`   | j r8|  j|| j |||||	||
|dd|ddI dH S |  j||||||	||
||d
I dH S )a%  Shortcut for either::

            await update.callback_query.message.edit_caption(*args, **kwargs)

        or::

            await bot.edit_message_caption(
                inline_message_id=update.callback_query.inline_message_id, *args, **kwargs,
            )

        For the documentation of the arguments, please see
        :meth:`telegram.Bot.edit_message_caption` and :meth:`telegram.Message.edit_caption`.

        .. versionchanged:: 20.8
           Raises :exc:`TypeError` if :attr:`message` is not accessible.

        Returns:
            :class:`telegram.Message`: On success, if edited message is sent by the bot, the
            edited Message is returned, otherwise :obj:`True` is returned.

        Raises:
            :exc:`TypeError` if :attr:`message` is not accessible.

        N)rK   r    rD   r3   r4   r5   r6   rC   r#   rL   rG   rH   rM   rI   )
rK   rD   r3   r4   r5   r6   rC   r#   rL   rM   )r    r;   edit_message_captionrA   Zedit_caption)r&   rK   rD   rC   rL   rM   r3   r4   r5   r6   r#   r)   r)   r*   rN     s:    &z"CallbackQuery.edit_message_caption)rD   r3   r4   r5   r6   r#   r,   c                   sP   | j r0|  j|| j |||||dddd
I dH S |  j||||||dI dH S )a@  Shortcut for either::

            await update.callback_query.message.edit_reply_markup(*args, **kwargs)

        or::

            await bot.edit_message_reply_markup(
                inline_message_id=update.callback_query.inline_message_id, *args, **kwargs
            )

        For the documentation of the arguments, please see
        :meth:`telegram.Bot.edit_message_reply_markup` and
        :meth:`telegram.Message.edit_reply_markup`.

        .. versionchanged:: 20.8
           Raises :exc:`TypeError` if :attr:`message` is not accessible.

        Returns:
            :class:`telegram.Message`: On success, if edited message is sent by the bot, the
            edited Message is returned, otherwise :obj:`True` is returned.

        Raises:
            :exc:`TypeError` if :attr:`message` is not accessible.

        N)
rD   r    r3   r4   r5   r6   r#   rG   rH   rI   rD   r3   r4   r5   r6   r#   )r    r;   edit_message_reply_markuprA   Zedit_reply_markupr&   rD   r3   r4   r5   r6   r#   r)   r)   r*   rP   _  s*    #z'CallbackQuery.edit_message_reply_markupr   )mediarD   r3   r4   r5   r6   r#   r,   c                   sT   | j r2|  j| j |||||||ddddI dH S |  j|||||||dI dH S )a"  Shortcut for either::

            await update.callback_query.message.edit_media(*args, **kwargs)

        or::

            await bot.edit_message_media(
                inline_message_id=update.callback_query.inline_message_id, *args, **kwargs
            )

        For the documentation of the arguments, please see
        :meth:`telegram.Bot.edit_message_media` and :meth:`telegram.Message.edit_media`.

        .. versionchanged:: 20.8
           Raises :exc:`TypeError` if :attr:`message` is not accessible.

        Returns:
            :class:`telegram.Message`: On success, if edited message is not an inline message, the
            edited Message is returned, otherwise :obj:`True` is returned.

        Raises:
            :exc:`TypeError` if :attr:`message` is not accessible.

        N)r    rR   rD   r3   r4   r5   r6   r#   rG   rH   rI   )rR   rD   r3   r4   r5   r6   r#   )r    r;   edit_message_mediarA   Z
edit_media)r&   rR   rD   r3   r4   r5   r6   r#   r)   r)   r*   rS     s.    #z CallbackQuery.edit_message_media)locationr3   r4   r5   r6   r#   )latitude	longituderD   horizontal_accuracyheadingproximity_alert_radiuslive_periodrT   r3   r4   r5   r6   r#   r,   c                   sl   | j r>|  j| j |||||	|
|||||||ddddI dH S |  j|||||	|
|||||||dI dH S )aD  Shortcut for either::

            await update.callback_query.message.edit_live_location(*args, **kwargs)

        or::

            await bot.edit_message_live_location(
                inline_message_id=update.callback_query.inline_message_id, *args, **kwargs
            )

        For the documentation of the arguments, please see
        :meth:`telegram.Bot.edit_message_live_location` and
        :meth:`telegram.Message.edit_live_location`.

        .. versionchanged:: 20.8
           Raises :exc:`TypeError` if :attr:`message` is not accessible.

        Returns:
            :class:`telegram.Message`: On success, if edited message is sent by the bot, the
            edited Message is returned, otherwise :obj:`True` is returned.

        Raises:
            :exc:`TypeError` if :attr:`message` is not accessible.

        N)r    rU   rV   rT   rD   r3   r4   r5   r6   r#   rW   rX   rY   rZ   rG   rH   rI   )rU   rV   rT   rD   r3   r4   r5   r6   r#   rW   rX   rY   rZ   )r    r;   edit_message_live_locationrA   Zedit_live_location)r&   rU   rV   rD   rW   rX   rY   rZ   rT   r3   r4   r5   r6   r#   r)   r)   r*   r[     sF    *z(CallbackQuery.edit_message_live_locationc                   sP   | j r0|  j| j ||||||dddd
I dH S |  j||||||dI dH S )aD  Shortcut for either::

            await update.callback_query.message.stop_live_location(*args, **kwargs)

        or::

            await bot.stop_message_live_location(
                inline_message_id=update.callback_query.inline_message_id, *args, **kwargs
            )

        For the documentation of the arguments, please see
        :meth:`telegram.Bot.stop_message_live_location` and
        :meth:`telegram.Message.stop_live_location`.

        .. versionchanged:: 20.8
           Raises :exc:`TypeError` if :attr:`message` is not accessible.

        Returns:
            :class:`telegram.Message`: On success, if edited message is sent by the bot, the
            edited Message is returned, otherwise :obj:`True` is returned.

        Raises:
            :exc:`TypeError` if :attr:`message` is not accessible.

        N)
r    rD   r3   r4   r5   r6   r#   rG   rH   rI   rO   )r    r;   stop_message_live_locationrA   Zstop_live_locationrQ   r)   r)   r*   r\   $  s*    #z(CallbackQuery.stop_message_live_location)
user_idscoreforcedisable_edit_messager3   r4   r5   r6   r#   r,   c          
         sZ   | j r4|  j| j |||||||||	dddI dH S |  j|||||||||	d	I dH S )a  Shortcut for either::

           await update.callback_query.message.set_game_score(*args, **kwargs)

        or::

            await bot.set_game_score(
                inline_message_id=update.callback_query.inline_message_id, *args, **kwargs
            )

        For the documentation of the arguments, please see
        :meth:`telegram.Bot.set_game_score` and :meth:`telegram.Message.set_game_score`.

        .. versionchanged:: 20.8
           Raises :exc:`TypeError` if :attr:`message` is not accessible.

        Returns:
            :class:`telegram.Message`: On success, if edited message is sent by the bot, the
            edited Message is returned, otherwise :obj:`True` is returned.

        Raises:
            :exc:`TypeError` if :attr:`message` is not accessible.

        N)r    r]   r^   r_   r`   r3   r4   r5   r6   r#   rG   rH   )	r]   r^   r_   r`   r3   r4   r5   r6   r#   )r    r;   set_game_scorerA   )
r&   r]   r^   r_   r`   r3   r4   r5   r6   r#   r)   r)   r*   ra   ^  s4    %zCallbackQuery.set_game_score)r   .)r]   r3   r4   r5   r6   r#   r,   c                   sN   | j r.|  j| j ||||||ddd	I dH S |  j||||||dI dH S )a  Shortcut for either::

            await update.callback_query.message.get_game_high_score(*args, **kwargs)

        or::

            await bot.get_game_high_scores(
                inline_message_id=update.callback_query.inline_message_id, *args, **kwargs
            )

        For the documentation of the arguments, please see
        :meth:`telegram.Bot.get_game_high_scores` and
        :meth:`telegram.Message.get_game_high_scores`.

        .. versionchanged:: 20.8
           Raises :exc:`TypeError` if :attr:`message` is not accessible.

        Returns:
            Tuple[:class:`telegram.GameHighScore`]

        Raises:
            :exc:`TypeError` if :attr:`message` is not accessible.

        N)	r    r]   r3   r4   r5   r6   r#   rG   rH   )r]   r3   r4   r5   r6   r#   )r    r;   get_game_high_scoresrA   )r&   r]   r3   r4   r5   r6   r#   r)   r)   r*   rb     s(    "z"CallbackQuery.get_game_high_scores)r3   r4   r5   r6   r#   r,   c                   s"   | j ddj|||||dI dH S )a  Shortcut for::

            await update.callback_query.message.delete(*args, **kwargs)

        For the documentation of the arguments, please see :meth:`telegram.Message.delete`.

        .. versionchanged:: 20.8
           Raises :exc:`TypeError` if :attr:`message` is not accessible.

        Returns:
            :obj:`bool`: On success, :obj:`True` is returned.

        Raises:
            :exc:`TypeError` if :attr:`message` is not accessible.

        deleter>   r2   N)rA   rc   r&   r3   r4   r5   r6   r#   r)   r)   r*   delete_message  s    zCallbackQuery.delete_message)disable_notificationr3   r4   r5   r6   r#   r,   c                   s$   | j ddj||||||dI dH S )a  Shortcut for::

            await update.callback_query.message.pin(*args, **kwargs)

        For the documentation of the arguments, please see :meth:`telegram.Message.pin`.

        .. versionchanged:: 20.8
           Raises :exc:`TypeError` if :attr:`message` is not accessible.

        Returns:
            :obj:`bool`: On success, :obj:`True` is returned.

        Raises:
            :exc:`TypeError` if :attr:`message` is not accessible.
        pinrd   )rg   r3   r4   r5   r6   r#   N)rA   rh   )r&   rg   r3   r4   r5   r6   r#   r)   r)   r*   pin_message  s    zCallbackQuery.pin_messagec                   s"   | j ddj|||||dI dH S )a  Shortcut for::

            await update.callback_query.message.unpin(*args, **kwargs)

        For the documentation of the arguments, please see :meth:`telegram.Message.unpin`.

        .. versionchanged:: 20.8
           Raises :exc:`TypeError` if :attr:`message` is not accessible.

        Returns:
            :obj:`bool`: On success, :obj:`True` is returned.

        Raises:
            :exc:`TypeError` if :attr:`message` is not accessible.
        unpinrd   r2   N)rA   rj   re   r)   r)   r*   unpin_message  s    zCallbackQuery.unpin_message)allow_sending_without_replyreply_to_message_idr3   r4   r5   r6   r#   r   r   )rG   rK   rC   rL   rg   rD   protect_contentmessage_thread_idreply_parametersrM   rl   rm   r3   r4   r5   r6   r#   r,   c                   s:   | j ddj||||||||||||||||	|
dI dH S )a  Shortcut for::

            await update.callback_query.message.copy(
                from_chat_id=update.message.chat_id,
                message_id=update.message.message_id,
                *args,
                **kwargs
            )

        For the documentation of the arguments, please see :meth:`telegram.Message.copy`.

        .. versionchanged:: 20.8
           Raises :exc:`TypeError` if :attr:`message` is not accessible.

        Returns:
            :class:`telegram.MessageId`: On success, returns the MessageId of the sent message.

        Raises:
            :exc:`TypeError` if :attr:`message` is not accessible.
        copyrd   )rG   rK   rC   rL   rg   rm   rl   rD   r3   r4   r5   r6   r#   rn   ro   rp   rM   N)rA   rq   )r&   rG   rK   rC   rL   rg   rD   rn   ro   rp   rM   rl   rm   r3   r4   r5   r6   r#   r)   r)   r*   copy_message8  s&    )zCallbackQuery.copy_messageMAX_ANSWER_TEXT_LENGTH)NNNN)N)NNNN)r=   )N)N)NNNNNNN)N)NN)-__name__
__module____qualname____doc__	__slots__strr   r   r
   r   r%   classmethodr.   r   boolintr   floatr<   r   rA   r   r   rJ   rN   rP   rS   r	   r[   r\   ra   r   rb   rf   ri   rk   r   rr   r   ZCallbackQueryLimitZ!ANSWER_CALLBACK_QUERY_TEXT_LENGTHrs   r   __annotations____classcell__r)   r)   r'   r*   r   ,   sH  
D    
      %

J

G 
= 
>       

Q 
>  
D:#%#

>r   N)"rw   typingr   r   r   r   r   r   Ztelegramr   Ztelegram._files.locationr	   Ztelegram._messager
   r   Ztelegram._telegramobjectr   Ztelegram._userr   Ztelegram._utils.defaultvaluer   Ztelegram._utils.typesr   r   r   r   r   r   r   r   r   r   r   r   r)   r)   r)   r*   <module>   s    (