
    iBC                    <   d Z ddlmZ ddlZddl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 ddlZd	Ze	r,dd
lmZ ddlmZ ddlmZ eeef         Zed         Zed         Z eh d          Zedhz  Zej         Z  G d d          Z! G d de!          Z"dS )a:  
The MIT License (MIT)

Copyright (c) 2015-present Rapptz

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
    )annotationsN)AnyLiteralOptionalTYPE_CHECKINGTupleUnion   )DiscordException)utils)File)Asset)Self)ConnectionState)_WebhookState)webpjpegjpgpng)r   r   r   r   gif>   r   r   r   r   r   c                  P    e Zd ZU dZded<   ded<   ddZd	d
ddZedddddZdS )
AssetMixin strurlzOptional[Any]_statereturnbytesc                   K   | j         t          d          | j         j                            | j                   d{V S )a  |coro|

        Retrieves the content of this asset as a :class:`bytes` object.

        Raises
        ------
        DiscordException
            There was no internal connection state.
        HTTPException
            Downloading the asset failed.
        NotFound
            The asset was deleted.

        Returns
        -------
        :class:`bytes`
            The content of the asset.
        Nz+Invalid state (no ConnectionState provided))r   r   httpget_from_cdnr   selfs    T/home/ubuntu/.hermes/hermes-agent/venv/lib/python3.11/site-packages/discord/asset.pyreadzAssetMixin.readA   sL      & ;"#PQQQ[%2248<<<<<<<<<    T)
seek_beginfp6Union[str, bytes, os.PathLike[Any], io.BufferedIOBase]r'   boolintc               H  K   |                                   d{V }t          |t          j                  r.|                    |          }|r|                    d           |S t          |d          5 }|                    |          cddd           S # 1 swxY w Y   dS )a2  |coro|

        Saves this asset into a file-like object.

        Parameters
        ----------
        fp: Union[:class:`io.BufferedIOBase`, :class:`os.PathLike`]
            The file-like object to save this asset to or the filename
            to use. If a filename is passed then a file is created with that
            filename and used instead.
        seek_begin: :class:`bool`
            Whether to seek to the beginning of the file after saving is
            successfully done.

        Raises
        ------
        DiscordException
            There was no internal connection state.
        HTTPException
            Downloading the asset failed.
        NotFound
            The asset was deleted.

        Returns
        --------
        :class:`int`
            The number of bytes written.
        Nr   wb)r%   
isinstanceioBufferedIOBasewriteseekopen)r#   r(   r'   datawrittenfs         r$   savezAssetMixin.saveY   s      < YY[[      b"+,, 	%hhtnnG 


Nb$ %1wwt}}% % % % % % % % % % % % % % % % % %s   5BBBNFfilenamedescriptionspoilerr9   Optional[str]r:   r;   r   c                  K   |                                   d{V }|t          ur|nt          j        | j                  j        }t          t          j        |          |||          S )a  |coro|

        Converts the asset into a :class:`File` suitable for sending via
        :meth:`abc.Messageable.send`.

        .. versionadded:: 2.0

        Parameters
        -----------
        filename: Optional[:class:`str`]
            The filename of the file. If not provided, then the filename from
            the asset's URL is used.
        description: Optional[:class:`str`]
            The description for the file.
        spoiler: :class:`bool`
            Whether the file is a spoiler.

        Raises
        ------
        DiscordException
            The asset does not have an associated state.
        ValueError
            The asset is a unicode emoji.
        TypeError
            The asset is a sticker with lottie type.
        HTTPException
            Downloading the asset failed.
        NotFound
            The asset was deleted.

        Returns
        -------
        :class:`File`
            The asset as a file suitable for sending.
        Nr8   )	r%   MISSINGyarlURLr   namer   r/   BytesIO)r#   r9   r:   r;   r4   file_filenames         r$   to_filezAssetMixin.to_file   sl      V YY[[      $,G$;$;$(ASASAXBJt$$}+_fggggr&   )r   r   )r(   r)   r'   r*   r   r+   )r9   r<   r:   r<   r;   r*   r   r   )	__name__
__module____qualname__	__slots____annotations__r%   r7   r>   rD   r   r&   r$   r   r   <   s         IHHH= = = =0 lp &% &% &% &% &% &%V #*%)-h -h -h -h -h -h -h -hr&   r   c                  (   e Zd ZU dZdZded<   dZdddIdZedJd            Z	edKd            Z
edLd            ZedMd            ZedNd            ZedOd#            ZedPd&            ZedQd(            ZedRd*            ZedSd,            ZedTd-            ZedUd.            ZedVd0            ZedTd1            ZedWdXd3            ZdYd4ZdZd5ZdYd6Zd[d9ZdZd:ZedYd;            ZedYd<            Zd\d=Z e!e!e!d>d]dDZ"d^dEZ#d_dFZ$d`dGZ%dHS )ar   a  Represents a CDN asset on Discord.

    .. container:: operations

        .. describe:: str(x)

            Returns the URL of the CDN asset.

        .. describe:: len(x)

            Returns the length of the CDN asset's URL.

        .. describe:: x == y

            Checks if the asset is equal to another asset.

        .. describe:: x != y

            Checks if the asset is not equal to another asset.

        .. describe:: hash(x)

            Returns the hash of the asset.
    r   _url	_animated_keyzTuple[str, ...]rH   zhttps://cdn.discordapp.comF)animatedstate_Stater   r   keyrO   r*   r   Nonec               >    || _         || _        || _        || _        d S NrK   )r#   rP   r   rR   rO   s        r$   __init__zAsset.__init__   s"    #	'			r&   indexr+   r   c                P     | || j          d| dt          |          d          S )Nz/embed/avatars/.pngFr   rR   rO   BASEr   )clsrP   rW   s      r$   _from_default_avatarzAsset._from_default_avatar   s@    s877E777E

	
 
 
 	
r&   user_idavatarc                x    |                     d          }|rdnd} | || j         d| d| d| d||          S )	Na_r   r   	/avatars//.
?size=1024rZ   
startswithr\   )r]   rP   r_   r`   rO   formats         r$   _from_avatarzAsset._from_avatar   sk    $$T**"-s8KKgKKKKKKK	
 
 
 	
r&   guild_id	member_idc                ~    |                     d          }|rdnd} | || j         d| d| d| d| d
||	          S )
Nrb   r   r   /guilds//users/rc   re   rf   rZ   rg   )r]   rP   rk   rl   r`   rO   ri   s          r$   _from_guild_avatarzAsset._from_guild_avatar   t    $$T**"-s8eeXeeiee&eeSYeee	
 
 
 	
r&   bannerc                ~    |                     d          }|rdnd} | || j         d| d| d| d| d
||	          S )
Nrb   r   r   rn   ro   	/banners/re   rf   rZ   rg   )r]   rP   rk   rl   rr   rO   ri   s          r$   _from_guild_bannerzAsset._from_guild_banner   rq   r&   avatar_decorationc                6     | || j          d| d|d          S )Nz/avatar-decoration-presets/z.png?size=96TrZ   r\   )r]   rP   rv   s      r$   _from_avatar_decorationzAsset._from_avatar_decoration  s;    s8WW8IWWW!	
 
 
 	
r&   	object_id	icon_hashpathc                B     | || j          d| d| d| d|d          S )Nrd   z-icons/.png?size=1024FrZ   rx   )r]   rP   rz   r{   r|   s        r$   
_from_iconzAsset._from_icon  sJ    s8PPdPP9PPyPPP	
 
 
 	
r&   
asset_typeLiteral['icon', 'cover_image']c           	     <     | || j          d| d| d|d          S )Nz/app-icons/rd   r~   FrZ   rx   )r]   rP   rz   r{   r   s        r$   _from_app_iconzAsset._from_app_icon  sD     s8NN	NNJNNN	
 
 
 	
r&   cover_image_hashc           	     <     | || j          d| d| d|d          S )Nz/app-assets/z/store/r~   FrZ   rx   )r]   rP   rz   r   s       r$   _from_cover_imagezAsset._from_cover_image!  sC    s8[[[[;K[[[ 	
 
 
 	
r&   scheduled_event_idc           	     <     | || j          d| d| d|d          S )Nz/guild-events/rd   r~   FrZ   rx   )r]   rP   r   r   s       r$   !_from_scheduled_event_cover_imagez'Asset._from_scheduled_event_cover_image*  sD    s8``+=``@P``` 	
 
 
 	
r&   imagec                ~    |                     d          }|rdnd} | || j         d| d| d| d| d
||          S )Nrb   r   r   rd   re   rf   rZ   rg   )r]   rP   rk   r   r|   rO   ri   s          r$   _from_guild_imagezAsset._from_guild_image3  ss    ##D))"-s8JJdJJXJJJJJJJ	
 
 
 	
r&   c                x    |                     d          }|rdnd} | || j         d| d| d| d||          S )	Nrb   r   r   z/icons/rd   re   rf   rZ   rg   )r]   rP   rk   r{   rO   ri   s         r$   _from_guild_iconzAsset._from_guild_icon>  sk    ''--"-s8MMHMMyMM6MMM	
 
 
 	
r&   c                P     | || j          d| dt          |          d          S )Nz%/app-assets/710982414301790216/store/rY   FrZ   r[   )r]   rP   rr   s      r$   _from_sticker_bannerzAsset._from_sticker_bannerI  s@    s8NN&NNNF	
 
 
 	
r&   banner_hashc                x    |                     d          }|rdnd} | || j         d| d| d| d||          S )	Nrb   r   r   rt   rd   re   z	?size=512rZ   rg   )r]   rP   r_   r   rO   ri   s         r$   _from_user_bannerzAsset._from_user_bannerR  sk    ))$//"-s8OOgOOOOfOOO	
 
 
 	
r&   c           	     <     | || j          d| d| d|d          S )Nz/guild-tag-badges/rd   z.png?size=64FrZ   rx   )r]   rP   rk   r{   s       r$   _from_primary_guildzAsset._from_primary_guild]  sB    s8QQxQQ)QQQ	
 
 
 	
r&   assetc                D    |sdnd} | || j          d| | ||          S )Nz
static.pngz
asset.webmz/assets/collectibles/rZ   rx   )r]   rP   r   rO   rA   s        r$   _from_user_collectiblezAsset._from_user_collectiblef  sJ    #+=||s8??%???	
 
 
 	
r&   c                    | j         S rU   rL   r"   s    r$   __str__zAsset.__str__p  s
    yr&   c                *    t          | j                  S rU   )lenrL   r"   s    r$   __len__zAsset.__len__s  s    49~~r&   c                N    | j                             | j        d          }d|dS )N z<Asset url=>)rL   replacer\   )r#   shortens     r$   __repr__zAsset.__repr__v  s,    )##DIr22)W))))r&   otherobjectc                L    t          |t                    o| j        |j        k    S rU   )r.   r   rL   )r#   r   s     r$   __eq__zAsset.__eq__z  s     %''CDI,CCr&   c                *    t          | j                  S rU   )hashrL   r"   s    r$   __hash__zAsset.__hash__}  s    DIr&   c                    | j         S )z6:class:`str`: Returns the underlying URL of the asset.r   r"   s    r$   r   z	Asset.url       yr&   c                    | j         S )z7:class:`str`: Returns the identifying key of the asset.)rN   r"   s    r$   rR   z	Asset.key  r   r&   c                    | j         S )z5:class:`bool`: Returns whether the asset is animated.)rM   r"   s    r$   is_animatedzAsset.is_animated  s
    ~r&   )sizeri   static_formatr   ri   ValidAssetFormatTypesr   ValidStaticFormatTypesc               &   t          j        | j                  }t          j                            |j                  \  }}|t          urk| j        r!|t          vrt          dt                     n)|t          u r |t          vrt          dt                     |                    | d|           }|t          urA| j        s:|t          vrt          dt                     |                    | d|           }|t          ur:t          j        |          st          d          |                    |          }n|                    |j                  }t!          |          }|                     | j        || j        | j                  S )a  Returns a new asset with the passed components replaced.


        .. versionchanged:: 2.0
            ``static_format`` is now preferred over ``format``
            if both are present and the asset is not animated.

        .. versionchanged:: 2.0
            This function will now raise :exc:`ValueError` instead of
            ``InvalidArgument``.

        Parameters
        -----------
        size: :class:`int`
            The new size of the asset.
        format: :class:`str`
            The new format to change it to. Must be either
            'webp', 'jpeg', 'jpg', 'png', or 'gif' if it's animated.
        static_format: :class:`str`
            The new format to change it to if the asset isn't animated.
            Must be either 'webp', 'jpeg', 'jpg', or 'png'.

        Raises
        -------
        ValueError
            An invalid size or format was passed.

        Returns
        --------
        :class:`Asset`
            The newly updated asset.
        format must be one of re   zstatic_format must be one of -size must be a power of 2 between 16 and 4096r   rP   r   rR   rO   )r?   r@   rL   osr|   splitextr>   rM   VALID_ASSET_FORMATS
ValueErrorVALID_STATIC_FORMATS	with_pathr   valid_icon_size
with_queryraw_query_stringr   	__class__r   rN   )r#   r   ri   r   r   r|   _s          r$   r   zAsset.replace  s   N hty!!'""38,,a  ~ V!444$%S>Q%S%STTT 5 !G++>R0R0R$%T>R%T%TUUU--4 2 2& 2 233C'''$888 !WAU!W!WXXX--4 9 9- 9 9::Cw(.. R !PQQQ..d.++CC..!566C#hh~~DKSdiRVR`~aaar&   c                  t          j        |          st          d          t          t	          j        | j                                      |                    }|                     | j	        || j
        | j                  S )a  Returns a new asset with the specified size.

        .. versionchanged:: 2.0
            This function will now raise :exc:`ValueError` instead of
            ``InvalidArgument``.

        Parameters
        ------------
        size: :class:`int`
            The new size of the asset.

        Raises
        -------
        ValueError
            The asset had an invalid size.

        Returns
        --------
        :class:`Asset`
            The new updated asset.
        r   r   r   )r   r   r   r   r?   r@   rL   r   r   r   rN   rM   )r#   r   r   s      r$   	with_sizezAsset.with_size  ss    , $T** 	NLMMM$(49%%00d0;;<<~~DKSdiRVR`~aaar&   c                  | j         r!|t          vrt          dt                     n |t          vrt          dt                     t	          j        | j                  }t          j        	                    |j                  \  }}t          |                    | d|                               |j                            }|                     | j        || j        | j                   S )a  Returns a new asset with the specified format.

        .. versionchanged:: 2.0
            This function will now raise :exc:`ValueError` instead of
            ``InvalidArgument``.

        Parameters
        ------------
        format: :class:`str`
            The new format of the asset.

        Raises
        -------
        ValueError
            The asset had an invalid format.

        Returns
        --------
        :class:`Asset`
            The new updated asset.
        r   re   r   )rM   r   r   r   r?   r@   rL   r   r|   r   r   r   r   r   r   r   rN   )r#   ri   r   r|   r   s        r$   with_formatzAsset.with_format  s    . > 	R000 !O:M!O!OPPP 1 111 !P:N!P!PQQQhty!!'""38,,a#--4 2 2& 2 233>>s?STTUU~~DKSdiRVR`~aaar&   c               >    | j         r| S |                     |          S )at  Returns a new asset with the specified static format.

        This only changes the format if the underlying asset is
        not animated. Otherwise, the asset is not changed.

        .. versionchanged:: 2.0
            This function will now raise :exc:`ValueError` instead of
            ``InvalidArgument``.

        Parameters
        ------------
        format: :class:`str`
            The new static format of the asset.

        Raises
        -------
        ValueError
            The asset had an invalid format.

        Returns
        --------
        :class:`Asset`
            The new updated asset.
        )rM   r   )r#   ri   s     r$   with_static_formatzAsset.with_static_format  s'    4 > 	K'''r&   N)
rP   rQ   r   r   rR   r   rO   r*   r   rS   )rP   rQ   rW   r+   r   r   )rP   rQ   r_   r+   r`   r   r   r   )
rP   rQ   rk   r+   rl   r+   r`   r   r   r   )
rP   rQ   rk   r+   rl   r+   rr   r   r   r   )rP   rQ   rv   r   r   r   )
rP   rQ   rz   r+   r{   r   r|   r   r   r   )
rP   rQ   rz   r+   r{   r   r   r   r   r   )rP   rQ   rz   r+   r   r   r   r   )rP   rQ   r   r+   r   r   r   r   )
rP   rQ   rk   r+   r   r   r|   r   r   r   )rP   rQ   rk   r+   r{   r   r   r   )rP   rQ   rr   r+   r   r   )rP   rQ   r_   r+   r   r   r   r   )F)rP   rQ   r   r   rO   r*   r   r   )r   r   )r   r+   )r   r   r   r*   )r   r*   )r   r+   ri   r   r   r   r   r   )r   r+   r   r   )ri   r   r   r   )ri   r   r   r   )&rE   rF   rG   __doc__rH   rI   r\   rV   classmethodr^   rj   rp   ru   ry   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   propertyr   rR   r   r>   r   r   r   r   r   r&   r$   r   r      s         2"I     (DNS       
 
 
 [
 
 
 
 [
 
 
 
 [
 
 
 
 [
 
 
 
 [
 
 
 
 [
 
 
 
 [
 
 
 
 [
 
 
 
 [
 
 
 
 [
 
 
 
 [
 
 
 
 [
 
 
 
 [
 
 
 
 [
 
 
 
 
 [
      * * * *D D D D       X    X    (/07@b @b @b @b @b @bDb b b b8!b !b !b !bF( ( ( ( ( (r&   r   )#r   
__future__r   r/   r   typingr   r   r   r   r   r	   errorsr   r   r   filer   r?   __all__typing_extensionsr   rP   r   webhook.async_r   rQ   r   r   	frozensetr   r   r>   r   r   r   r&   r$   <module>r      s   0 # " " " " " 				 				 F F F F F F F F F F F F F F F F $ $ $ $ $ $             
  	I&&&&&&&&&&&&------?M12F$%AB#$GH y!?!?!?@@ *eW4  -rh rh rh rh rh rh rh rhjz( z( z( z( z(J z( z( z( z( z(r&   