
    iFQ                        d 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 erddlmZ  G d de          Z G d de          Z G d de          Z G d de          Z G d de          ZdS )z:This module contains classes related to gifs sent by bots.    )Sequence)TYPE_CHECKING)Chat)Sticker)MessageEntity)TelegramObject)de_json_optionalde_list_optionalparse_sequence_arg)parse_message_entitiesparse_message_entity)JSONDict)Botc            
       D     e Zd ZdZdZdddededededz  f fd	Z xZS )
GiftBackgrounda  This object describes the background of a gift.

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

    .. versionadded:: 22.6

    Args:
        center_color (:obj:`int`): Center color of the background in RGB format.
        edge_color (:obj:`int`): Edge color of the background in RGB format.
        text_color (:obj:`int`): Text color of the background in RGB format.

    Attributes:
        center_color (:obj:`int`): Center color of the background in RGB format.
        edge_color (:obj:`int`): Edge color of the background in RGB format.
        text_color (:obj:`int`): Text color of the background in RGB format.

    )center_color
edge_color
text_colorN
api_kwargsr   r   r   r   c                    t                                          |           || _        || _        || _        | j        | j        | j        f| _        |                                  d S Nr   )super__init__r   r   r   	_id_attrs_freeze)selfr   r   r   r   	__class__s        O/Users/shanyulin/my-agent/.venv/lib/python3.11/site-packages/telegram/_gifts.pyr   zGiftBackground.__init__@   sd     	J///!-)) OO
 	    )	__name__
__module____qualname____doc__	__slots__intr   r   __classcell__r   s   @r   r   r   %   s         (I '+    	 tO         r    r   c                        e Zd ZdZdZ	 	 	 	 	 	 	 	 	 	 ddddededededz  d	edz  d
edz  dedz  dedz  dedz  de	dz  de
dz  de
dz  dedz  dedz  f fdZeddedddd f fd            Z xZS )Giftak  This object represents a gift that can be sent by the bot.

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

    .. versionadded:: 21.8

    Args:
        id (:obj:`str`): Unique identifier of the gift.
        sticker (:class:`~telegram.Sticker`): The sticker that represents the gift.
        star_count (:obj:`int`): The number of Telegram Stars that must be paid to send the
            sticker.
        total_count (:obj:`int`, optional): The total number of the gifts of this type that can be
            sent by all users; for limited gifts only.
        remaining_count (:obj:`int`, optional): The number of remaining gifts of this type that can
            be sent by all users; for limited gifts only.
        upgrade_star_count (:obj:`int`, optional): The number of Telegram Stars that must be paid
            to upgrade the gift to a unique one.

            .. versionadded:: 21.10
        publisher_chat (:class:`telegram.Chat`, optional): Information about the chat that
            published the gift.

            .. versionadded:: 22.4
        personal_total_count (:obj:`int`, optional): The total number of gifts of this type that
            can be sent by the bot; for limited gifts only.

            .. versionadded:: 22.6
        personal_remaining_count (:obj:`int`, optional): The number of remaining gifts of this type
            that can be sent by the bot; for limited gifts only.

            .. versionadded:: 22.6
        background (:class:`GiftBackground`, optional): Background of the gift.

            .. versionadded:: 22.6
        is_premium (:obj:`bool`, optional): :obj:`True`, if the gift can only be purchased by
            Telegram Premium subscribers.

            .. versionadded:: 22.6
        has_colors (:obj:`bool`, optional): :obj:`True`, if the gift can be used (after being
            upgraded) to customize a user's appearance.

            .. versionadded:: 22.6
        unique_gift_variant_count (:obj:`int`, optional): The total number of different unique
            gifts that can be obtained by upgrading the gift.

            .. versionadded:: 22.6

    Attributes:
        id (:obj:`str`): Unique identifier of the gift.
        sticker (:class:`~telegram.Sticker`): The sticker that represents the gift.
        star_count (:obj:`int`): The number of Telegram Stars that must be paid to send the
            sticker.
        total_count (:obj:`int`): Optional. The total number of the gifts of this type that can be
            sent by all users; for limited gifts only.
        remaining_count (:obj:`int`): Optional. The number of remaining gifts of this type that can
            be sent by all users; for limited gifts only.
        upgrade_star_count (:obj:`int`): Optional. The number of Telegram Stars that must be paid
            to upgrade the gift to a unique one.

            .. versionadded:: 21.10
        publisher_chat (:class:`telegram.Chat`): Optional. Information about the chat that
            published the gift.

            .. versionadded:: 22.4
        personal_total_count (:obj:`int`): Optional. The total number of gifts of this type that
            can be sent by the bot; for limited gifts only.

            .. versionadded:: 22.6
        personal_remaining_count (:obj:`int`): Optional. The number of remaining gifts of this type
            that can be sent by the bot; for limited gifts only.

            .. versionadded:: 22.6
        background (:class:`GiftBackground`): Optional. Background of the gift.

            .. versionadded:: 22.6
        is_premium (:obj:`bool`): Optional. :obj:`True`, if the gift can only be purchased by
            Telegram Premium subscribers.

            .. versionadded:: 22.6
        has_colors (:obj:`bool`): Optional. :obj:`True`, if the gift can be used (after being
            upgraded) to customize a user's appearance.

            .. versionadded:: 22.6
        unique_gift_variant_count (:obj:`int`): Optional. The total number of different unique
            gifts that can be obtained by upgrading the gift.

            .. versionadded:: 22.6

    )
background
has_colorsid
is_premiumpersonal_remaining_countpersonal_total_countpublisher_chatremaining_count
star_countstickertotal_countunique_gift_variant_countupgrade_star_countNr   r-   r4   r3   r5   r2   r7   r1   r0   r/   r+   r.   r,   r6   r   c                D   t                                          |           || _        || _        || _        || _        || _        || _        || _        || _	        |	| _
        |
| _        || _        || _        || _        | j        f| _        |                                  d S r   )r   r   r-   r4   r3   r5   r2   r7   r1   r0   r/   r+   r.   r,   r6   r   r   )r   r-   r4   r3   r5   r2   r7   r1   r0   r/   r+   r.   r,   r6   r   r   s                  r   r   zGift.__init__   s    $ 	J/// ')'2+:.@+90D!4L%1;'1'15N&'r    databot
Bot | Nonereturnc                 |   |                      |          }t          |                    d          t          |          |d<   t          |                    d          t          |          |d<   t          |                    d          t
          |          |d<   t                                          ||          S ),See :meth:`telegram.TelegramObject.de_json`.r4   r1   r+   r9   r:   )_parse_datar	   getr   r   r   r   de_jsonclsr9   r:   r   s      r   rB   zGift.de_json   s     t$$*488I+>+>MMY!1$((;K2L2LdTW!X!X-dhh|.D.DnVYZZ\wwDc222r    )
NNNNNNNNNNN)r!   r"   r#   r$   r%   strr   r&   r   r   boolr   r   classmethodrB   r'   r(   s   @r   r*   r*   V   s       Y YvI* #'&*)-&*+//3,0"&"&04#  '+!# # ## # 	#
 4Z# t#  $J# t# "Dj# #&*# #T)# 4K# 4K# $':#  tO!# # # # # #J 3 38 3, 3& 3 3 3 3 3 [3 3 3 3 3r    r*   c                   r     e Zd ZdZdZdddee         dedz  f fdZe	dded	d
dd f fd            Z
 xZS )Giftsav  This object represent a list of gifts.

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

    .. versionadded:: 21.8

    Args:
        gifts (Sequence[:class:`Gift`]): The sequence of gifts.

    Attributes:
        gifts (tuple[:class:`Gift`]): The sequence of gifts.

    )giftsNr   rK   r   c                    t                                          |           t          |          | _        | j        f| _        |                                  d S r   )r   r   r   rK   r   r   )r   rK   r   r   s      r   r   zGifts.__init__  sK     	J///'9%'@'@
*r    r9   r:   r;   r<   c                     |                      |          }t          |                    d          t          |          |d<   t	                                          ||          S )r>   rK   r?   )r@   r
   rA   r*   r   rB   rC   s      r   rB   zGifts.de_json  sQ     t$$('):):D#FFWwwDc222r    rE   )r!   r"   r#   r$   r%   r   r*   r   r   rH   rB   r'   r(   s   @r   rJ   rJ      s          I '+	  ~ tO	      3 38 3, 3' 3 3 3 3 3 [3 3 3 3 3r    rJ   c                   $    e Zd ZdZdZ	 	 	 	 	 	 	 	 	 ddddededz  dedz  dedz  d	edz  d
edz  de	e
         dz  dedz  dedz  dedz  dedz  f fdZeddedddd f fd            Zde
defdZddee         dz  dee
ef         fdZ xZS )GiftInfoa  Describes a service message about a regular gift that was sent or received.

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

    .. versionadded:: 22.1

    Args:
        gift (:class:`Gift`): Information about the gift.
        owned_gift_id (:obj:`str`, optional): Unique identifier of the received gift for the bot;
            only present for gifts received on behalf of business accounts.
        convert_star_count (:obj:`int`, optional) Number of Telegram Stars that can be claimed by
            the receiver by converting the gift; omitted if conversion to Telegram Stars
            is impossible.
        prepaid_upgrade_star_count (:obj:`int`, optional): Number of Telegram Stars that were
            prepaid for the ability to upgrade the gift.
        can_be_upgraded (:obj:`bool`, optional): :obj:`True`, if the gift can be upgraded
            to a unique gift.
        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_upgrade_separate (:obj:`bool`, optional): :obj:`True`, if the gift's upgrade was
            purchased after the gift was sent.

            .. 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:
        gift (:class:`Gift`): Information about the gift.
        owned_gift_id (:obj:`str`): Optional. Unique identifier of the received gift for the bot;
            only present for gifts received on behalf of business accounts.
        convert_star_count (:obj:`int`): Optional. Number of Telegram Stars that can be claimed by
            the receiver by converting the gift; omitted if conversion to Telegram Stars
            is impossible.
        prepaid_upgrade_star_count (:obj:`int`): Optional. Number of Telegram Stars that were
            prepaid for the ability to upgrade the gift.
        can_be_upgraded (:obj:`bool`): Optional. :obj:`True`, if the gift can be upgraded
            to a unique gift.
        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_upgrade_separate (:obj:`bool`): Optional. :obj:`True`, if the gift's upgrade was
            purchased after the gift was sent.

            .. 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_upgrade_separateowned_gift_idprepaid_upgrade_star_counttextunique_gift_numberNr   rS   rV   rQ   rW   rP   rX   rR   rT   rY   rU   r   c                4   t                                          |           || _        || _        || _        || _        || _        || _        t          |          | _	        || _
        |	| _        |
| _        | j        f| _        |                                  d S r   )r   r   rS   rV   rQ   rW   rP   rX   r   rR   rT   rY   rU   r   r   )r   rS   rV   rQ   rW   rP   rX   rR   rT   rY   rU   r   r   s               r   r   zGiftInfo.__init__c  s     	J///	)6.@6P',; $	3Eh3O3O'1.@0C )r    r9   r:   r;   r<   c                 $   |                      |          }t          |                    d          t          |          |d<   t	          |                    d          t
          |          |d<   t                                          ||          S )r>   rS   rR   r?   )r@   r	   rA   r*   r
   r   r   rB   rC   s      r   rB   zGiftInfo.de_json  st     t$$'(8(8$DDV+DHHZ,@,@-QTUUZwwDc222r    entityc                 X    | 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 ``Message.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 gift info has no text.

        This GiftInfo has no 'text'.)rX   RuntimeErrorr   )r   r\   s     r   parse_entityzGiftInfo.parse_entity  s/    ( y 	?=>>>#DIv666r    typesc                 d    | j         st          d          t          | j         | j        |          S )aO  
        Returns a :obj:`dict` that maps :class:`telegram.MessageEntity` to :obj:`str`.
        It contains entities from this gift info'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 gift info has no text.

        r^   )rX   r_   r   rR   )r   ra   s     r   parse_entitieszGiftInfo.parse_entities  s3    0 y 	?=>>>%diFFFr    )	NNNNNNNNNrE   )r!   r"   r#   r$   r%   r*   rF   r&   rG   r   r   r   r   rH   rB   r`   listdictrc   r'   r(   s   @r   rO   rO     s       9 9vI  %))-15'+37"&)-+/ '+   Tz  $J	
 %($J  Dj =)D0 4K  $J "D[ tO     B 3 38 3, 3* 3 3 3 3 3 [37= 7S 7 7 7 72G GDI$4 G]TWEW@X G G G G G G G Gr    rO   c                   L     e Zd ZdZdZdddedededed	ed
edz  f fdZ xZS )AcceptedGiftTypesa  This object describes the types of gifts that can be gifted to 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:`unlimited_gifts`, :attr:`limited_gifts`,
    :attr:`unique_gifts`, :attr:`premium_subscription` and :attr:`gifts_from_channels` are equal.

    .. versionadded:: 22.1
    .. versionchanged:: 22.6
        :attr:`gifts_from_channels` is now considered for equality checks.

    Args:
        unlimited_gifts (:class:`bool`): :obj:`True`, if unlimited regular gifts are accepted.
        limited_gifts (:class:`bool`): :obj:`True`, if limited regular gifts are accepted.
        unique_gifts (:class:`bool`): :obj:`True`, if unique gifts or gifts that can be upgraded
            to unique for free are accepted.
        premium_subscription (:class:`bool`): :obj:`True`, if a Telegram Premium subscription
            is accepted.
        gifts_from_channels (:obj:`bool`): :obj:`True`, if transfers of unique gifts from channels
            are accepted

            .. versionadded:: 22.6

    Attributes:
        unlimited_gifts (:class:`bool`): :obj:`True`, if unlimited regular gifts are accepted.
        limited_gifts (:class:`bool`): :obj:`True`, if limited regular gifts are accepted.
        unique_gifts (:class:`bool`): :obj:`True`, if unique gifts or gifts that can be upgraded
            to unique for free are accepted.
        premium_subscription (:class:`bool`): :obj:`True`, if a Telegram Premium subscription
            is accepted.
        gifts_from_channels (:obj:`bool`): :obj:`True`, if transfers of unique gifts from channels
            are accepted

            .. versionadded:: 22.6

    )gifts_from_channelslimited_giftspremium_subscriptionunique_giftsunlimited_giftsNr   rl   ri   rk   rj   rh   r   c                   t                                          |           || _        || _        || _        || _        || _        | j        | j        | j        | j        | j        f| _        |                                  d S r   )	r   r   rl   ri   rk   rj   rh   r   r   )r   rl   ri   rk   rj   rh   r   r   s          r   r   zAcceptedGiftTypes.__init__  s     	J///%4#0".*>!)<   %$
 	r    )	r!   r"   r#   r$   r%   rG   r   r   r'   r(   s   @r   rg   rg     s        " "HI  '+    	
 # " tO         r    rg   N)r$   collections.abcr   typingr   telegram._chatr   telegram._files.stickerr   telegram._messageentityr   telegram._telegramobjectr   telegram._utils.argumentparsingr	   r
   r   telegram._utils.entitiesr   r   telegram._utils.typesr   telegramr   r   r*   rJ   rO   rg    r    r   <module>ry      s  ( A @ $ $ $ $ $ $                   + + + + + + 1 1 1 1 1 1 3 3 3 3 3 3 b b b b b b b b b b Q Q Q Q Q Q Q Q * * * * * * . . . . .^ . . .bY3 Y3 Y3 Y3 Y3> Y3 Y3 Y3x%3 %3 %3 %3 %3N %3 %3 %3PhG hG hG hG hG~ hG hG hGVF F F F F F F F F Fr    