o
    Zzj6O  ã                   @   s  d Z ddl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 ddlmZ ddlmZmZmZ ddlmZmZ ddlmZmZ ddl m!Z! erfddlm"Z" G dd„ deƒZ#G dd„ deƒZ$G dd„ de#ƒZ%G dd„ de#ƒZ&dS )z8This module contains objects that represent owned gifts.é    N)ÚSequence)ÚTYPE_CHECKINGÚFinal)Ú	constants)ÚGift)ÚMessageEntity)ÚTelegramObject)Ú
UniqueGift)ÚUser)Úenum)Úde_json_optionalÚde_list_optionalÚparse_sequence_arg)Úextract_tzinfo_from_defaultsÚfrom_timestamp)Úparse_message_entitiesÚparse_message_entity)ÚJSONDict)ÚBotc                       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< 	 ddœde	dedB d	df‡ fd
d„Zeddeddd	d f‡ fdd„ƒZ‡  ZS )Ú	OwnedGiftaî  This object describes a gift received and owned by a user or a chat. Currently, it
    can be one of:

    * :class:`telegram.OwnedGiftRegular`
    * :class:`telegram.OwnedGiftUnique`

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

    .. versionadded:: 22.1

    Args:
        type (:obj:`str`): Type of the owned gift.

    Attributes:
        type (:obj:`str`): Type of the owned gift.
    )ÚtypeÚREGULARÚUNIQUEN©Ú
api_kwargsr   r   Úreturnc                   s6   t ƒ j|d� t tj||¡| _| jf| _|  ¡  d S ©Nr   )	ÚsuperÚ__init__r   Ú
get_memberr   ÚOwnedGiftTyper   Ú	_id_attrsÚ_freeze)Úselfr   r   ©Ú	__class__© úN/var/www/kodo/tsheker/venv/lib/python3.10/site-packages/telegram/_ownedgift.pyr   C   s   
zOwnedGift.__init__ÚdataÚbotú
Bot | Nonec                    sX   |   |¡}| jt| jti}| tu r$| d¡|v r$|| d¡ j||d�S t	ƒ j||d�S )aX  Converts JSON data to the appropriate :class:`OwnedGift` object, i.e. takes
        care of selecting the correct subclass.

        Args:
            data (dict[:obj:`str`, ...]): The JSON data.
            bot (:class:`telegram.Bot`, optional): The bot associated with this object.

        Returns:
            The Telegram object.

        r   ©r(   r)   )
Ú_parse_datar   ÚOwnedGiftRegularr   ÚOwnedGiftUniquer   ÚgetÚpopÚde_jsonr   )Úclsr(   r)   Ú_class_mappingr$   r&   r'   r1   O   s   
þzOwnedGift.de_json©N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__r   r    r   r   ÚstrÚ__annotations__r   r   r   Úclassmethodr1   Ú__classcell__r&   r&   r$   r'   r   )   s"   
 üþüû&r   c                       sl   e Zd ZdZdZ	dddœdedee dedB de	dB f‡ fd	d
„Z
edde	dddd f‡ fdd„ƒZ‡  ZS )Ú
OwnedGiftsau  Contains the list of gifts received and owned by a user or a chat.

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

    .. versionadded:: 22.1

    Args:
        total_count (:obj:`int`): The total number of gifts owned by the user or the chat.
        gifts (Sequence[:class:`telegram.OwnedGift`]): The list of gifts.
        next_offset (:obj:`str`, optional): Offset for the next request. If empty,
            then there are no more results.

    Attributes:
        total_count (:obj:`int`): The total number of gifts owned by the user or the chat.
        gifts (Sequence[:class:`telegram.OwnedGift`]): The list of gifts.
        next_offset (:obj:`str`): Optional. Offset for the next request. If empty,
            then there are no more results.
    )ÚgiftsÚnext_offsetÚtotal_countNr   rA   r?   r@   r   c                   s>   t ƒ j|d� || _t|ƒ| _|| _| j| jf| _|  ¡  d S r   )r   r   rA   r   r?   r@   r!   r"   )r#   rA   r?   r@   r   r$   r&   r'   r   „   s   
zOwnedGifts.__init__r(   r)   r*   r   c                    s0   |   |¡}t| d¡t|ƒ|d< tƒ j||d�S )z,See :meth:`telegram.TelegramObject.de_json`.r?   r+   )r,   r   r/   r   r   r1   )r2   r(   r)   r$   r&   r'   r1   •   s   
zOwnedGifts.de_jsonr4   )r5   r6   r7   r8   r9   Úintr   r   r:   r   r   r<   r1   r=   r&   r&   r$   r'   r>   i   s"    
üúþýüú&r>   c                "       s  e Zd ZdZdZ												d"ddœdedejdedB de	dB d	edB d
e
e dB dedB dedB dedB dedB dedB dedB dedB dedB dedB ddf ‡ fdd„Zed#dedddd f‡ fdd„ƒZdedefdd„Zd#dee dB deeef fd d!„Z‡  ZS )$r-   a�  Describes a regular gift owned by a user or a chat.

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

    .. versionadded:: 22.1

    Args:
        gift (:class:`telegram.Gift`): Information about the regular gift.
        owned_gift_id (:obj:`str`, optional): Unique identifier of the gift for the bot; for
            gifts received on behalf of business accounts only.
        sender_user (:class:`telegram.User`, optional): Sender of the gift if it is a known user.
        send_date (:obj:`datetime.datetime`): Date the gift was sent as :class:`datetime.datetime`.
            |datetime_localization|.
        text (:obj:`str`, optional): Text of the message that was added to the gift.
        entities (Sequence[:class:`telegram.MessageEntity`], optional): Special entities that
            appear in the text.
        is_private (:obj:`bool`, optional): :obj:`True`, if the sender and gift text are shown
            only to the gift receiver; otherwise, everyone will be able to see them.
        is_saved (:obj:`bool`, optional): :obj:`True`, if the gift is displayed on the account's
            profile page; for gifts received on behalf of business accounts only.
        can_be_upgraded (:obj:`bool`, optional): :obj:`True`, if the gift can be upgraded to a
            unique gift; for gifts received on behalf of business accounts only.
        was_refunded (:obj:`bool`, optional): :obj:`True`, if the gift was refunded and isn't
            available anymore.
        convert_star_count (:obj:`int`, optional): Number of Telegram Stars that can be
            claimed by the receiver instead of the gift; omitted if the gift cannot be converted
            to Telegram Stars; for gifts received on behalf of business accounts only.
        prepaid_upgrade_star_count (:obj:`int`, optional): Number of Telegram Stars that were
            paid for the ability to upgrade the gift.
        is_upgrade_separate (:obj:`bool`, optional): :obj:`True`, if the gift's upgrade was
            purchased after the gift was sent; for gifts received on behalf of business accounts

            .. versionadded:: 22.6
        unique_gift_number (:obj:`int`, optional): Unique number reserved for this gift when
            upgraded. See the number field in :class:`~telegram.UniqueGift`

            ... versionadded:: 22.6

    Attributes:
        type (:obj:`str`): Type of the gift, always :attr:`~telegram.OwnedGift.REGULAR`.
        gift (:class:`telegram.Gift`): Information about the regular gift.
        owned_gift_id (:obj:`str`): Optional. Unique identifier of the gift for the bot; for
            gifts received on behalf of business accounts only.
        sender_user (:class:`telegram.User`): Optional. Sender of the gift if it is a known user.
        send_date (:obj:`datetime.datetime`): Date the gift was sent as :class:`datetime.datetime`.
            |datetime_localization|.
        text (:obj:`str`): Optional. Text of the message that was added to the gift.
        entities (Sequence[:class:`telegram.MessageEntity`]): Optional. Special entities that
            appear in the text.
        is_private (:obj:`bool`): Optional. :obj:`True`, if the sender and gift text are shown
            only to the gift receiver; otherwise, everyone will be able to see them.
        is_saved (:obj:`bool`): Optional. :obj:`True`, if the gift is displayed on the account's
            profile page; for gifts received on behalf of business accounts only.
        can_be_upgraded (:obj:`bool`): Optional. :obj:`True`, if the gift can be upgraded to a
            unique gift; for gifts received on behalf of business accounts only.
        was_refunded (:obj:`bool`): Optional. :obj:`True`, if the gift was refunded and isn't
            available anymore.
        convert_star_count (:obj:`int`): Optional. Number of Telegram Stars that can be
            claimed by the receiver instead of the gift; omitted if the gift cannot be converted
            to Telegram Stars; for gifts received on behalf of business accounts only.
        prepaid_upgrade_star_count (:obj:`int`): Optional. Number of Telegram Stars that were
            paid for the ability to upgrade the gift.
        is_upgrade_separate (:obj:`bool`): Optional. :obj:`True`, if the gift's upgrade was
            purchased after the gift was sent; for gifts received on behalf of business accounts

            .. versionadded:: 22.6
        unique_gift_number (:obj:`int`): Optional. Unique number reserved for this gift when
            upgraded. See the number field in :class:`~telegram.UniqueGift`

            ... versionadded:: 22.6

    )Úcan_be_upgradedÚconvert_star_countÚentitiesÚgiftÚ
is_privateÚis_savedÚis_upgrade_separateÚowned_gift_idÚprepaid_upgrade_star_countÚ	send_dateÚsender_userÚtextÚunique_gift_numberÚwas_refundedNr   rF   rL   rJ   rM   rN   rE   rG   rH   rC   rP   rD   rK   rI   rO   r   r   c                   sª   t ƒ jtj|d� |  ¡ �> || _|| _|| _|| _|| _	t
|ƒ| _|| _|| _|	| _|
| _|| _|| _|| _|| _| j| j| jf| _W d   ƒ d S 1 sNw   Y  d S ©N)r   r   )r   r   r   r   Ú	_unfrozenrF   rL   rJ   rM   rN   r   rE   rG   rH   rC   rP   rD   rK   rI   rO   r   r!   )r#   rF   rL   rJ   rM   rN   rE   rG   rH   rC   rP   rD   rK   rI   rO   r   r$   r&   r'   r   ú   s$   

"ðzOwnedGiftRegular.__init__r(   r)   r*   c                    sz   |   |¡}t|ƒ}t| d¡|d�|d< t| d¡t|ƒ|d< t| d¡t|ƒ|d< t| d¡t|ƒ|d< t	ƒ j
||d�S )ú'See :meth:`telegram.OwnedGift.de_json`.rL   ©ÚtzinforM   rF   rE   r+   )r,   r   r   r/   r   r
   r   r   r   r   r1   ©r2   r(   r)   Ú
loc_tzinfor$   r&   r'   r1   !  s   
zOwnedGiftRegular.de_jsonÚentityc                 C   s   | j stdƒ‚t| j |ƒS )aÞ  Returns the text in :attr:`text`
        from a given :class:`telegram.MessageEntity` of :attr:`entities`.

        Note:
            This method is present because Telegram calculates the offset and length in
            UTF-16 codepoint pairs, which some versions of Python don't handle automatically.
            (That is, you can't just slice ``OwnedGiftRegular.text`` with the offset and length.)

        Args:
            entity (:class:`telegram.MessageEntity`): The entity to extract the text from. It must
                be an entity that belongs to :attr:`entities`.

        Returns:
            :obj:`str`: The text of the given entity.

        Raises:
            RuntimeError: If the owned gift has no text.

        ú$This OwnedGiftRegular has no 'text'.)rN   ÚRuntimeErrorr   )r#   rX   r&   r&   r'   Úparse_entity.  s   zOwnedGiftRegular.parse_entityÚtypesc                 C   s   | j stdƒ‚t| j | j|ƒS )aQ  
        Returns a :obj:`dict` that maps :class:`telegram.MessageEntity` to :obj:`str`.
        It contains entities from this owned gift's text filtered by their ``type`` attribute as
        the key, and the text that each entity belongs to as the value of the :obj:`dict`.

        Note:
            This method should always be used instead of the :attr:`entities`
            attribute, since it calculates the correct substring from the message text based on
            UTF-16 codepoints. See :attr:`parse_entity` for more info.

        Args:
            types (list[:obj:`str`], optional): List of ``MessageEntity`` types as strings. If the
                    ``type`` attribute of an entity is contained in this list, it will be returned.
                    Defaults to :attr:`telegram.MessageEntity.ALL_TYPES`.

        Returns:
            dict[:class:`telegram.MessageEntity`, :obj:`str`]: A dictionary of entities mapped to
            the text that belongs to them, calculated based on UTF-16 codepoints.

        Raises:
            RuntimeError: If the owned gift has no text.

        rY   )rN   rZ   r   rE   )r#   r\   r&   r&   r'   Úparse_entitiesG  s   zOwnedGiftRegular.parse_entities)NNNNNNNNNNNNr4   )r5   r6   r7   r8   r9   r   ÚdtmÚdatetimer:   r
   r   r   ÚboolrB   r   r   r<   r1   r[   ÚlistÚdictr]   r=   r&   r&   r$   r'   r-   ž   sl    Jñïþýüûú
ùø	÷
öõôóòñïî',r-   c                       s¢   e Zd ZdZdZ						dddœdedejdedB de	dB d	e
dB d
e
dB dedB dejdB dedB ddf‡ fdd„Zeddedddd f‡ fdd„ƒZ‡  ZS )r.   ah  
    Describes a unique gift received and owned by a user or a chat.

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

    .. versionadded:: 22.1

    Args:
        gift (:class:`telegram.UniqueGift`): Information about the unique gift.
        owned_gift_id (:obj:`str`, optional): Unique identifier of the received gift for the
            bot; for gifts received on behalf of business accounts only.
        sender_user (:class:`telegram.User`, optional): Sender of the gift if it is a known user.
        send_date (:obj:`datetime.datetime`): Date the gift was sent as :class:`datetime.datetime`.
            |datetime_localization|
        is_saved (:obj:`bool`, optional): :obj:`True`, if the gift is displayed on the account's
            profile page; for gifts received on behalf of business accounts only.
        can_be_transferred (:obj:`bool`, optional): :obj:`True`, if the gift can be transferred to
            another owner; for gifts received on behalf of business accounts only.
        transfer_star_count (:obj:`int`, optional): Number of Telegram Stars that must be paid
            to transfer the gift; omitted if the bot cannot transfer the gift.
        next_transfer_date (:obj:`datetime.datetime`, optional): Date when the gift can be
            transferred. If it's in the past, then the gift can be transferred now.
            |datetime_localization|
            .. versionadded:: 22.3

    Attributes:
        type (:obj:`str`): Type of the owned gift, always :tg-const:`~telegram.OwnedGift.UNIQUE`.
        gift (:class:`telegram.UniqueGift`): Information about the unique gift.
        owned_gift_id (:obj:`str`): Optional. Unique identifier of the received gift for the
            bot; for gifts received on behalf of business accounts only.
        sender_user (:class:`telegram.User`): Optional. Sender of the gift if it is a known user.
        send_date (:obj:`datetime.datetime`): Date the gift was sent as :class:`datetime.datetime`.
            |datetime_localization|
        is_saved (:obj:`bool`): Optional. :obj:`True`, if the gift is displayed on the account's
            profile page; for gifts received on behalf of business accounts only.
        can_be_transferred (:obj:`bool`): Optional. :obj:`True`, if the gift can be transferred to
            another owner; for gifts received on behalf of business accounts only.
        transfer_star_count (:obj:`int`): Optional. Number of Telegram Stars that must be paid
            to transfer the gift; omitted if the bot cannot transfer the gift.
        next_transfer_date (:obj:`datetime.datetime`): Optional. Date when the gift can be
            transferred. If it's in the past, then the gift can be transferred now.
            |datetime_localization|
            .. versionadded:: 22.3
    )Úcan_be_transferredrF   rH   Únext_transfer_daterJ   rL   rM   Útransfer_star_countNr   rF   rL   rJ   rM   rH   rc   re   rd   r   r   c	          
         s‚   t ƒ jtj|	d� |  ¡ �* || _|| _|| _|| _|| _	|| _
|| _|| _| j| j| jf| _W d   ƒ d S 1 s:w   Y  d S rQ   )r   r   r   r   rR   rF   rL   rJ   rM   rH   rc   re   rd   r   r!   )
r#   rF   rL   rJ   rM   rH   rc   re   rd   r   r$   r&   r'   r   Ÿ  s   
"özOwnedGiftUnique.__init__r(   r)   r*   c                    sz   |   |¡}t|ƒ}t| d¡|d�|d< t| d¡t|ƒ|d< t| d¡t|ƒ|d< t| d¡|d�|d< tƒ j||d�S )rS   rL   rT   rM   rF   rd   r+   )	r,   r   r   r/   r   r
   r	   r   r1   rV   r$   r&   r'   r1   º  s   


ÿzOwnedGiftUnique.de_json)NNNNNNr4   )r5   r6   r7   r8   r9   r	   r^   r_   r:   r
   r`   rB   r   r   r<   r1   r=   r&   r&   r$   r'   r.   e  sD    .÷õþýüûúùø	÷õô&r.   )'r8   r_   r^   Úcollections.abcr   Útypingr   r   Útelegramr   Útelegram._giftsr   Útelegram._messageentityr   Útelegram._telegramobjectr   Útelegram._uniquegiftr	   Útelegram._userr
   Útelegram._utilsr   Útelegram._utils.argumentparsingr   r   r   Útelegram._utils.datetimer   r   Útelegram._utils.entitiesr   r   Útelegram._utils.typesr   r   r   r>   r-   r.   r&   r&   r&   r'   Ú<module>   s,   @5 H