U
    ddK                     @   s   d Z ddlmZmZmZmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ ddlmZ ddlmZ dd	l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 erddlmZm Z m!Z! G dd deZ"dS )zAThis module contains an object that represents a Telegram Update.    )TYPE_CHECKINGClassVarListOptional)	constants)CallbackQuery)ChatJoinRequest)ChatMemberUpdated)ChosenInlineResult)InlineQuery)Message)PreCheckoutQuery)ShippingQuery)Poll
PollAnswer)TelegramObject)JSONDict)BotChatUserc                       s  e Zd ZU dZdZejjZee	 e
d< ejjZee	 e
d< ejjZee	 e
d< ejjZee	 e
d< ejjZee	 e
d< ejjZee	 e
d< ejjZee	 e
d	< ejjZee	 e
d
< ejjZee	 e
d< ejjZee	 e
d< ejjZee	 e
d< ejjZee	 e
d< ejjZee	 e
d< ejjZeejZeee	  e
d< d#ddeeeeeeeee e!e"e#e$e$e%e&d fddZ'e(e)d dddZ*e(e)d dddZ+e(e)e dddZ,e-e)e& de)d  d  fd!d"Z.  Z/S )$Updatea  This object represents an incoming update.

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

    Note:
        At most one of the optional parameters can be present in any given update.

    .. seealso:: :wiki:`Your First Bot <Extensions---Your-first-Bot>`

    Args:
        update_id (:obj:`int`): The update's unique identifier. Update identifiers start from a
            certain positive number and increase sequentially. This ID becomes especially handy if
            you're using Webhooks, since it allows you to ignore repeated updates or to restore the
            correct update sequence, should they get out of order. If there are no new updates for
            at least a week, then identifier of the next update will be chosen randomly instead of
            sequentially.
        message (:class:`telegram.Message`, optional): New incoming message of any kind - text,
            photo, sticker, etc.
        edited_message (:class:`telegram.Message`, optional): New version of a message that is
            known to the bot and was edited.
        channel_post (:class:`telegram.Message`, optional): New incoming channel post of any kind
            - text, photo, sticker, etc.
        edited_channel_post (:class:`telegram.Message`, optional): New version of a channel post
            that is known to the bot and was edited.
        inline_query (:class:`telegram.InlineQuery`, optional): New incoming inline query.
        chosen_inline_result (:class:`telegram.ChosenInlineResult`, optional): The result of an
            inline query that was chosen by a user and sent to their chat partner.
        callback_query (:class:`telegram.CallbackQuery`, optional): New incoming callback query.
        shipping_query (:class:`telegram.ShippingQuery`, optional): New incoming shipping query.
            Only for invoices with flexible price.
        pre_checkout_query (:class:`telegram.PreCheckoutQuery`, optional): New incoming
            pre-checkout query. Contains full information about checkout.
        poll (:class:`telegram.Poll`, optional): New poll state. Bots receive only updates about
            stopped polls and polls, which are sent by the bot.
        poll_answer (:class:`telegram.PollAnswer`, optional): A user changed their answer
            in a non-anonymous poll. Bots receive new votes only in polls that were sent
            by the bot itself.
        my_chat_member (:class:`telegram.ChatMemberUpdated`, optional): The bot's chat member
            status was updated in a chat. For private chats, this update is received only when the
            bot is blocked or unblocked by the user.

            .. versionadded:: 13.4
        chat_member (:class:`telegram.ChatMemberUpdated`, optional): A chat member's status was
            updated in a chat. The bot must be an administrator in the chat and must explicitly
            specify :attr:`CHAT_MEMBER` in the list of
            :paramref:`telegram.ext.Application.run_polling.allowed_updates` to receive these
            updates (see :meth:`telegram.Bot.get_updates`, :meth:`telegram.Bot.set_webhook`,
            :meth:`telegram.ext.Application.run_polling` and
            :meth:`telegram.ext.Application.run_webhook`).

            .. versionadded:: 13.4
        chat_join_request (:class:`telegram.ChatJoinRequest`, optional): A request to join the
            chat has been sent. The bot must have the
            :attr:`telegram.ChatPermissions.can_invite_users` administrator right in the chat to
            receive these updates.

            .. versionadded:: 13.8
    Attributes:
        update_id (:obj:`int`): The update's unique identifier. Update identifiers start from a
            certain positive number and increase sequentially. This ID becomes especially handy if
            you're using Webhooks, since it allows you to ignore repeated updates or to restore the
            correct update sequence, should they get out of order. If there are no new updates for
            at least a week, then identifier of the next update will be chosen randomly instead of
            sequentially.
        message (:class:`telegram.Message`): Optional. New incoming message of any kind - text,
            photo, sticker, etc.
        edited_message (:class:`telegram.Message`): Optional. New version of a message that is
            known to the bot and was edited.
        channel_post (:class:`telegram.Message`): Optional. New incoming channel post of any kind
            - text, photo, sticker, etc.
        edited_channel_post (:class:`telegram.Message`): Optional. New version of a channel post
            that is known to the bot and was edited.
        inline_query (:class:`telegram.InlineQuery`): Optional. New incoming inline query.
        chosen_inline_result (:class:`telegram.ChosenInlineResult`): Optional. The result of an
            inline query that was chosen by a user and sent to their chat partner.
        callback_query (:class:`telegram.CallbackQuery`): Optional. New incoming callback query.

            Examples:
                :any:`Arbitrary Callback Data Bot <examples.arbitrarycallbackdatabot>`
        shipping_query (:class:`telegram.ShippingQuery`): Optional. New incoming shipping query.
            Only for invoices with flexible price.
        pre_checkout_query (:class:`telegram.PreCheckoutQuery`): Optional. New incoming
            pre-checkout query. Contains full information about checkout.
        poll (:class:`telegram.Poll`): Optional. New poll state. Bots receive only updates about
            stopped polls and polls, which are sent by the bot.
        poll_answer (:class:`telegram.PollAnswer`): Optional. A user changed their answer
            in a non-anonymous poll. Bots receive new votes only in polls that were sent
            by the bot itself.
        my_chat_member (:class:`telegram.ChatMemberUpdated`): Optional. The bot's chat member
            status was updated in a chat. For private chats, this update is received only when the
            bot is blocked or unblocked by the user.

            .. versionadded:: 13.4
        chat_member (:class:`telegram.ChatMemberUpdated`): Optional. A chat member's status was
            updated in a chat. The bot must be an administrator in the chat and must explicitly
            specify :attr:`CHAT_MEMBER` in the list of
            :paramref:`telegram.ext.Application.run_polling.allowed_updates` to receive these
            updates (see :meth:`telegram.Bot.get_updates`, :meth:`telegram.Bot.set_webhook`,
            :meth:`telegram.ext.Application.run_polling` and
            :meth:`telegram.ext.Application.run_webhook`).

            .. versionadded:: 13.4
        chat_join_request (:class:`telegram.ChatJoinRequest`): Optional. A request to join the
            chat has been sent. The bot must have the
            :attr:`telegram.ChatPermissions.can_invite_users` administrator right in the chat to
            receive these updates.

            .. versionadded:: 13.8

    )callback_querychosen_inline_resultpre_checkout_queryinline_query	update_idmessageshipping_querypollpoll_answerchannel_postedited_channel_postedited_message_effective_user_effective_chat_effective_messagemy_chat_memberchat_memberchat_join_requestMESSAGEEDITED_MESSAGECHANNEL_POSTEDITED_CHANNEL_POSTINLINE_QUERYCHOSEN_INLINE_RESULTCALLBACK_QUERYSHIPPING_QUERYPRE_CHECKOUT_QUERYPOLLPOLL_ANSWERMY_CHAT_MEMBERCHAT_MEMBER	ALL_TYPESN
api_kwargs)r   r   r"   r    r!   r   r   r   r   r   r   r   r&   r'   r(   r8   c                   s   t  j|d || _|| _|| _|| _|| _|| _|	| _|
| _	|| _
|| _|| _|| _|| _|| _|| _d | _d | _d | _| jf| _|   d S )Nr7   )super__init__r   r   r"   r   r   r   r   r   r    r!   r   r   r&   r'   r(   r#   r$   r%   Z	_id_attrsZ_freeze)selfr   r   r"   r    r!   r   r   r   r   r   r   r   r&   r'   r(   r8   	__class__ 4/tmp/pip-unpacked-wheel-e3anp165/telegram/_update.pyr:      s*    
zUpdate.__init__r   )returnc                 C   s   | j r| j S d}| jr | jj}n| jr0| jj}n| jr@| jj}n~| jrP| jj}nn| jr`| jj}n^| jrp| jj}nN| jr| jj}n>| j	r| j	j
}n.| jr| jj}n| jr| jj}n| jr| jj}|| _ |S )a  
        :class:`telegram.User`: The user that sent this update, no matter what kind of update this
        is. If no user is associated with this update, this gives :obj:`None`. This is the case
        if :attr:`channel_post`, :attr:`edited_channel_post` or :attr:`poll` is present.

        Example:
            * If :attr:`message` is present, this will give
              :attr:`telegram.Message.from_user`.
            * If :attr:`poll_answer` is present, this will give :attr:`telegram.PollAnswer.user`.

        N)r#   r   Z	from_userr"   r   r   r   r   r   r   userr&   r'   r(   )r;   rA   r>   r>   r?   effective_user  s6    









zUpdate.effective_userr   c                 C   s   | j r| j S d}| jr | jj}nx| jr0| jj}nh| jrJ| jjrJ| jjj}nN| jrZ| jj}n>| jrj| jj}n.| jrz| jj}n| jr| jj}n| j	r| j	j}|| _ |S )a0  
        :class:`telegram.Chat`: The chat that this update was sent in, no matter what kind of
        update this is.
        If no chat is associated with this update, this gives :obj:`None`.
        This is the case, if :attr:`inline_query`,
        :attr:`chosen_inline_result`, :attr:`callback_query` from inline messages,
        :attr:`shipping_query`, :attr:`pre_checkout_query`, :attr:`poll` or
        :attr:`poll_answer` is present.

        Example:
            If :attr:`message` is present, this will give :attr:`telegram.Message.chat`.

        N)
r$   r   chatr"   r   r    r!   r&   r'   r(   )r;   rC   r>   r>   r?   effective_chatP  s*    





zUpdate.effective_chatc                 C   s`   | j r| j S d}| jr| j}n8| jr,| j}n*| jr<| jj}n| jrJ| j}n| jrV| j}|| _ |S )a  
        :class:`telegram.Message`: The message included in this update, no matter what kind of
            update this is. More precisely, this will be the message contained in :attr:`message`,
            :attr:`edited_message`, :attr:`channel_post`, :attr:`edited_channel_post` or
            :attr:`callback_query` (i.e. :attr:`telegram.CallbackQuery.message`) or :obj:`None`, if
            none of those are present.

        N)r%   r   r"   r   r    r!   )r;   r   r>   r>   r?   effective_message  s    

zUpdate.effective_messager   )databotr@   c                    sV  |  |}|sdS t|d||d< t|d||d< t|d||d< t|d||d< t|d||d< t|d||d< t|d||d< t|d	||d	< t|d
||d
< t	|d||d< t
|d||d< t|d||d< t|d||d< t|d||d< t j||dS )z,See :meth:`telegram.TelegramObject.de_json`.Nr   r"   r   r   r   r   r   r    r!   r   r   r&   r'   r(   )rF   rG   )Z_parse_datar   de_jsongetr   r
   r   r   r   r   r   r	   r   r9   )clsrF   rG   r<   r>   r?   rH     s*    
 zUpdate.de_json)NNNNNNNNNNNNNN)0__name__
__module____qualname____doc__	__slots__r   Z
UpdateTyper)   r   str__annotations__r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   ZCHAT_JOIN_REQUESTlistr6   r   intr   r   r
   r   r   r   r   r   r	   r   r   r:   propertyr   rB   rD   rE   classmethodrH   __classcell__r>   r>   r<   r?   r   (   sv   
p              /5. r   N)#rN   typingr   r   r   r   Ztelegramr   Ztelegram._callbackqueryr   Ztelegram._chatjoinrequestr   Ztelegram._chatmemberupdatedr	   Ztelegram._choseninlineresultr
   Ztelegram._inline.inlinequeryr   Ztelegram._messager   Z"telegram._payment.precheckoutqueryr   Ztelegram._payment.shippingqueryr   Ztelegram._pollr   r   Ztelegram._telegramobjectr   Ztelegram._utils.typesr   r   r   r   r   r>   r>   r>   r?   <module>   s    