
    i                       U d Z ddlmZ ddlZddlZddlZddlZddlZddlm	Z
 ddlmZmZmZmZmZmZmZmZmZmZmZmZ ddlZddlmZ ddlmZ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'm(Z( ddl)m*Z*m+Z+ dZ, ej-        e.          Z/ertddl0m1Z1 ddl2m3Z3 ddl4m5Z5 ddl6m7Z7 ddl8m9Z9 ddl:m;Z; ddl m<Z< ddl=m>Z> ddl?m@Z@ ddlAmBZBmCZCmDZD ddlEmFZG ddlHm!ZI ddlJmKZK  edeL          ZM	 ddlNmOZOmPZP n# eQ$ r Y nw xY wejR        ZRdeSd <    G d! d"          ZT G d# d$          ZU G d% d&ejV                  ZW eW            ZXd-d(ZY G d) d*e!          ZZ 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)quote)AnyDictListLiteralOptionalTYPE_CHECKINGSequenceTupleUnionTypeVarTypeoverload   )utils)HTTPException	ForbiddenNotFoundDiscordServerError)MessageMessageFlags)Routehandle_message_parameters)PartialMessageableForumTag   )BaseWebhook_WebhookState)SyncWebhookSyncWebhookMessage)Self)TracebackType)File)Embed)Poll)AllowedMentions)
Attachment)	Snowflake)ConnectionState)BaseViewView
LayoutView)Webhook)r   )SnowflakeListBE)bound)SessionResponser   MISSINGc                  .    e Zd ZddZddZdd
ZddZdS )DeferredLocklockthreading.LockreturnNonec                "    || _         d | _        d S N)r7   delta)selfr7   s     U/usr/local/lib/hermes-agent/venv/lib/python3.11/site-packages/discord/webhook/sync.py__init__zDeferredLock.__init__Y   s    $(	&*


    r"   c                8    | j                                          | S r<   )r7   acquirer>   s    r?   	__enter__zDeferredLock.__enter__]   s    	rA   r=   floatc                    || _         d S r<   )r=   )r>   r=   s     r?   delay_byzDeferredLock.delay_bya   s    


rA   exc_typeOptional[Type[BE]]excOptional[BE]	tracebackOptional[TracebackType]c                x    | j         rt          j        | j                    | j                                         d S r<   )r=   timesleepr7   release)r>   rI   rK   rM   s       r?   __exit__zDeferredLock.__exit__d   s:     : 	#Jtz"""	rA   N)r7   r8   r9   r:   )r9   r"   )r=   rF   r9   r:   )rI   rJ   rK   rL   rM   rN   r9   r:   )__name__
__module____qualname__r@   rE   rH   rS    rA   r?   r6   r6   X   sd        + + + +           rA   r6   c                      e Zd Zd Zdddddddd3dZdddd4dZddd5dZddd6d Zddd6d!Zddddd"d"d#d7d*Z	dd+d8d-Z
ddddd"d.d9d/Zdd+d:d0Zd;d1Zd;d2ZdS )<WebhookAdapterc                6    t          j                    | _        d S r<   )weakrefWeakValueDictionary_locksrD   s    r?   r@   zWebhookAdapter.__init__p   s    HOHcHeHerA   N)payload	multipartfilesreason
auth_tokenparamsrouter   sessionr2   r^   Optional[Dict[str, Any]]r_   Optional[List[Dict[str, Any]]]r`   Optional[Sequence[File]]ra   Optional[str]rb   rc   r9   r   c          
        i }	|pg }d }
|j         |j        f}	 | j        |         }n-# t          $ r  t	          j                    x| j        |<   }Y nw xY w|,d|	d<   t          j        |                              d          }
|d| |	d<   |t          |d          |	d<   d }d }d }|j
        }|j        }|j         }t          |          5 }t          d	          D ]}|D ]}|                    |
           |r:i }|D ]5}|d         }|dk    rd|d         i}
|d         |d         |d         f||<   6	 |                    |||
||	|          5 }t                               d||||j                   d|_        |j        |_        |j        pd }	 |r%|j        d         dk    rt/          j        |          }n# t          $ r Y nw xY w|j                            d          }|dk    rP|j        dk    rEt          j        |          }t                               d||           |                    |           d|j        cxk    rdk    rn n|cd d d            c cd d d            S |j        dk    rr|j                            d          st9          ||          d}|d         }t                               |||           t=          j        |           	 d d d            |j        dk    r(t=          j        d|dz  z              	 d d d            @|j        dk    rtA          ||          |j        d k    rtC          ||          t9          ||          # 1 swxY w Y   # tD          $ r5}|d!k     r)|j#        d"v r t=          j        d|dz  z              Y d }~̂ d }~ww xY w|r+|j        dk    rtI          ||          t9          ||          tK          d#          # 1 swxY w Y   d S )$Nzapplication/json; charset=utf-8zContent-Typezutf-8zBot Authorizationz/ )safezX-Audit-Log-Reason   )seeknamepayload_jsonvaluefilenamecontent_type)datar`   headersrc   z4Webhook ID %s with %s %s has returned status code %szapplication/jsonzX-Ratelimit-Remaining0i  z>Webhook ID %s has exhausted its rate limit bucket (retry: %s).i,     Viaz8Webhook ID %s is rate limited. Retrying in %.2f seconds.retry_afteri  r   r   i  i     )6   iF'  z"Unreachable code in HTTP handling.)&
webhook_idwebhook_tokenr]   KeyError	threadingLockr   _to_jsonencodeurlquotemethodurlr6   rangeresetrequest_logdebugstatus_codeencodingstatustextru   jsonloadsget_parse_ratelimit_headerrH   r   warningrP   rQ   r   r   OSErrorerrnor   RuntimeError)r>   rd   re   r^   r_   r`   ra   rb   rc   ru   to_sendbucketr7   responsert   	file_datar   r   r|   attemptfilepro   	remainingr=   fmtry   es                               r?   r   zWebhookAdapter.requests   s    #%?C"E$78	:;v&DD 	: 	: 	:)2)9)99DK$$$	: &GGN#nW--44W==G!':j':':GO$,4V$,G,G,GG()'+59.2	i%
$ Q	E4 88 I I! - -DJJGJ,,,, ] "I& ] ] y>11'5qz&BGG/0}aj!NJ[.\IdOO< 'G\b )   5@!

R&"$0   -4)*2*>'}4!# 8(8(HL^(^(^'+z$'7'7' ! ! ! D! %-$4$8$89P$Q$Q	$++0D0K0K$)$A($K$KE JJ ` * %  
 !MM%000!5<<<<<<<<<#'A5@ 5@ 5@ 5@ 5@ 5@ 5@ 5@ 5@Q	E Q	E Q	E Q	E Q	E Q	E Q	E Q	Eb $/366#+#3#7#7#>#> D&3Hd&C&C C"\C15m1DK LLj+FFF J{333$U5@ 5@ 5@ 5@ 5@ 5@ 5@X $/366 Jq7Q;777$]5@ 5@ 5@ 5@ 5@ 5@ 5@` $/366"+Hd";";;%1S88"*8T":"::"/$"?"??k5@ 5@ 5@ 5@ 5@ 5@ 5@ 5@ 5@n    {{qw+'='=
1w{?333 	  4'3..,Xt<<<#Hd333CDDDcQ	E Q	E Q	E Q	E Q	E Q	E Q	E Q	E Q	E Q	Es   & 'AAA*O,6M.A M!'F:9M!:
G	M!G	B	M!M.O,+A0M!M.&O,(&M!M.O,AM!!M%%M.(M%)M.,O,.
N-8)N(!O,'N((N--?O,,O03O0)tokenra   r|   intr   r:   c               X    t          dd|          }|                     ||||          S )NDELETE/webhooks/{webhook_id}r|   )ra   rb   r   r   r>   r|   r   re   ra   rd   s         r?   delete_webhookzWebhookAdapter.delete_webhook   s3     h 8ZPPP||E76e|LLLrA   ra   strc               X    t          dd||          }|                     |||          S )Nr   &/webhooks/{webhook_id}/{webhook_token}r|   r}   r   r   r   s         r?   delete_webhook_with_tokenz(WebhookAdapter.delete_webhook_with_token   s5     h HU_otuuu||E76|:::rA   Dict[str, Any]WebhookPayloadc               Z    t          dd|          }|                     |||||          S )NPATCHr   r   )ra   r^   rb   r   r>   r|   r   r^   re   ra   rd   s          r?   edit_webhookzWebhookAdapter.edit_webhook  s6     g7JOOO||E767W\|]]]rA   c               Z    t          dd||          }|                     ||||          S )Nr   r   r   )ra   r^   r   r   s          r?   edit_webhook_with_tokenz&WebhookAdapter.edit_webhook_with_token  s7     gGT^nsttt||E767|KKKrA   F)r^   r_   r`   	thread_idwaitwith_componentsr   Optional[int]r   boolr   MessagePayloadc                   t          |          t          |	          d}
|r||
d<   t          dd||          }|                     ||||||
          S )N)r   r   r   POSTr   r   r^   r_   r`   rc   )r   r   r   )r>   r|   r   re   r^   r_   r`   r   r   r   rc   rd   s               r?   execute_webhookzWebhookAdapter.execute_webhook  sj     d))O8L8LMM 	,"+F;fFS]mrsss||E7GyX]fl|mmmrA   )r   
message_idc               j    t          dd|||          }|d nd|i}|                     |||          S )NGET</webhooks/{webhook_id}/{webhook_token}/messages/{message_id}r|   r}   r   r   rc   r   r>   r|   r   r   re   r   rd   rc   s           r?   get_webhook_messagez"WebhookAdapter.get_webhook_message.  sT     J!!
 
 
 #*i0H||E76|:::rA   )r^   r_   r`   r   r   c                   t          dd|||          }
dt          |	          i}|r||d<   |                     |
|||||          S )Nr   r   r   r   r   r   )r   r   r   )r>   r|   r   r   re   r^   r_   r`   r   r   rd   rc   s               r?   edit_webhook_messagez#WebhookAdapter.edit_webhook_messageA  sm     J!!
 
 
 $S%9%9: 	,"+F;||E7GyX]fl|mmmrA   c               j    t          dd|||          }|d nd|i}|                     |||          S )Nr   r   r   r   r   r   r   s           r?   delete_webhook_messagez%WebhookAdapter.delete_webhook_messageZ  sT     J!!
 
 
 #*i0H||E76|:::rA   c               V    t          dd|          }|                     |||          S )Nr   r   r   )re   rb   r   r>   r|   r   re   rd   s        r?   fetch_webhookzWebhookAdapter.fetch_webhookm  s1     e5*MMM||E7u|EEErA   c               V    t          dd||          }|                     ||          S )Nr   r   r   re   r   r   s        r?   fetch_webhook_with_tokenz'WebhookAdapter.fetch_webhook_with_tokenw  s3     eER\lqrrr||E7|333rA   )rd   r   re   r2   r^   rf   r_   rg   r`   rh   ra   ri   rb   ri   rc   rf   r9   r   )
r|   r   r   ri   re   r2   ra   ri   r9   r:   )
r|   r   r   r   re   r2   ra   ri   r9   r:   )r|   r   r   r   r^   r   re   r2   ra   ri   r9   r   )r|   r   r   r   re   r2   r^   rf   r_   rg   r`   rh   r   r   r   r   r   r   r9   r   )r|   r   r   r   r   r   re   r2   r   r   r9   r   )r|   r   r   r   r   r   re   r2   r^   rf   r_   rg   r`   rh   r   r   r   r   r9   r   )r|   r   r   r   r   r   re   r2   r   r   r9   r:   )r|   r   r   r   re   r2   r9   r   )rT   rU   rV   r@   r   r   r   r   r   r   r   r   r   r   r   rW   rA   r?   rY   rY   o   s       f f f -148*. $$(+/xE xE xE xE xE xE|  $ $	M 	M 	M 	M 	M 	M" !%	; 	; 	; 	; 	; 	;$ !%
^ 
^ 
^ 
^ 
^ 
^& !%
L 
L 
L 
L 
L 
L$ -148*.#' %n n n n n n4 $(; ; ; ; ; ;4 -148*.#' %n n n n n n@ $(; ; ; ; ; ;&F F F F4 4 4 4 4 4rA   rY   c                      e Zd ZU dZded<   dS )_WebhookContextNzOptional[WebhookAdapter]adapter)rT   rU   rV   r   __annotations__rW   rA   r?   r   r     s#         (,G,,,,,,rA   r   r9   c                 b    t           j        t                      t           _        t           j        S r<   )_contextr   rY   rW   rA   r?   _get_webhook_adapterr     s"    )++rA   c                  T    e Zd ZU dZded<   eeeededddZddZd dZddd!dZ	dS )"r!   a  Represents a message sent from your webhook.

    This allows you to edit or delete a message sent by your
    webhook.

    This inherits from :class:`discord.Message` with changes to
    :meth:`edit` and :meth:`delete` to work.

    .. versionadded:: 2.0
    r   _stateN)contentembedsembedattachmentsallowed_mentionsviewr   ri   r   Sequence[Embed]r   Optional[Embed]r   !Sequence[Union[Attachment, File]]r   Optional[AllowedMentions]r   Optional[BaseView]r9   c          
     n    | j         j                            | j        |||||| j         j        |          S )a=	  Edits the message.

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

        Parameters
        ------------
        content: Optional[:class:`str`]
            The content to edit the message with or ``None`` to clear it.
        embeds: List[:class:`Embed`]
            A list of embeds to edit the message with.
        embed: Optional[:class:`Embed`]
            The embed to edit the message with. ``None`` suppresses the embeds.
            This should not be mixed with the ``embeds`` parameter.
        attachments: List[Union[:class:`Attachment`, :class:`File`]]
            A list of attachments to keep in the message as well as new files to upload. If ``[]`` is passed
            then all attachments are removed.

            .. note::

                New files will always appear after current attachments.

            .. versionadded:: 2.0
        allowed_mentions: :class:`AllowedMentions`
            Controls the mentions being processed in this message.
            See :meth:`.abc.Messageable.send` for more information.
        view: Union[:class:`discord.ui.View`, :class:`discord.ui.LayoutView`]
            The updated view to update this message with. This can only have non-interactible items, which do not
            require a state to be attached to it. If ``None`` is passed then the view is removed.

            If you want to edit a webhook message with any component attached to it, check :meth:`WebhookMessage.edit`.

            .. note::

                To update the message to add a :class:`~discord.ui.LayoutView`, you
                must explicitly set the ``content``, ``embed``, ``embeds``, and
                ``attachments`` parameters to either ``None`` or an empty array, as appropriate.

            .. versionadded:: 2.7

        Raises
        -------
        HTTPException
            Editing the message failed.
        Forbidden
            Edited a message that is not yours.
        TypeError
            You specified both ``embed`` and ``embeds``.
        ValueError
            The length of ``embeds`` was invalid or
            there was no token associated with this webhook.

        Returns
        --------
        :class:`SyncWebhookMessage`
            The newly edited message.
        )r   r   r   r   r   threadr   )r   _webhookedit_messageid_thread)r>   r   r   r   r   r   r   s          r?   editzSyncWebhookMessage.edit  sF    H {#00G#-;& 1 	
 	
 		
rA   r`   r$   c                @    |                      g | j        |          S )a  Adds new files to the end of the message attachments.

        .. versionadded:: 2.0

        Parameters
        -----------
        \*files: :class:`File`
            New files to add to the message.

        Raises
        -------
        HTTPException
            Editing the message failed.
        Forbidden
            Tried to edit a message that isn't yours.

        Returns
        --------
        :class:`SyncWebhookMessage`
            The newly edited message.
        r   r   r   )r>   r`   s     r?   	add_fileszSyncWebhookMessage.add_files  s&    , yy%@t'7%@%%@yAAArA   r(   c                R    |                      fd| j        D                       S )a  Removes attachments from the message.

        .. versionadded:: 2.0

        Parameters
        -----------
        \*attachments: :class:`Attachment`
            Attachments to remove from the message.

        Raises
        -------
        HTTPException
            Editing the message failed.
        Forbidden
            Tried to edit a message that isn't yours.

        Returns
        --------
        :class:`SyncWebhookMessage`
            The newly edited message.
        c                    g | ]}|v|	S rW   rW   ).0ar   s     r?   
<listcomp>z9SyncWebhookMessage.remove_attachments.<locals>.<listcomp>  s#    %Z%Z%ZAQkEYEYaEYEYEYrA   r   r   )r>   r   s    `r?   remove_attachmentsz%SyncWebhookMessage.remove_attachments  s1    , yy%Z%Z%Z%Z1A%Z%Z%Zy[[[rA   )delayr   Optional[float]r:   c                   |t          j        |           | j        j                            | j        | j        j                   dS )a  Deletes the message.

        Parameters
        -----------
        delay: Optional[:class:`float`]
            If provided, the number of seconds to wait before deleting the message.
            This blocks the thread.

        Raises
        ------
        Forbidden
            You do not have proper permissions to delete the message.
        NotFound
            The message was deleted already.
        HTTPException
            Deleting the message failed.
        Nr   )rP   rQ   r   r   delete_messager   r   )r>   r   s     r?   deletezSyncWebhookMessage.delete  sE    & Ju++DGDK<O+PPPPPrA   )r   ri   r   r   r   r   r   r   r   r   r   r   r9   r!   )r`   r$   r9   r!   )r   r(   r9   r!   )r   r   r9   r:   )
rT   rU   rV   __doc__r   r4   r   r   r   r   rW   rA   r?   r!   r!     s         	 	 
 ")")!(9@6:#*M
 M
 M
 M
 M
 M
^B B B B0\ \ \ \0 26 Q Q Q Q Q Q Q QrA   r!   c                  n    e Zd ZU dZdZded<   	 	 dgdh fdZdidZedid            Z	e
edddjd            Ze
edddkd            ZdddldZddd dmd"Zdeeddd#dnd)Zed*dod/Zeeeeeeeeeeed0
dpdC            ZeeeeeedDeeeeedEdqdG            ZeefeeeeeeeeeeeeeeedHdrdR            ZeefeeeeeeeeeedDeeeeedSdsdT            ZefeedUeeeeeeedUdUdUeeedSdtdXZed*dudYZedDdDdDdZdvd_            ZedDdDdDdDdDdDdDd`dwdc            Zeeeeeded`dxdeZed*dydfZ xZS )zr    ah  Represents a synchronous Discord webhook.

    For an asynchronous counterpart, see :class:`Webhook`.

    .. container:: operations

        .. describe:: x == y

            Checks if two webhooks are equal.

        .. describe:: x != y

            Checks if two webhooks are not equal.

        .. describe:: hash(x)

            Returns the webhooks's hash.

    .. versionchanged:: 1.4
        Webhooks are now comparable and hashable.

    Attributes
    ------------
    id: :class:`int`
        The webhook's ID
    type: :class:`WebhookType`
        The type of the webhook.

        .. versionadded:: 1.3

    token: Optional[:class:`str`]
        The authentication token of the webhook. If this is ``None``
        then the webhook cannot be used to make requests.
    guild_id: Optional[:class:`int`]
        The guild ID this webhook is for.
    channel_id: Optional[:class:`int`]
        The channel ID this webhook is for.
    user: Optional[:class:`abc.User`]
        The user this webhook was created by. If the webhook was
        received without authentication then this will be ``None``.
    name: Optional[:class:`str`]
        The default name of the webhook.
    source_guild: Optional[:class:`PartialWebhookGuild`]
        The guild of the channel that this webhook is following.
        Only given if :attr:`type` is :attr:`WebhookType.channel_follower`.

        .. versionadded:: 2.0

    source_channel: Optional[:class:`PartialWebhookChannel`]
        The channel that this webhook is following.
        Only given if :attr:`type` is :attr:`WebhookType.channel_follower`.

        .. versionadded:: 2.0
    r   zTuple[str, ...]	__slots__Nrt   r   re   r2   r   ri   state/Optional[Union[ConnectionState, _WebhookState]]r9   r:   c                \    t                                          |||           || _        d S r<   )superr@   re   )r>   rt   re   r   r  	__class__s        r?   r@   zSyncWebhook.__init__n  s,     	ue,,, 'rA   r   c                8    d| j         d| j        d| j        dS )Nz<Webhook id=z type=z name=>)r   typero   rD   s    r?   __repr__zSyncWebhook.__repr__x  s)    PdgPPtyPP$)PPPPrA   c                &    d| j          d| j         S )z):class:`str` : Returns the webhook's url.z!https://discord.com/api/webhooks//)r   r   rD   s    r?   r   zSyncWebhook.url{  s     J47IITZIIIrA   )re   	bot_tokenr   r   r  c                   |d|d}ddl }|t          ur2t          ||j                  st	          d|j        j                   n|} | |||          S )ae  Creates a partial :class:`Webhook`.

        Parameters
        -----------
        id: :class:`int`
            The ID of the webhook.
        token: :class:`str`
            The authentication token of the webhook.
        session: :class:`requests.Session`
            The session to use to send requests with. Note
            that the library does not manage the session and
            will not close it. If not given, the ``requests``
            auto session creation functions are used instead.
        bot_token: Optional[:class:`str`]
            The bot authentication token for authenticated requests
            involving the webhook.

        Returns
        --------
        :class:`SyncWebhook`
            A partial :class:`SyncWebhook`.
            A partial :class:`SyncWebhook` is just a :class:`SyncWebhook` object with an ID and a token.
        r   )r   r	  r   r   Nexpected requests.Session not r   )requestsr4   
isinstancer2   	TypeErrorr  rT   )clsr   r   re   r  rt   r  s          r?   partialzSyncWebhook.partial  s    4  
  

 	'!!gx'788 _ ]ARA[ ] ]^^^_ Gs4	2222rA   r   c                  t          j        d|          }|t          d          |                                }d|d<   ddl}|t
          ur2t          ||j                  st          d|j	        j
                   n|} | |||          S )	a}  Creates a partial :class:`Webhook` from a webhook URL.

        Parameters
        ------------
        url: :class:`str`
            The URL of the webhook.
        session: :class:`requests.Session`
            The session to use to send requests with. Note
            that the library does not manage the session and
            will not close it. If not given, the ``requests``
            auto session creation functions are used instead.
        bot_token: Optional[:class:`str`]
            The bot authentication token for authenticated requests
            involving the webhook.

        Raises
        -------
        ValueError
            The URL is invalid.

        Returns
        --------
        :class:`SyncWebhook`
            A partial :class:`SyncWebhook`.
            A partial :class:`SyncWebhook` is just a :class:`SyncWebhook` object with an ID and a token.
        zXdiscord(?:app)?\.com/api/webhooks/(?P<id>[0-9]{17,20})/(?P<token>[A-Za-z0-9\.\-\_]{60,})NzInvalid webhook URL given.r   r	  r   r  r  )research
ValueError	groupdictr  r4   r  r2   r  r  rT   )r  r   re   r  mrt   r  s          r?   from_urlzSyncWebhook.from_url  s    8 Iqsvww99::: {{}}V'!!gx'788 _ ]ARA[ ] ]^^^_ Gs4	2222rA   T)prefer_authr  r   c               @   t                      }|r/| j        r(|                    | j        | j        | j                  }n>| j        r(|                    | j        | j        | j                  }nt          d          t          || j        | j        | j	                  S )aZ  Fetches the current webhook.

        This could be used to get a full webhook from a partial webhook.

        .. note::

            When fetching with an unauthenticated webhook, i.e.
            :meth:`is_authenticated` returns ``False``, then the
            returned webhook does not contain any user information.

        Parameters
        -----------
        prefer_auth: :class:`bool`
            Whether to use the bot token over the webhook token
            if available. Defaults to ``True``.

        Raises
        -------
        HTTPException
            Could not fetch the webhook
        NotFound
            Could not find the webhook by this ID
        ValueError
            This webhook does not have a token associated with it.

        Returns
        --------
        :class:`SyncWebhook`
            The fetched webhook.
        r   5This webhook does not have a token associated with it)r   r  )
r   rb   r   r   re   r   r   r  r    r   )r>   r  r   rt   s       r?   fetchzSyncWebhook.fetch  s    > #7"8"8 	V4? 	V(($/4<(XXDDZ 	V33DGTZQUQ]3^^DDTUUU4T_DKXXXXrA   )ra   r  ra   c               $   | j         | j        t          d          t                      }|r1| j        r*|                    | j        | j        | j        |           dS | j         r*|                    | j        | j         | j        |           dS dS )a  Deletes this Webhook.

        Parameters
        ------------
        reason: Optional[:class:`str`]
            The reason for deleting this webhook. Shows up on the audit log.

            .. versionadded:: 1.4
        prefer_auth: :class:`bool`
            Whether to use the bot token over the webhook token
            if available. Defaults to ``True``.

        Raises
        -------
        HTTPException
            Deleting the webhook failed.
        NotFound
            This webhook does not exist.
        Forbidden
            You do not have permissions to delete this webhook.
        ValueError
            This webhook does not have a token associated with it.
        Nr  )r   re   ra   )re   ra   )r   rb   r  r   r   r   re   r   )r>   ra   r  r   s       r?   r   zSyncWebhook.delete  s    0 :$/"9TUUU"6"8"8 	h4? 	h""47$/4<`f"gggggZ 	h--dgtz4<`f-ggggg	h 	hrA   )ra   ro   avatarchannelr  ro   r"  Optional[bytes]r#  Optional[Snowflake]c                  | j         | j        t          d          i }|t          ur|t	          |          nd|d<   |t          ur|t          j        |          nd|d<   t                      }d}|J| j        t          d          |j        |d<   |	                    | j        | j        || j
        |          }nc|r1| j        r*|	                    | j        | j        || j
        |          }n0| j         r)|                    | j        | j         || j
        |          }|t          d          t          || j
        | j        | j        	          S )
aW  Edits this Webhook.

        Parameters
        ------------
        name: Optional[:class:`str`]
            The webhook's new default name.
        avatar: Optional[:class:`bytes`]
            A :term:`py:bytes-like object` representing the webhook's new default avatar.
        channel: Optional[:class:`abc.Snowflake`]
            The webhook's new channel. This requires an authenticated webhook.
        reason: Optional[:class:`str`]
            The reason for editing this webhook. Shows up on the audit log.

            .. versionadded:: 1.4
        prefer_auth: :class:`bool`
            Whether to use the bot token over the webhook token
            if available. Defaults to ``True``.

        Raises
        -------
        HTTPException
            Editing the webhook failed.
        NotFound
            This webhook does not exist.
        ValueError
            This webhook does not have a token associated with it
            or it tried editing a channel without authentication.

        Returns
        --------
        :class:`SyncWebhook`
            The newly edited webhook.
        Nr  ro   r"  z.Editing channel requires authenticated webhook
channel_id)r^   re   ra   z+Unreachable code hit: data was not assigned)rt   re   r   r  )r   rb   r  r4   r   r   _bytes_to_base64_datar   r   r   re   r   r   r    r   )	r>   ra   ro   r"  r#  r  r^   r   rt   s	            r?   r   zSyncWebhook.edit  sz   T :$/"9TUUUw+/+;c$iiiGFO  GMGY ;F C C C_cGH"6"8"8)-& !QRRR$+JGL!'''[_[gpv'wwDD 	~T_ 	~'''[_[gpv'wwDDZ 	~2247DJPWaeamv|2}}D<LMMMdl$/Y]YdeeeerA   r   r   r   r)   r!   c                   t          | | j        |          }| j        p.t          | j        | j        t          |d                             }t          |||          S )N)parentr   r'  )r  guild_idr   )rt   r  r#  )r   r   r#  r   r+  r   r!   )r>   rt   r   r  r#  s        r?   _create_messagezSyncWebhook._create_messagef  s_    d4;vFFF,{"44;QUQ^cfgklxgyczcz"{"{"{!t5'JJJJrA   )
username
avatar_urlr   r`   r   r   thread_namesuppress_embedssilentapplied_tagsr-  r.  r   r   r$   r`   Sequence[File]r   r'   r   r-   r   Literal[True]r/  r0  r1  r2  List[ForumTag]c                   d S r<   rW   r>   r-  r.  r   r`   r   r   r   r   r/  r0  r1  r2  s                r?   sendzSyncWebhook.sendm  s	      !SrA   .)r-  r.  r   r`   r   r   r   r/  r0  r1  r2  Literal[False]c                   d S r<   rW   r7  s                r?   r8  zSyncWebhook.send  s	      srA   )r-  r.  ttsr   r`   r   r   r   r   r/  r0  r1  r2  pollr   r   r;  r   r%   r   r   r<  r&   r,   c                   d S r<   rW   r>   r   r-  r.  r;  r   r`   r   r   r   r   r/  r   r0  r1  r2  r<  r   s                     r?   r8  zSyncWebhook.send  s	    * !SrA   )r-  r.  r;  r   r`   r   r   r   r   r/  r   r0  r1  r2  r<  r   c                   d S r<   rW   r>  s                     r?   r8  zSyncWebhook.send  s	    * srA   Fr+   Optional[SyncWebhookMessage]c                  | j         t          d          t          | j        dd          }|t          }|s|r#t          j        d          }||_        ||_        nt          }|t          urOt          |d          st          d|j        j                   |                                rt          d          |t          ur|
t          urt          d          |t          u rt          }nd	 |D             }t          ||||||||||	|||||
          5 }t                      }d}|
t          ur|
j        }|                    | j        | j         | j        |j        |j        |j        |||t          u	  	        }ddd           n# 1 swxY w Y   d}|r|                     ||
          }|t          ur|r|                    |           |S )a7  Sends a message using the webhook.

        The content must be a type that can convert to a string through ``str(content)``.

        To upload a single file, the ``file`` parameter should be used with a
        single :class:`File` object.

        If the ``embed`` parameter is provided, it must be of type :class:`Embed` and
        it must be a rich embed type. You cannot mix the ``embed`` parameter with the
        ``embeds`` parameter, which must be a :class:`list` of :class:`Embed` objects to send.

        Parameters
        ------------
        content: :class:`str`
            The content of the message to send.
        wait: :class:`bool`
            Whether the server should wait before sending a response. This essentially
            means that the return type of this function changes from ``None`` to
            a :class:`WebhookMessage` if set to ``True``.
        username: :class:`str`
            The username to send with this message. If no username is provided
            then the default username for the webhook is used.
        avatar_url: :class:`str`
            The avatar URL to send with this message. If no avatar URL is provided
            then the default avatar for the webhook is used. If this is not a
            string then it is explicitly cast using ``str``.
        tts: :class:`bool`
            Indicates if the message should be sent using text-to-speech.
        file: :class:`File`
            The file to upload. This cannot be mixed with ``files`` parameter.
        files: List[:class:`File`]
            A list of files to send with the content. This cannot be mixed with the
            ``file`` parameter.
        embed: :class:`Embed`
            The rich embed for the content to send. This cannot be mixed with
            ``embeds`` parameter.
        embeds: List[:class:`Embed`]
            A list of embeds to send with the content. Maximum of 10. This cannot
            be mixed with the ``embed`` parameter.
        allowed_mentions: :class:`AllowedMentions`
            Controls the mentions being processed in this message.

            .. versionadded:: 1.4
        thread: :class:`~discord.abc.Snowflake`
            The thread to send this message to.

            .. versionadded:: 2.0
        thread_name: :class:`str`
            The thread name to create with this webhook if the webhook belongs
            to a :class:`~discord.ForumChannel`. Note that this is mutually
            exclusive with the ``thread`` parameter, as this will create a
            new thread with the given name.

            .. versionadded:: 2.0
        suppress_embeds: :class:`bool`
            Whether to suppress embeds for the message. This sends the message without any embeds if set to ``True``.

            .. versionadded:: 2.0
        silent: :class:`bool`
            Whether to suppress push and desktop notifications for the message. This will increment the mention counter
            in the UI, but will not actually send a notification.

            .. versionadded:: 2.2
        poll: :class:`Poll`
            The poll to send with this message.

            .. warning::

                When sending a Poll via webhook, you cannot manually end it.

            .. versionadded:: 2.4
        view: Union[:class:`~discord.ui.View`, :class:`~discord.ui.LayoutView`]
            The view to send with the message. This can only have non-interactible items, which do not
            require a state to be attached to it.

            If you want to send a view with any component attached to it, check :meth:`Webhook.send`.

            .. versionadded:: 2.5

        Raises
        --------
        HTTPException
            Sending the message failed.
        NotFound
            This webhook was not found.
        Forbidden
            The authorization token for the webhook is incorrect.
        TypeError
            You specified both ``embed`` and ``embeds`` or ``file`` and ``files``
            or ``thread`` and ``thread_name``.
        ValueError
            The length of ``embeds`` was invalid, there was no token
            associated with this webhook or you tried to send a view
            with components other than URL buttons.

        Returns
        ---------
        Optional[:class:`SyncWebhookMessage`]
            If ``wait`` is ``True`` then the message that was sent, otherwise ``None``.
        Nr  r   r   __discord_ui_view__z/expected view parameter to be of type View not z.SyncWebhook views can only contain URL buttonsz4Cannot mix thread_name and thread keyword arguments.c                    g | ]	}|j         
S rW   )r   )r   tags     r?   r   z$SyncWebhook.send.<locals>.<listcomp>T  s    -M-M-Mcf-M-M-MrA   )r   r-  r.  r;  r   r`   r   r   r/  r   previous_allowed_mentionsflagsr2  r<  r   )re   r^   r_   r`   r   r   r   r   )r   r  getattrr   r4   r   _from_valuer0  suppress_notificationshasattrr  r  rT   is_dispatchabler   r   r   r   re   r^   r_   r`   r,  _update)r>   r   r-  r.  r;  r   r`   r   r   r   r   r/  r   r0  r1  r2  r<  r   previous_mentionsrF  applied_tag_idsrc   r   r   rt   msgs                             r?   r8  zSyncWebhook.send  sl   t :TUUU7>t{L^`d7e7e?G 	f 	 ,Q//E$3E!+1E((Ew4!677 m kRVR`Ri k klll##%% S !QRRRg%%&*?*?RSSS7""%OO-M-M-M-M-MO&!#-&7(
 
 
  	  &:&<&<G'+IW$$"I	**
 *l# $G 3 + 
 
D- 	  	  	  	  	  	  	  	  	  	  	  	  	  	  	D  	<&&tF&;;Cw3LL
s   A$FFFc                  | j         t          d          d}|t          ur|j        }t	                      }|                    | j        | j         || j        |          }|                     ||          S )a  Retrieves a single :class:`~discord.SyncWebhookMessage` owned by this webhook.

        .. versionadded:: 2.0

        Parameters
        ------------
        id: :class:`int`
            The message ID to look for.
        thread: :class:`~discord.abc.Snowflake`
            The thread to look in.

        Raises
        --------
        ~discord.NotFound
            The specified message was not found.
        ~discord.Forbidden
            You do not have the permissions required to get a message.
        ~discord.HTTPException
            Retrieving the message failed.
        ValueError
            There was no token associated with this webhook.

        Returns
        --------
        :class:`~discord.SyncWebhookMessage`
            The message asked for.
        Nr  re   r   r   )r   r  r4   r   r   r   re   r,  )r>   r   r   r   r   rt   s         r?   fetch_messagezSyncWebhook.fetch_message  s    : :TUUU#'	  	I"6"8"8**GJL + 
 
 ##D#888rA   )r   r   r   r   r   r   r   c                   d S r<   rW   )r>   r   r   r   r   r   s         r?   r   zSyncWebhook.edit_message  s	     !SrA   )r   r   r   r   r   r   r   r   Optional[View]c                   d S r<   rW   )	r>   r   r   r   r   r   r   r   r   s	            r?   r   zSyncWebhook.edit_message  s	     !SrA   r   c               \   | j         t          d          |rOt          |d          st          d|j        j                   |                                rt          d          t          | j        dd          }	t          ||||||	|          5 }
d}|t          ur|j        }t                      }|                    | j        | j         || j        |
j        |
j        |
j        |t%          |          	  	        }|                     ||	          cddd           S # 1 swxY w Y   dS )
aO	  Edits a message owned by this webhook.

        This is a lower level interface to :meth:`WebhookMessage.edit` in case
        you only have an ID.

        .. versionadded:: 1.6

        Parameters
        ------------
        message_id: :class:`int`
            The message ID to edit.
        content: Optional[:class:`str`]
            The content to edit the message with or ``None`` to clear it.
        embeds: List[:class:`Embed`]
            A list of embeds to edit the message with.
        embed: Optional[:class:`Embed`]
            The embed to edit the message with. ``None`` suppresses the embeds.
            This should not be mixed with the ``embeds`` parameter.
        attachments: List[Union[:class:`Attachment`, :class:`File`]]
            A list of attachments to keep in the message as well as new files to upload. If ``[]`` is passed
            then all attachments are removed.

            .. versionadded:: 2.0
        view: Optional[Union[:class:`~discord.ui.View`, :class:`~discord.ui.LayoutView`]]
            The updated view to update this message with. This can only have non-interactible items, which do not
            require a state to be attached to it. If ``None`` is passed then the view is removed.

            If you want to edit a webhook message with any component attached to it, check :meth:`WebhookMessage.edit`.

            .. note::

                To update the message to add a :class:`~discord.ui.LayoutView`, you
                must explicitly set the ``content``, ``embed``, ``embeds``, and
                ``attachments`` parameters to either ``None`` or an empty array, as appropriate.

            .. versionadded:: 2.6
        allowed_mentions: :class:`AllowedMentions`
            Controls the mentions being processed in this message.
            See :meth:`.abc.Messageable.send` for more information.
        thread: :class:`~discord.abc.Snowflake`
            The thread the webhook message belongs to.

            .. versionadded:: 2.0

        Raises
        -------
        HTTPException
            Editing the message failed.
        Forbidden
            Edited a message that is not yours.
        TypeError
            You specified both ``embed`` and ``embeds``
        ValueError
            The length of ``embeds`` was invalid or
            there was no token associated with this webhook.
        Nr  rB  z>expected view parameter to be of type View or LayoutView, not z1SyncWebhooks can not send interactable componentsr   )r   r   r   r   r   rE  r   )re   r^   r_   r`   r   r   r   )r   r  rJ  r  r  rT   rK  rG  r   r   r4   r   r   r   re   r^   r_   r`   r   r,  )r>   r   r   r   r   r   r   r   r   rM  rc   r   r   rt   s                 r?   r   zSyncWebhook.edit_message  s   J :TUUU 	V4!677 | zaeaoax z z{{{##%% V !TUUU7>t{L^`d7e7e&#-&7
 
 
 	= '+IW$$"I	&:&<&<G//
 *l# $T

 0 
 
D ''V'<<3	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	=s   B D!!D%(D%c                  | j         t          d          d}|t          ur|j        }t	                      }|                    | j        | j         || j        |           dS )a  Deletes a message owned by this webhook.

        This is a lower level interface to :meth:`WebhookMessage.delete` in case
        you only have an ID.

        .. versionadded:: 1.6

        Parameters
        ------------
        message_id: :class:`int`
            The message ID to delete.
        thread: :class:`~discord.abc.Snowflake`
            The thread the webhook message belongs to.

            .. versionadded:: 2.0

        Raises
        -------
        HTTPException
            Deleting the message failed.
        Forbidden
            Deleted a message that is not yours.
        ValueError
            This webhook does not have a token associated with it.
        Nr  rQ  )r   r  r4   r   r   r   re   )r>   r   r   r   r   s        r?   r   zSyncWebhook.delete_message4  sy    4 :TUUU#'	  	I"6"8"8&&GJL 	' 	
 	
 	
 	
 	
rA   )NN)
rt   r   re   r2   r   ri   r  r  r9   r:   )r9   r   )
r   r   r   r   re   r2   r  ri   r9   r    )r   r   re   r2   r  ri   r9   r    )r  r   r9   r    )ra   ri   r  r   r9   r:   )ra   ri   ro   ri   r"  r$  r#  r%  r  r   r9   r    )rt   r   r   r)   r9   r!   )r-  r   r.  r   r   r$   r`   r3  r   r'   r   r-   r   r4  r   r)   r/  r   r0  r   r1  r   r2  r5  r9   r!   )r-  r   r.  r   r   r$   r`   r3  r   r'   r   r-   r   r9  r   r)   r/  r   r0  r   r1  r   r2  r5  r9   r:   )$r   r   r-  r   r.  r   r;  r   r   r$   r`   r3  r   r%   r   r   r   r'   r   r)   r/  r   r   r4  r0  r   r1  r   r2  r5  r<  r&   r   r,   r9   r!   )$r   r   r-  r   r.  r   r;  r   r   r$   r`   r3  r   r%   r   r   r   r'   r   r)   r/  r   r   r9  r0  r   r1  r   r2  r5  r<  r&   r   r,   r9   r:   )$r   r   r-  r   r.  r   r;  r   r   r$   r`   r3  r   r%   r   r   r   r'   r   r)   r/  r   r   r   r0  r   r1  r   r2  r5  r<  r&   r   r+   r9   r@  )r   r   r   r)   r9   r!   )r   r   r   r   r   r-   r   r   r   r)   r9   r!   )r   r   r   ri   r   r   r   r   r   r   r   rT  r   r   r   r)   r9   r!   )r   r   r   ri   r   r   r   r   r   r   r   r   r   r   r   r)   r9   r!   )r   r   r   r)   r9   r:   )rT   rU   rV   r   r  r   r@   r
  propertyr   classmethodr4   r  r  r   r   r   r,  r   r8  rR  r   r   __classcell__)r  s   @r?   r    r    4  s        5 5n ".I----  $AE( ( ( ( ( ( (Q Q Q Q J J J XJ @Gdh $3 $3 $3 $3 $3 [$3L 6=Z^ (3 (3 (3 (3 (3 [(3T ,0 (Y (Y (Y (Y (Y (YT 15$  h  h  h  h  h  hJ !%%")'+ Ff Ff Ff Ff Ff FfP LS K K K K K K   ! ',3 $" ''.! ! ! ! ! X!"   ! ',3"#" ''.     X"  !  ! '"),3#" ''.'! ! ! ! ! X!,    ! '"),3#"" ''.'     X0 A  ! '"),3#" %'. 'A A A A A AF @G ,9 ,9 ,9 ,9 ,9 ,9\ 
 :=69! ! ! ! ! X! 
 "%"%!$9<"69! ! ! ! ! X!" ")")!(9@#*6:#i= i= i= i= i= i=V IP (
 (
 (
 (
 (
 (
 (
 (
 (
 (
rA   r    )r9   rY   )\r   
__future__r   r   loggingr   rP   r  urllib.parser   r   typingr   r   r   r   r	   r
   r   r   r   r   r   r   r[    r   errorsr   r   r   r   messager   r   httpr   r   r#  r   r   async_r   r   __all__	getLoggerrT   r   typing_extensionsr"   typesr#   r   r$   r   r%   r<  r&   mentionsr'   r(   abcr)   r  r*   ui.viewr+   r,   r-   types.webhookr.   r   types.messager   types.snowflaker/   BaseExceptionr0   r  r2   r3   ModuleNotFoundErrorr4   r   r6   rY   localr   r   r   r!   r    rW   rA   r?   <module>rq     s    < # " " " " "        				 * * * * * * u u u u u u u u u u u u u u u u u u u u u u u u u u u u        K K K K K K K K K K K K + + + + + + + + 3 3 3 3 3 3 3 3 2 2 2 2 2 2 2 2 . . . . . . . .
 w"" &&&&&&######******$$$$$$''''''4444444444           0/////	]	+	+	+B.........    }           .P4 P4 P4 P4 P4 P4 P4 P4f- - - - -io - - - ?   bQ bQ bQ bQ bQ bQ bQ bQJh
 h
 h
 h
 h
+ h
 h
 h
 h
 h
s   *C3 3C;:C;