U
    gx                     @   s*  d Z ddlmZmZmZmZmZ ddlmZ ddl	m
Z
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 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& ddl'm(Z( ddl)m*Z* ddl+m,Z, erddlm-Z-m.Z.m/Z/ G dd de(Z0dS )zAThis module contains an object that represents a Telegram Update.    )TYPE_CHECKINGFinalListOptionalUnion)	constants)BusinessConnectionBusinessMessagesDeleted)CallbackQuery)ChatBoostRemovedChatBoostUpdated)ChatJoinRequest)ChatMemberUpdated)ChosenInlineResult)InlineQuery)Message)MessageReactionCountUpdatedMessageReactionUpdated)PaidMediaPurchased)PreCheckoutQuery)ShippingQuery)Poll
PollAnswer)TelegramObject)JSONDict)warn)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	 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!ejZ"ee#e	  e
d< d0dde$e%e& e%e& e%e& e%e& e%e' e%e( e%e) e%e* e%e+ e%e, e%e- e%e. e%e. e%e/ e%e0 e%e1 e%e2 e%e3 e%e4 e%e& e%e& e%e5 e%e6 e%e7 d fddZ8e9e%d  d!d"d#Z:e9e%e;d$  d!d%d&Z<e9e%d' d!d(d)Z=e9e%e& d!d*d+Z>e?d1e%e7 e%d, e%d  d- fd.d/Z@  ZAS )2Updateax4  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. This update may at times be triggered by changes to
            message fields that are either unavailable or not actively used by your bot.
        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. This update may at times be triggered by
            changes to message fields that are either unavailable or not actively used by your bot.
        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
            manually 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

        chat_boost (:class:`telegram.ChatBoostUpdated`, optional): A chat boost was added or
            changed. The bot must be an administrator in the chat to receive these updates.

            .. versionadded:: 20.8

        removed_chat_boost (:class:`telegram.ChatBoostRemoved`, optional): A boost was removed from
            a chat. The bot must be an administrator in the chat to receive these updates.

            .. versionadded:: 20.8

        message_reaction (:class:`telegram.MessageReactionUpdated`, optional): A reaction to a
            message was changed by a user. The bot must be an administrator in the chat and must
            explicitly specify :attr:`MESSAGE_REACTION` 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`). The update isn't received for reactions
            set by bots.

            .. versionadded:: 20.8

        message_reaction_count (:class:`telegram.MessageReactionCountUpdated`, optional): Reactions
            to a message with anonymous reactions were changed. The bot must be an administrator in
            the chat and must explicitly specify :attr:`MESSAGE_REACTION_COUNT` 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`). The updates are grouped and can be sent
            with delay up to a few minutes.

            .. versionadded:: 20.8

        business_connection (:class:`telegram.BusinessConnection`, optional): The bot was connected
            to or disconnected from a business account, or a user edited an existing connection
            with the bot.

            .. versionadded:: 21.1

        business_message (:class:`telegram.Message`, optional): New message from a connected
            business account.

            .. versionadded:: 21.1

        edited_business_message (:class:`telegram.Message`, optional): New version of a message
            from a connected business account.

            .. versionadded:: 21.1

        deleted_business_messages (:class:`telegram.BusinessMessagesDeleted`, optional): Messages
            were deleted from a connected business account.

            .. versionadded:: 21.1

        purchased_paid_media (:class:`telegram.PaidMediaPurchased`, optional): A user purchased
            paid media with a non-empty payload sent by the bot in a non-channel chat.

            .. versionadded:: 21.6


    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. This update may at times be triggered by changes to
            message fields that are either unavailable or not actively used by your bot.
        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. This update may at times be triggered by
            changes to message fields that are either unavailable or not actively used by your bot.
        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
            manually 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

        chat_boost (:class:`telegram.ChatBoostUpdated`): Optional. A chat boost was added or
            changed. The bot must be an administrator in the chat to receive these updates.

            .. versionadded:: 20.8

        removed_chat_boost (:class:`telegram.ChatBoostRemoved`): Optional. A boost was removed from
            a chat. The bot must be an administrator in the chat to receive these updates.

            .. versionadded:: 20.8

        message_reaction (:class:`telegram.MessageReactionUpdated`): Optional. A reaction to a
            message was changed by a user. The bot must be an administrator in the chat and must
            explicitly specify :attr:`MESSAGE_REACTION` 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`). The update isn't received for reactions
            set by bots.

            .. versionadded:: 20.8

        message_reaction_count (:class:`telegram.MessageReactionCountUpdated`): Optional. Reactions
            to a message with anonymous reactions were changed. The bot must be an administrator in
            the chat and must explicitly specify :attr:`MESSAGE_REACTION_COUNT` 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`). The updates are grouped and can be sent
            with delay up to a few minutes.

            .. versionadded:: 20.8

        business_connection (:class:`telegram.BusinessConnection`): Optional. The bot was connected
            to or disconnected from a business account, or a user edited an existing connection
            with the bot.

            .. versionadded:: 21.1

        business_message (:class:`telegram.Message`): Optional. New message from a connected
            business account.

            .. versionadded:: 21.1

        edited_business_message (:class:`telegram.Message`): Optional. New version of a message
            from a connected business account.

            .. versionadded:: 21.1

        deleted_business_messages (:class:`telegram.BusinessMessagesDeleted`): Optional. Messages
            were deleted from a connected business account.

            .. versionadded:: 21.1

        purchased_paid_media (:class:`telegram.PaidMediaPurchased`): Optional. A user purchased
            paid media with a non-empty payload sent by the bot in a non-channel chat.

            .. versionadded:: 21.6
    )_effective_chat_effective_message_effective_sender_effective_userbusiness_connectionbusiness_messagecallback_querychannel_post
chat_boostchat_join_requestchat_memberchosen_inline_resultdeleted_business_messagesedited_business_messageedited_channel_postedited_messageinline_querymessagemessage_reactionmessage_reaction_countmy_chat_memberpollpoll_answerpre_checkout_querypurchased_paid_mediaremoved_chat_boostshipping_query	update_id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CHAT_JOIN_REQUEST
CHAT_BOOSTREMOVED_CHAT_BOOSTMESSAGE_REACTIONMESSAGE_REACTION_COUNTBUSINESS_CONNECTIONBUSINESS_MESSAGEEDITED_BUSINESS_MESSAGEDELETED_BUSINESS_MESSAGESPURCHASED_PAID_MEDIA	ALL_TYPESN
api_kwargs)r;   r1   r/   r'   r.   r0   r+   r&   r:   r7   r5   r6   r4   r*   r)   r(   r9   r2   r3   r$   r%   r-   r,   r8   rU   c                   s   t  j|d || _|| _|| _|| _|| _|| _|	| _|
| _	|| _
|| _|| _|| _|| _|| _|| _|| _|| _|| _|| _|| _|| _|| _|| _|| _d | _d | _d | _d | _| jf| _|   d S )NrT   ) super__init__r;   r1   r/   r0   r+   r&   r:   r7   r'   r.   r5   r6   r4   r*   r)   r(   r9   r2   r3   r$   r%   r-   r,   r8   r#   r"   r    r!   Z	_id_attrsZ_freeze)selfr;   r1   r/   r'   r.   r0   r+   r&   r:   r7   r5   r6   r4   r*   r)   r(   r9   r2   r3   r$   r%   r-   r,   r8   rU   	__class__ 4/tmp/pip-unpacked-wheel-swnnwir2/telegram/_update.pyrW     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}n| jr`| jj}n| jrp| jj}n| jr| jj}n| j	r| j	j
}n| jr| jj}nr| jr| jj}nb| jr| jj}nR| jr| jj
}nB| jr| jj}n2| 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 any of

        * :attr:`channel_post`
        * :attr:`edited_channel_post`
        * :attr:`poll`
        * :attr:`chat_boost`
        * :attr:`removed_chat_boost`
        * :attr:`message_reaction_count`
        * :attr:`deleted_business_messages`

        is present.

        .. versionchanged:: 21.1
            This property now also considers :attr:`business_connection`, :attr:`business_message`
            and :attr:`edited_business_message`.

        .. versionchanged:: 21.6
            This property now also considers :attr:`purchased_paid_media`.

        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#   r1   Z	from_userr/   r0   r+   r&   r:   r7   r6   userr4   r*   r)   r2   r%   r-   r$   r8   )rX   r^   r[   r[   r\   effective_user  sJ    














zUpdate.effective_user)r   r   c                 C   sv   | j r| j S d}| jp2| jp2| jp2| jp2| jp2| j }r@|j}n| jrP| jj	}n| j
r^| j
j}|dkrl| j}|| _ |S )a  
        :class:`telegram.User` or :class:`telegram.Chat`: The user or chat that sent this update,
        no matter what kind of update this is.

        Note:
            * Depending on the type of update and the user's 'Remain anonymous' setting, this
              could either be :class:`telegram.User`, :class:`telegram.Chat` or :obj:`None`.

        If no user whatsoever is associated with this update, this gives :obj:`None`. This
        is the case if any of

        * :attr:`poll`
        * :attr:`chat_boost`
        * :attr:`removed_chat_boost`
        * :attr:`message_reaction_count`
        * :attr:`deleted_business_messages`

        is present.

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

        .. versionadded:: 21.1
        N)r"   r1   r/   r'   r.   r%   r-   Zsender_chatr6   Z
voter_chatr2   Z
actor_chatr_   )rX   Zsenderr1   r[   r[   r\   effective_sender4  s.    
zUpdate.effective_senderr   c                 C   s  | j r| j S d}| jr | jj}n| jr0| jj}n| jrJ| jjrJ| jjj}n| jrZ| jj}n| jrj| jj}n| jrz| jj}n| jr| jj}n| j	r| j	j}np| j
r| j
j}n`| jr| jj}nP| jr| jj}n@| jr| jj}n0| jr| jj}n | jr| jj}n| jr
| jj}|| _ |S )a1  
        :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`,
        :attr:`poll_answer`, :attr:`business_connection`, or :attr:`purchased_paid_media`
        is present.

        .. versionchanged:: 21.1
            This property now also considers :attr:`business_message`,
            :attr:`edited_business_message`, and :attr:`deleted_business_messages`.

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

        N)r    r1   chatr/   r&   r'   r.   r4   r*   r)   r(   r9   r2   r3   r%   r-   r,   )rX   ra   r[   r[   r\   effective_chatn  sF    












zUpdate.effective_chatc                 C   s   | j r| j S d}| jr| j}n| jr,| j}nv| jrlt| jj }tsL|dkrR|}qtd|jj ddd n6| j	rz| j	}n(| j
r| j
}n| jr| j}n| jr| 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.

        .. versionchanged:: 21.1
            This property now also considers :attr:`business_message`, and
            :attr:`edited_business_message`.

        Tip:
            This property will only ever return objects of type :class:`telegram.Message` or
            :obj:`None`, never :class:`telegram.MaybeInaccessibleMessage` or
            :class:`telegram.InaccessibleMessage`.
            Currently, this is only relevant for :attr:`callback_query`, as
            :attr:`telegram.CallbackQuery.message` is the only attribute considered by this
            property that can be an object of these types.
        Nz4`update.callback_query` is not `None`, but of type `zl`. This is not considered by `Update.effective_message`. Please manually access this attribute if necessary.   )
stacklevel)r!   r1   r/   r&   
isinstancer   r   rZ   __name__r'   r.   r%   r-   )rX   r1   Zcbq_messager[   r[   r\   effective_message  s6    
zUpdate.effective_messager   )databotr]   c                    s  |  |}|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|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`.Nr1   r/   r0   r+   r&   r:   r7   r'   r.   r5   r6   r4   r*   r)   r(   r9   r2   r3   r$   r%   r-   r,   r8   )rh   ri   )Z_parse_datar   de_jsongetr   r   r
   r   r   r   r   r   r   r   r   r   r   r   r	   r   rV   )clsrh   ri   rY   r[   r\   rj     sZ    
      zUpdate.de_json)NNNNNNNNNNNNNNNNNNNNNNN)N)Brf   
__module____qualname____doc__	__slots__r   Z
UpdateTyper<   r   str__annotations__r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   listrS   r   intr   r   r   r   r
   r   r   r   r   r   r   r   r   r   r   r   r	   r   r   rW   propertyr_   r   r`   rb   rg   classmethodrj   __classcell__r[   r[   rY   r\   r   -   s   
 j                       DU9H?r   N)1ro   typingr   r   r   r   r   Ztelegramr   Ztelegram._businessr   r	   Ztelegram._callbackqueryr
   Ztelegram._chatboostr   r   Ztelegram._chatjoinrequestr   Ztelegram._chatmemberupdatedr   Ztelegram._choseninlineresultr   Ztelegram._inline.inlinequeryr   Ztelegram._messager   Z telegram._messagereactionupdatedr   r   Ztelegram._paidmediar   Z"telegram._payment.precheckoutqueryr   Ztelegram._payment.shippingqueryr   Ztelegram._pollr   r   Ztelegram._telegramobjectr   Ztelegram._utils.typesr   Ztelegram._utils.warningsr   r   r   r   r   r[   r[   r[   r\   <module>   s*   