
    cjh<$                        d 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
mZ dZerddlZdd	lmZ ddlmZ dd
lmZ  G d d      Z G d d      Z G d d      Zy)ae  
The MIT License (MIT)

Copyright (c) 2015-2021 Rapptz
Copyright (c) 2021-present Pycord Development

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.
    )annotations)TYPE_CHECKINGAny   )Guild)MISSING_bytes_to_base64_data
parse_time)TemplateN)ConnectionState)Userc                      e Zd ZdZd Zy)!_FriendlyHttpAttributeErrorHelper c                    t        d      )Nz3PartialTemplateState does not support http methods.AttributeErrorselfattrs     C/var/www/html/venv/lib/python3.12/site-packages/discord/template.py__getattr__z-_FriendlyHttpAttributeErrorHelper.__getattr__.   s    RSS    N)__name__
__module____qualname__	__slots__r   r   r   r   r   r   +   s    ITr   r   c                  x    e Zd Zd Zed        Zed        Zed        Zed        Zd Z	d Z
d Zd	 Zdd
Zd Zy)_PartialTemplateStatec               0    || _         t               | _        y N)_PartialTemplateState__stater   http)r   states     r   __init__z_PartialTemplateState.__init__3   s    57	r   c                .    | j                   j                  S r!   )r"   shard_countr   s    r   r'   z!_PartialTemplateState.shard_count7   s    ||'''r   c                .    | j                   j                  S r!   )r"   userr(   s    r   r*   z_PartialTemplateState.user;   s    ||   r   c                B    | j                   j                  j                  S r!   )r"   r*   idr(   s    r   self_idz_PartialTemplateState.self_id?   s    ||  ###r   c                .    | j                   j                  S r!   )r"   member_cache_flagsr(   s    r   r/   z(_PartialTemplateState.member_cache_flagsC   s    ||...r   c                     y r!   r   )r   guildpackets      r   store_emojiz!_PartialTemplateState.store_emojiG       r   c                     y r!   r   r   r,   s     r   _get_voice_clientz'_PartialTemplateState._get_voice_clientJ   r4   r   c                     y r!   r   r6   s     r   _get_messagez"_PartialTemplateState._get_messageM   r4   r   c                8    | j                   j                  |      S r!   )r"   
_get_guildr6   s     r   r;   z _PartialTemplateState._get_guildP   s    ||&&r**r   c                   K   g S wr!   r   )r   kwargss     r   query_membersz#_PartialTemplateState.query_membersS   s     	s   c                     t        d|d      )Nz&PartialTemplateState does not support .r   r   s     r   r   z!_PartialTemplateState.__getattr__V   s    EdXQOPPr   N)r=   r   )r   r   r   r%   propertyr'   r*   r-   r/   r3   r7   r9   r;   r>   r   r   r   r   r   r   2   sv    8 ( ( ! ! $ $ / /+Qr   r   c                  r    e Zd ZdZdZddZddZddZdddZddZ	e
e
d		 	 	 	 	 dd
ZddZedd       Zy)r   a  Represents a Discord template.

    .. versionadded:: 1.4

    Attributes
    ----------
    code: :class:`str`
        The template code.
    uses: :class:`int`
        How many times the template has been used.
    name: :class:`str`
        The name of the template.
    description: :class:`str`
        The description of the template.
    creator: :class:`User`
        The creator of the template.
    created_at: :class:`datetime.datetime`
        An aware datetime in UTC representing when the template was created.
    updated_at: :class:`datetime.datetime`
        An aware datetime in UTC representing when the template was last updated.
        This is referred to as "last synced" in the official Discord client.
    source_guild: :class:`Guild`
        The source guild.
    is_dirty: Optional[:class:`bool`]
        Whether the template has unsynced changes.

        .. versionadded:: 2.0
    )
codeusesnamedescriptioncreator
created_at
updated_atsource_guildis_dirty_statec               4    || _         | j                  |       y r!   )rL   _store)r   r$   datas      r   r%   zTemplate.__init__   s    Dr   c                6   |d   | _         |d   | _        |d   | _        |d   | _        |j	                  d      }|d n| j
                  j                  |      | _        t        |j	                  d            | _	        t        |j	                  d            | _
        t        |d         }| j
                  j                  |      }|  |3|d	   }||d
<   t        | j
                        }t        ||      | _        n|| _        |j	                  dd       | _        y )NrC   usage_countrE   rF   rG   rH   rI   source_guild_idserialized_source_guildr,   )r$   rO   r$   rK   )rC   rD   rE   rF   getrL   create_userrG   r
   rH   rI   intr;   r   r   rJ   rK   )r   rO   creator_dataguild_idr1   source_serialisedr$   s          r   rN   zTemplate._store   s   f	m,	f	'+M':xx	* (Ddkk.E.El.S 	 5?txx?U4V4>txx?U4Vt-./"kk44X>= $%> ?&.d#)<E %+<E JD %D%)XXj$%?r   c                    d| j                   d| j                   d| j                  d| j                  d| j                  d| j
                   dS )Nz<Template code=z uses=z name=z	 creator=z source_guild=z
 is_dirty=>)rC   rD   rE   rG   rJ   rK   r(   s    r   __repr__zTemplate.__repr__   sV    dii]&6$))'~d6G6G5J*UYUbUbTccdf	
r   Nc                   K   |t        |      }| j                  j                  j                  | j                  ||       d{   }t        || j                        S 7 w)a  |coro|

        Creates a :class:`.Guild` using the template.

        Bot accounts in more than 10 guilds are not allowed to create guilds.

        Parameters
        ----------
        name: :class:`str`
            The name of the guild.
        icon: :class:`bytes`
            The :term:`py:bytes-like object` representing the icon. See :meth:`.ClientUser.edit`
            for more details on what is expected.

        Returns
        -------
        :class:`.Guild`
            The guild created. This is not the same guild that is
            added to cache.

        Raises
        ------
        HTTPException
            Guild creation failed.
        InvalidArgument
            Invalid icon image format given. Must be PNG or JPG.
        NrT   )r	   rL   r#   create_from_templaterC   r   )r   rE   iconrO   s       r   create_guildzTemplate.create_guild   sT     8 (.D[[%%::499dDQQ$dkk22 Rs   AA"A A"c                   K   | j                   j                  j                  | j                  j                  | j
                         d{   }t        | j                   |      S 7 w)a  |coro|

        Sync the template to the guild's current state.

        You must have the :attr:`~Permissions.manage_guild` permission in the
        source guild to do this.

        .. versionadded:: 1.7

        .. versionchanged:: 2.0
            The template is no longer synced in-place, instead it is returned.

        Returns
        -------
        :class:`Template`
            The newly synced template.

        Raises
        ------
        HTTPException
            Syncing the template failed.
        Forbidden
            You don't have permissions to sync the template.
        NotFound
            This template does not exist.
        Nr$   rO   )rL   r#   sync_templaterJ   r,   rC   r   )r   rO   s     r   synczTemplate.sync   sN     8 [[%%33D4E4E4H4H$))TTdkk55 Us   AA(
A&A()rE   rF   c                 K   i }|t         ur||d<   |t         ur||d<   | j                  j                  j                  | j                  j
                  | j                  |       d{   }t        | j                  |      S 7 w)a<  |coro|

        Edit the template metadata.

        You must have the :attr:`~Permissions.manage_guild` permission in the
        source guild to do this.

        .. versionadded:: 1.7

        .. versionchanged:: 2.0
            The template is no longer edited in-place, instead it is returned.

        Parameters
        ----------
        name: :class:`str`
            The template's new name.
        description: Optional[:class:`str`]
            The template's new description.

        Returns
        -------
        :class:`Template`
            The newly edited template.

        Raises
        ------
        HTTPException
            Editing the template failed.
        Forbidden
            You don't have permissions to edit the template.
        NotFound
            This template does not exist.
        rE   rF   Nrc   )r   rL   r#   edit_templaterJ   r,   rC   r   )r   rE   rF   payloadrO   s        r   editzTemplate.edit   s     N w"GFOg%%0GM"[[%%33  $))W
 
 dkk55
s   A%B'B(Bc                   K   | j                   j                  j                  | j                  j                  | j
                         d{    y7 w)a  |coro|

        Delete the template.

        You must have the :attr:`~Permissions.manage_guild` permission in the
        source guild to do this.

        .. versionadded:: 1.7

        Raises
        ------
        HTTPException
            Deleting the template failed.
        Forbidden
            You don't have permissions to delete the template.
        NotFound
            This template does not exist.
        N)rL   r#   delete_templaterJ   r,   rC   r(   s    r   deletezTemplate.delete  s8     & kk..t/@/@/C/CTYYOOOs   AA
AAc                     d| j                    S )z9The template url.

        .. versionadded:: 2.0
        zhttps://discord.new/)rC   r(   s    r   urlzTemplate.url4  s     &dii[11r   )r$   r   rO   TemplatePayloadreturnNone)rO   ro   rp   rq   )rp   strr!   )rE   rr   r`   r   rp   r   )rp   r   )rE   rr   rF   z
str | Nonerp   r   )rp   rq   )r   r   r   __doc__r   r%   rN   r]   ra   re   r   ri   rl   rA   rn   r   r   r   r   r   Z   sp    :I@8
 3D6D ")	16 16  	16
 
16fP* 2 2r   r   )rs   
__future__r   typingr   r   r1   r   utilsr   r	   r
   __all__datetimer$   r   types.templater   ro   r*   r   r   r   r   r   r   <module>rz      sT   2 # %  = =
&;T T%Q %QP`2 `2r   