
    cjh                       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	Z	ddl
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 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 m!Z!m"Z"m#Z#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l0m1Z1m2Z2 	 ddl3Z3dZ4dZ6dZ7 G d d      Z8 e8       Z9de:d<    ed       Z; G d d      Z<erGddl=m>Z> ddl?m@Z@ ddlAmBZB ddlCmDZD ddlEmFZF ddlGmHZH ddlImJZJ  G d  d!e+      ZK e*d"eL      ZM e>d#      ZNne<ZMeZBeZD e-d$      ZO e-d%d&      ZPe.e'eO   e eO   f   ZQ G d' d(e%eOePf         ZR G d) d*e%eP         ZS	 	 	 	 dxd+ZT G d, d-e%eP   ej~                  jX                        ZUdyd.ZVe/dzd/       ZWe/d{d0       ZWe/d|d1       ZWd|d2ZWd}d3ZX	 	 	 	 	 d~	 	 	 	 	 	 	 	 	 	 	 	 	 dd4ZY	 	 	 	 	 d~dd5	 	 	 	 	 	 	 	 	 	 	 	 	 dd6ZZe9e9e9e9dd7	 	 	 	 	 	 	 	 	 	 	 	 	 dd8Z[dd9Z\ddd:Z]dd;Z^dd<Z_e9d=dd>Z`dd?Zadd@ZbddAZcddBZde4rddCZee3j                  j                  ZgnddDZee
j                  ZgddEddFZidG ZjedHdIZkdJ ZlddKZmddLZndddMZoddNZpddOZq G dP dQej                        Zr ej                  dR      ZtetdSddTZuddUZvddVZwdWj                  dX dYD              ZydZZzd[ez Z{ ej                  d\ey dWe{ d]ej                  ej                  z        Z~d^Zd_e{ d]Zdd`ddaZdddb	 	 	 	 	 	 	 ddcZdddZddeZddfZddgZddhZddiZe/ddj       Ze/ddk       ZddlZej                  dmk\  ZddnZddoZddp	 	 	 	 	 	 	 	 	 ddqZ	 	 	 	 	 	 	 	 	 	 ddrZe(ds   ZdddtZddduZe.e&eD   e&e   e&e   e&e   f   Ze!e   Ze.ee"eBge.eef   f   ef   Ze"eBgef   ZddvZdw Zy# e5$ r dZ4Y 0w xY w)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.
    )annotationsN)	b64encode)bisect_left)field)isawaitable)	signature)
attrgetter)TYPE_CHECKINGAnyAsyncIterator	AwaitableCallable	Coroutine
ForwardRefGenericIterableIteratorLiteralMappingNewTypeProtocolSequenceTypeVarUnionoverload   )HTTPExceptionInvalidArgumentTF)
parse_timewarn_deprecated
deprecated	oauth_urlsnowflake_timetime_snowflakefindgetget_or_fetchsleep_untilutcnowresolve_inviteresolve_templateremove_markdownescape_markdownescape_mentionsraw_mentionsraw_channel_mentionsraw_role_mentions	as_chunks	format_dtgenerate_snowflakebasic_autocompletefilter_paramsl    0E*c                  $    e Zd ZddZddZddZy)_MissingSentinelc                     yNF )selfothers     @/var/www/html/venv/lib/python3.12/site-packages/discord/utils.py__eq__z_MissingSentinel.__eq__l           c                     yr:   r;   r<   s    r>   __bool__z_MissingSentinel.__bool__o   r@   rA   c                     y)Nz...r;   rC   s    r>   __repr__z_MissingSentinel.__repr__r   r@   rA   N)returnbool)rG   str)__name__
__module____qualname__r?   rD   rF   r;   rA   r>   r8   r8   k   s    rA   r8   r   MISSINGc                     t         S N)rM   r;   rA   r>   <lambda>rP   {   s    W rA   )default_factoryc                      e Zd Zd Zd Zy)_cached_propertyc                4    || _         t        |d      | _        y N__doc__)functiongetattrrV   )r<   rW   s     r>   __init__z_cached_property.__init__   s     x3rA   c                r    || S | j                  |      }t        || j                   j                  |       |S rO   )rW   setattrrJ   r<   instanceownervalues       r>   __get__z_cached_property.__get__   s6    Kh'$--00%8rA   N)rJ   rK   rL   rY   r`   r;   rA   r>   rS   rS   ~   s    4rA   rS   )	ParamSpec)	Snowflake)AutocompleteContext)OptionChoiceInvite)PermissionsTemplatec                      e Zd ZU ded<   y)_RequestLikezMapping[str, Any]headersN)rJ   rK   rL   __annotations__r;   rA   r>   rk   rk      s    ""rA   rk   cached_propertyPTT_co)	covariantc                  L    e Zd ZddZe	 	 	 	 	 	 dd       Zedd       Zd	dZy)
CachedSlotPropertyc                B    || _         || _        t        |d      | _        y rU   )namerW   rX   rV   )r<   rv   rW   s      r>   rY   zCachedSlotProperty.__init__   s    	 x3rA   c                     y rO   r;   r<   r]   r^   s      r>   r`   zCachedSlotProperty.__get__   s     '*rA   c                     y rO   r;   rx   s      r>   r`   zCachedSlotProperty.__get__   s    <?rA   c                    || S 	 t        || j                        S # t        $ r- | j                  |      }t	        || j                  |       |cY S w xY wrO   )rX   rv   AttributeErrorrW   r[   r\   s       r>   r`   zCachedSlotProperty.__get__   sU    K	8TYY// 	MM(+EHdii/L	s    3AAN)rv   rI   rW   Callable[[T], T_co]rG   None)r]   r}   r^   type[T]rG   CachedSlotProperty[T, T_co])r]   rp   r^   r~   rG   rq   )r]   T | Noner^   r~   rG   r   )rJ   rK   rL   rY   r   r`   r;   rA   r>   rt   rt      sH    4
 **%,*	$* * ? ?	rA   rt   c                  $    e Zd ZddZddZddZy)classpropertyc                    || _         y rO   fget)r<   r   s     r>   rY   zclassproperty.__init__   s	    	rA   c                $    | j                  |      S rO   r   rx   s      r>   r`   zclassproperty.__get__   s    yyrA   c                    t        d      )Nzcannot set attribute)r{   )r<   r]   r_   s      r>   __set__zclassproperty.__set__   s    344rA   N)r   zCallable[[Any], T_co]rG   r}   )r]   z
Any | Noner^   	type[Any]rG   rq   )rG   r}   )rJ   rK   rL   rY   r`   r   r;   rA   r>   r   r      s     5rA   r   c                     d fd}|S )Nc                    t        |       S rO   )rt   )funcrv   s    r>   	decoratorz'cached_slot_property.<locals>.decorator   s    !$--rA   )r   r|   rG   r   r;   )rv   r   s   ` r>   cached_slot_propertyr      s    . rA   c                  P    e Zd ZdZddZddZddZddZddZddZ	ddZ
dd	Zy
)SequenceProxyzRead-only proxy of a Sequence.c                    || _         y rO   _SequenceProxy__proxied)r<   proxieds     r>   rY   zSequenceProxy.__init__   s	     rA   c                     | j                   |   S rO   r   )r<   idxs     r>   __getitem__zSequenceProxy.__getitem__   s    ~~c""rA   c                ,    t        | j                        S rO   )lenr   rC   s    r>   __len__zSequenceProxy.__len__   s    4>>""rA   c                    || j                   v S rO   r   )r<   items     r>   __contains__zSequenceProxy.__contains__   s    t~~%%rA   c                ,    t        | j                        S rO   )iterr   rC   s    r>   __iter__zSequenceProxy.__iter__   s    DNN##rA   c                ,    t        | j                        S rO   )reversedr   rC   s    r>   __reversed__zSequenceProxy.__reversed__   s    ''rA   c                B     | j                   j                  |g|i |S rO   )r   index)r<   r_   argskwargss       r>   r   zSequenceProxy.index   s#    #t~~##E;D;F;;rA   c                8    | j                   j                  |      S rO   )r   count)r<   r_   s     r>   r   zSequenceProxy.count   s    ~~##E**rA   N)r   zSequence[T_co])r   intrG   rq   )rG   r   r   r   rG   rH   )rG   zIterator[T_co])r_   r   rG   r   )rJ   rK   rL   rV   rY   r   r   r   r   r   r   r   r;   rA   r>   r   r      s-    (!##&$(<+rA   r   c                H      fd}t        j                   |              y )Nc                    K   t        j                          d {    	  d {    y 7 7 # t        $ r Y y w xY wwrO   )asynciosleepr   )delayr   s   r>   
inner_callzdelay_task.<locals>.inner_call   s?     mmE"""	JJ 	# 		s5   A -A 1 /1 A 1 	=A =A )r   create_task)r   r   r   s   `` r>   
delay_taskr      s     
%rA   c                     y rO   r;   	timestamps    r>   r   r      s    ),rA   c                     y rO   r;   r   s    r>   r   r     s    58rA   c                     y rO   r;   r   s    r>   r   r     s    CFrA   c                F    | rt         j                   j                  |       S y)a  A helper function to convert an ISO 8601 timestamp to a datetime object.

    Parameters
    ----------
    timestamp: Optional[:class:`str`]
        The timestamp to convert.

    Returns
    -------
    Optional[:class:`datetime.datetime`]
        The converted datetime object.
    N)datetimefromisoformatr   s    r>   r   r   
  s!       ..y99rA   c                     d fd}|S )Nc                J    j                   | _         t              | _        | S rO   )rV   
_signature__signature__)
overriddenoriginals    r>   r   zcopy_doc.<locals>.decorator  s$    %--
#-h#7
 rA   )r   rp   rG   rp   r;   )r   r   s   ` r>   copy_docr     s    
 rA   c                   t        j                  dt               |  d}|r|d| z  }|r|d| z  }|r	|d| dz  }|dz  }|r	|d| d	z  }t        j                  ||t        
       t        j                  dt               y)a  Warn about a deprecated function, with the ability to specify details about the deprecation. Emits a
    DeprecationWarning.

    Parameters
    ----------
    name: str
        The name of the deprecated function.
    instead: Optional[:class:`str`]
        A recommended alternative to the function.
    since: Optional[:class:`str`]
        The version in which the function was deprecated. This should be in the format ``major.minor(.patch)``, where
        the patch version is optional.
    removed: Optional[:class:`str`]
        The version in which the function is planned to be removed. This should be in the format
        ``major.minor(.patch)``, where the patch version is optional.
    reference: Optional[:class:`str`]
        A reference that explains the deprecation, typically a URL to a page such as a changelog entry or a GitHub
        issue/PR.
    stacklevel: :class:`int`
        The stacklevel kwarg passed to :func:`warnings.warn`. Defaults to 3.
    alwaysz is deprecatedz since version z  and will be removed in version z, consider using z instead.z See z for more information.)
stacklevelcategorydefaultN)warningssimplefilterDeprecationWarningwarn)rv   insteadsinceremoved	referencer   messages          r>   r    r    %  s    : ($67n%G_UG,,5gY??&wix88sNGU9+%;<<MM'j;MN)%78rA   )use_qualnamec               (     d fd}|S )a  A decorator implementation of :func:`warn_deprecated`. This will automatically call :func:`warn_deprecated` when
    the decorated function is called.

    Parameters
    ----------
    instead: Optional[:class:`str`]
        A recommended alternative to the function.
    since: Optional[:class:`str`]
        The version in which the function was deprecated. This should be in the format ``major.minor(.patch)``, where
        the patch version is optional.
    removed: Optional[:class:`str`]
        The version in which the function is planned to be removed. This should be in the format
        ``major.minor(.patch)``, where the patch version is optional.
    reference: Optional[:class:`str`]
        A reference that explains the deprecation, typically a URL to a page such as a changelog entry or a GitHub
        issue/PR.
    stacklevel: :class:`int`
        The stacklevel kwarg passed to :func:`warnings.warn`. Defaults to 3.
    use_qualname: :class:`bool`
        Whether to use the qualified name of the function in the deprecation warning. If ``False``, the short name of
        the function will be used instead. For example, __qualname__ will display as ``Client.login`` while __name__
        will display as ``login``. Defaults to ``True``.
    c           	     R     t        j                         d fd       }|S )Nc                 f    t        rj                  nj                          | i |S )N)rv   r   r   r   r   r   )r    rL   rJ   )	r   r   r   r   r   r   r   r   r   s	     r>   	decoratedz7deprecated.<locals>.actual_decorator.<locals>.decoratedt  s=    *6T&&DMM#% (((rA   )r   zP.argsr   zP.kwargsrG   rp   )	functoolswraps)r   r   r   r   r   r   r   r   s   ` r>   actual_decoratorz$deprecated.<locals>.actual_decorators  s+    				) 		) 
		) rA   )r   Callable[[P], T]rG   r   r;   )r   r   r   r   r   r   r   s   `````` r>   r!   r!   R  s    B  rA   )permissionsguildredirect_uriscopesdisable_guild_selectc                   d|  }|ddj                  |xs d       z  }|t        ur|d|j                   z  }|t        ur|d|j                   z  }|t        urddlm} |d	 |d
|i       z  }|r|dz  }|S )a  A helper function that returns the OAuth2 URL for inviting the bot
    into guilds.

    Parameters
    ----------
    client_id: Union[:class:`int`, :class:`str`]
        The client ID for your bot.
    permissions: :class:`~discord.Permissions`
        The permissions you're requesting. If not given then you won't be requesting any
        permissions.
    guild: :class:`~discord.abc.Snowflake`
        The guild to pre-select in the authorization screen, if available.
    redirect_uri: :class:`str`
        An optional valid redirect URI.
    scopes: Iterable[:class:`str`]
        An optional valid list of scopes. Defaults to ``('bot',)``.

        .. versionadded:: 1.7
    disable_guild_select: :class:`bool`
        Whether to disallow the user from changing the guild dropdown.

        .. versionadded:: 2.0

    Returns
    -------
    :class:`str`
        The OAuth2 URL for inviting the bot into guilds.
    z/https://discord.com/oauth2/authorize?client_id=z&scope=+)botz&permissions=z
&guild_id=r   )	urlencodez&response_type=code&r   z&disable_guild_select=true)joinrM   r_   idurllib.parser   )	client_idr   r   r   r   r   urlr   s           r>   r"   r"     s    J <I;
GCWSXXf01233C'!{00122GEHH:&&7"*%i0N&O%PQQ++JrA   c                    | dz	  t         z   dz  }t        j                  j                  |t        j                  j                        S )a  Converts a Discord snowflake ID to a UTC-aware datetime object.

    Parameters
    ----------
    id: :class:`int`
        The snowflake ID.

    Returns
    -------
    :class:`datetime.datetime`
        An aware datetime in UTC representing the creation time of the snowflake.
         )tz)DISCORD_EPOCHr   fromtimestamptimezoneutc)r   r   s     r>   r#   r#     s?     (m+t3I**99J9J9N9N*OOrA   c                d    t        | j                         dz  t        z
        }|dz  |rdz   S dz   S )a  Returns a numeric snowflake pretending to be created at the given date.

    When using as the lower end of a range, use ``time_snowflake(high=False) - 1``
    to be inclusive, ``high=True`` to be exclusive.

    When using as the higher end of a range, use ``time_snowflake(high=True) + 1``
    to be inclusive, ``high=False`` to be exclusive

    Parameters
    ----------
    dt: :class:`datetime.datetime`
        A datetime object to convert to a snowflake.
        If naive, the timezone is assumed to be local time.
    high: :class:`bool`
        Whether to set the lower 22 bit to high or low.

    Returns
    -------
    :class:`int`
        The snowflake representing the time given.
    r   r   ? r   )r   r   r   )dthighdiscord_milliss      r>   r$   r$     s8    , $.>?Nb $Y>>A>>rA   c                *    |D ]  } | |      s|c S  y)a~  A helper to return the first element found in the sequence
    that meets the predicate. For example: ::

        member = discord.utils.find(lambda m: m.name == 'Mighty', channel.guild.members)

    would find the first :class:`~discord.Member` whose name is 'Mighty' and return it.
    If an entry is not found, then ``None`` is returned.

    This is different from :func:`py:filter` due to the fact it stops the moment it finds
    a valid entry.

    Parameters
    ----------
    predicate
        A function that returns a boolean-like result.
    seq: :class:`collections.abc.Iterable`
        The iterable to search through.
    Nr;   )	predicateseqelements      r>   r%   r%     s%    (  WN rA   c           
     v  
 t         }t        }t        |      dk(  rB|j                         \  }} ||j	                  dd            }| D ]  
 |
      |k(  s
c S  y|j                         D cg c]  \  }} ||j	                  dd            |f! }	}}| D ]  
 |
fd|	D              s
c S  yc c}}w )a  A helper that returns the first element in the iterable that meets
    all the traits passed in ``attrs``. This is an alternative for
    :func:`~discord.utils.find`.

    When multiple attributes are specified, they are checked using
    logical AND, not logical OR. Meaning they have to meet every
    attribute passed in and not one of them.

    To have a nested attribute search (i.e. search by ``x.y``) then
    pass in ``x__y`` as the keyword argument.

    If nothing is found that matches the attributes passed, then
    ``None`` is returned.

    Examples
    ---------

    Basic usage:

    .. code-block:: python3

        member = discord.utils.get(message.guild.members, name='Foo')

    Multiple attribute matching:

    .. code-block:: python3

        channel = discord.utils.get(guild.voice_channels, name='Foo', bitrate=64000)

    Nested attribute matching:

    .. code-block:: python3

        channel = discord.utils.get(client.get_all_channels(), guild__name='Cool', name='general')

    Parameters
    -----------
    iterable
        An iterable to search through.
    \*\*attrs
        Keyword arguments that denote attributes to search with.
    r   __r   Nc              3  :   K   | ]  \  }} |      |k(    y wrO   r;   ).0predr_   elems      r>   	<genexpr>zget.<locals>.<genexpr><  s     AeT
e#A   )allr	   r   popitemreplaceitems)iterableattrs_allattrgetkvr   attrr_   	convertedr   s             @r>   r&   r&     s    Z DG 5zQ}}1qyys+, 	DDzQ	  FK[[]6AdEdC(	)51I   AyAAK s   1$B5)r   c          	     >  K    t        | d|       |      }| 	  t        | d|       |       d{   }|S |S 7 # t        $ r8  t        | d|       |       d{  7  }|t        d| d| d|        Y |S t        t        f$ r |t        ur|cY S  w xY ww)a  |coro|

    Attempts to get an attribute from the object in cache. If it fails, it will attempt to fetch it.
    If the fetch also fails, an error will be raised.

    Parameters
    ----------
    obj: Any
        The object to use the get or fetch methods in
    attr: :class:`str`
        The attribute to get or fetch. Note the object must have both a ``get_`` and ``fetch_`` method for this attribute.
    id: :class:`int`
        The ID of the object
    default: Any
        The default value to return if the object is not found, instead of raising an error.

    Returns
    -------
    Any
        The object found or the default value.

    Raises
    ------
    :exc:`AttributeError`
        The object is missing a ``get_`` or ``fetch_`` method
    :exc:`NotFound`
        Invalid ID for the object
    :exc:`HTTPException`
        An error occurred fetching the object
    :exc:`Forbidden`
        You do not have permission to fetch the object

    Examples
    --------

    Getting a guild from a guild ID: ::

        guild = await utils.get_or_fetch(client, 'guild', guild_id)

    Getting a channel from the guild. If the channel is not found, return None: ::

        channel = await utils.get_or_fetch(guild, 'channel', channel_id, default=None)
    get_Nfetch__fetch_zCould not find z	 with id z on )rX   r{   
ValueErrorr   rM   )objr  r   r   getters        r>   r'   r'   A  s     X )WSD-(,F~
	873&8<<F M6M = 	Q973'$(89"===F~ ?4&	"T#!OPP  M z* 	g%		sI   B> <> B> !BA" B;B>BBBBc                R    t         j                  |       D cg c]  }| c}S c c}w rO   )dictfromkeys)r  xs     r>   _uniquer  }  s    }}X./!A///s   	$c                J    	 | |   }|xr t        |      S # t        $ r Y y w xY wrO   )r   KeyError)datakeyr_   s      r>   _get_as_snowflaker    s5    $S	 #U#  s    	""c                    | j                  d      ry| dd dk(  s| dd dv ry	| j                  d
      ry| j                  d      r	| dd dk(  ryt        d      )Ns   PNG

z	image/pngr      s      
   )s   JFIFs   Exifz
image/jpeg)s   GIF87as   GIF89az	image/gifs   RIFF      s   WEBPz
image/webpzUnsupported image type given)
startswithr   )r  s    r>   _get_mime_type_for_imager&    si    :;	ao	%a7I)I	S	T		!d1RjG&;<==rA   c                v    d}t        |       }t        |       j                  d      }|j                  ||      S )Nzdata:{mime};base64,{data}ascii)mimer  )r&  r   decodeformat)r  fmtr)  b64s       r>   _bytes_to_base64_datar.    s8    
%C#D)D
D/
 
 
)C::4c:**rA   c                ^    t         j                  j                  |       j                  d      S )Nzutf-8)msgspecjsonencoder*  r  s    r>   _to_jsonr4    s"    ||""3'..w77rA   c                2    t        j                  | dd      S )N),:T)
separatorsensure_ascii)r1  dumpsr3  s    r>   r4  r4    s    zz#*4HHrA   )	use_clockc               Z   | j                   j                  d      }|s|rt        |      S t        j                  j
                  }t        j                  j                  |      }t        j                  j                  t        | j                   d         |      }||z
  j                         S )NzX-Ratelimit-Reset-AfterzX-Ratelimit-Reset)	rl   r&   floatr   r   r   nowr   total_seconds)requestr;  reset_afterr   r>  resets         r>   _parse_ratelimit_headerrC    s    %oo112KLK[!!




C





$C++goo123SE CK&&((rA   c                L   K    | |i |}t        |      r
| d {   S |S 7 wrO   )_isawaitable)fr   r   r_   s       r>   maybe_coroutinerG    s/     tvEE{ s   $"$)checkc               J   K   | D ]  } ||      r
| d {   }|r y y7 w)NFTr;   )genrH  r   s      r>   	async_allrK    s3      ;:D	
  s   #!##c                 K   | D cg c]  }t        j                  |       }}t        j                  ||t         j                         d {   \  }}t	        |      dk7  rt        j
                         |S c c}w 7 0w)N)timeoutreturn_whenr   )r   ensure_futurewaitALL_COMPLETEDr   TimeoutError)futuresrM  futensureddonependings         r>   sane_wait_forrX    st     5<=cw$$S)=G=!,,g.C.C MD' 7|q""$$K >s   BA:+BA?1Bc              #     K   t        | j                        D ]  }	 |j                  E d {     y 7 # t        $ r Y (w xY wwrO   )r   __mro__	__slots__r{   )clsmros     r>   	get_slotsr^    sD     $ 	}}$$$ 		s0   A535A5	AA AAc                    | j                   | j                         } t        j                  j                  t        j                  j
                        }t        | |z
  j                         d      S Nr   )tzinfo
astimezoner   r>  r   r   maxr?  )r   r>  s     r>   compute_timedeltard    sS    	yy]]_




 1 1 5 5
6CS'')1--rA   c                `   K   t        |       }t        j                  ||       d{   S 7 w)a  |coro|

    Sleep until a specified time.

    If the time supplied is in the past this function will yield instantly.

    .. versionadded:: 1.3

    Parameters
    ----------
    when: :class:`datetime.datetime`
        The timestamp in which to sleep until. If the datetime is naive then
        it is assumed to be local time.
    result: Any
        If provided is returned to the caller when the coroutine completes.
    N)rd  r   r   )whenresultdeltas      r>   r(   r(     s)     " d#Euf----s   %.,.c                 p    t         j                   j                  t         j                  j                        S )ap  A helper function to return an aware UTC datetime representing the current time.

    This should be preferred to :meth:`datetime.datetime.utcnow` since it is an aware
    datetime, compared to the naive datetime in the standard library.

    .. versionadded:: 2.0

    Returns
    -------
    :class:`datetime.datetime`
        The current aware datetime in UTC.
    )r   r>  r   r   r;   rA   r>   r)   r)     s'       !2!2!6!677rA   c                8    | | dz
  z   xr d| cxk\  xr dk\  S c S )z+Icons must be power of 2 within [16, 4096].r   i      r;   )sizes    r>   valid_icon_sizerm  
  s)    tax  7TT%7R%77%77rA   c                  L    e Zd ZdZdZerddddZddddZddZddZ	dd	Z
y
)SnowflakeLista'  Internal data storage class to efficiently store a list of snowflakes.

    This should have the following characteristics:

    - Low memory usage
    - O(n) iteration (obviously)
    - O(n log n) initial creation if data is unsorted
    - O(log n) search and indexing
    - O(n) insertion
    r;   F)	is_sortedc                    y rO   r;   )r<   r  rp  s      r>   rY   zSnowflakeList.__init__  s    rA   c               f    t         j                   j                  | d|r|      S t        |            S )NQ)array__new__sorted)r\  r  rp  s      r>   ru  zSnowflakeList.__new__!  s)    {{""3YTQQF4LQQrA   c                @    t        | |      }| j                  ||       y rO   )r   insertr<   r   is      r>   addzSnowflakeList.add$  s    g&AwrA   c                T    t        | |      }|t        |       k7  r| |   |k(  r| |   S d S rO   r   r   ry  s      r>   r&   zSnowflakeList.get(  s2    g&s4y.T!W-?tAwITIrA   c                J    t        | |      }|t        |       k7  xr | |   |k(  S rO   r}  ry  s      r>   haszSnowflakeList.has,  s*    g&CI~4$q'W"44rA   N)r  zIterable[int]rp  rH   )r   r   rG   r}   )r   r   rG   
int | None)r   r   rG   rH   )rJ   rK   rL   rV   r[  r
   rY   ru  r{  r&   r  r;   rA   r>   ro  ro    s0    	 IEJP?D R J5rA   ro  z^[\x00-\x7f]+$)	_IS_ASCIIc                   |j                  |       }|r|j                  S dt        j                  t	        fd| D              S )zReturns string's width.WFAc              3  :   K   | ]  } |      v rd nd  yw)   r   Nr;   )r   charUNICODE_WIDE_CHAR_TYPEr   s     r>   r   z _string_width.<locals>.<genexpr><  s"     SDDJ"88qa?Sr  )matchendposunicodedataeast_asian_widthsum)stringr  r  r  r   s      @@r>   _string_widthr  4  s@    OOF#E||"''DSFSSSrA   c                    ddl m} t        | |      r| j                  S d}t	        j
                  ||       }|r|j                  d      S | S )z
    Resolves an invite from a :class:`~discord.Invite`, URL or code.

    Parameters
    ----------
    invite: Union[:class:`~discord.Invite`, :class:`str`]
        The invite.

    Returns
    -------
    :class:`str`
        The invite code.
    r   re   z<(?:https?\:\/\/)?discord(?:\.gg|(?:app)?\.com\/invite)\/(.+))inviterf   
isinstancecoderer  group)r  rf   rxms       r>   r*   r*   ?  sF     &&!{{	HB
VAwwqzMrA   c                    ddl m} t        | |      r| j                  S d}t	        j
                  ||       }|r|j                  d      S | S )a  
    Resolves a template code from a :class:`~discord.Template`, URL or code.

    .. versionadded:: 1.4

    Parameters
    ----------
    code: Union[:class:`~discord.Template`, :class:`str`]
        The code.

    Returns
    -------
    :class:`str`
        The template code.
    r   rh   z?(?:https?\:\/\/)?discord(?:\.new|(?:app)?\.com\/template)\/(.+))templateri   r  r  r  r  r  )r  ri   r  r  s       r>   r+   r+   X  sF      #$!yy	KB
TAwwqzKrA   |c              #  >   K   | ]  }d j                  |        yw)z \{0}(?=([\s\S]*((?<!\{0})\{0})))N)r+  )r   cs     r>   r   r   s  s!      %67'..q1%s   )*`_~r  z
\[  # matches link text
    [^\[\]]* # link text can contain anything but brackets
\]
\(  # matches link destination
    [^\(\)]+ # link destination cannot contain parentheses
\)z^>(?:>>)?\s|z(?P<markdown>)zH(?P<url><[^: >]+:\/[^ >]+>|(?:https?|steam):\/\/[^\s<]+[^<.,:;\"\'\]\s])z(?P<markdown>[_\\~|\*`]|)ignore_linksc                   d }t         }|rdt         d| d}t        j                  ||| dt        j                        S )a  A helper function that removes markdown characters.

    .. versionadded:: 1.7

    .. note::
            This function is not markdown aware and may remove meaning from the original text. For example,
            if the input contains ``10 * 5`` then it will be converted into ``10  5``.

    Parameters
    ----------
    text: :class:`str`
        The text to remove markdown from.
    ignore_links: :class:`bool`
        Whether to leave links alone when removing markdown. For example,
        if a URL in the text contains characters such as ``_`` then it will
        be left alone. Defaults to ``True``.

    Returns
    -------
    :class:`str`
        The text with the markdown special characters removed.
    c                F    | j                         }|j                  dd      S )Nr    	groupdictr&   )r  r  s     r>   replacementz$remove_markdown.<locals>.replacement  s    OO%	}}UB''rA   (?:r  r  r   )_MARKDOWN_STOCK_REGEX
_URL_REGEXr  sub	MULTILINE)textr  r  regexs       r>   r,   r,     s@    0( "Ej\5'+66%dAr||<<rA   )	as_neededr  c                   |sPd }t         }|rdt         d| d}t        j                  ||| dt        j                  t        j
                  z        S t        j                  dd|       } t        j                  d|       S )	a  A helper function that escapes Discord's markdown.

    Parameters
    -----------
    text: :class:`str`
        The text to escape markdown from.
    as_needed: :class:`bool`
        Whether to escape the markdown characters as needed. This
        means that it does not escape extraneous characters if it's
        not necessary, e.g. ``**hello**`` is escaped into ``\*\*hello**``
        instead of ``\*\*hello\*\*``. Note however that this can open
        you up to some clever syntax abuse. Defaults to ``False``.
    ignore_links: :class:`bool`
        Whether to leave links alone when escaping markdown. For example,
        if a URL in the text contains characters such as ``_`` then it will
        be left alone. This option is not supported with ``as_needed``.
        Defaults to ``True``.

    Returns
    --------
    :class:`str`
        The text with the markdown special characters escaped with a slash.
    c                \    | j                         }|j                  d      }|r|S d|d    S )Nr   \markdownr  )r  r  is_urls      r>   r  z$escape_markdown.<locals>.replacement  s7    )I]]5)F	*-.//rA   r  r  r  r   z\\z\\\\z\\\1)r  r  r  r  r  X_MARKDOWN_ESCAPE_REGEX)r  r  r  r  r  s        r>   r-   r-     ss    6 	0 &*QugQ/Evve[$2<<"$$3FGGvveWd+%))'488rA   c                0    t        j                  dd|       S )a  A helper function that escapes everyone, here, role, and user mentions.

    .. note::

        This does not include channel mentions.

    .. note::

        For more granular control over what mentions should be escaped
        within messages, refer to the :class:`~discord.AllowedMentions`
        class.

    Parameters
    ----------
    text: :class:`str`
        The text to escape mentions from.

    Returns
    -------
    :class:`str`
        The text with the mentions removed.
    z"@(everyone|here|[!&]?[0-9]{17,20})u   @​\1)r  r  )r  s    r>   r.   r.     s    . 667tLLrA   c                f    t        j                  d|       D cg c]  }t        |       c}S c c}w )a%  Returns a list of user IDs matching ``<@user_id>`` in the string.

    .. versionadded:: 2.2

    Parameters
    ----------
    text: :class:`str`
        The string to get user mentions from.

    Returns
    -------
    List[:class:`int`]
        A list of user IDs found in the string.
    z<@!?([0-9]+)>r  findallr   r  r  s     r>   r/   r/     s(     JJ'7>?qCF???   .c                f    t        j                  d|       D cg c]  }t        |       c}S c c}w )a2  Returns a list of channel IDs matching ``<@#channel_id>`` in the string.

    .. versionadded:: 2.2

    Parameters
    ----------
    text: :class:`str`
        The string to get channel mentions from.

    Returns
    -------
    List[:class:`int`]
        A list of channel IDs found in the string.
    z<#([0-9]+)>r  r  s     r>   r0   r0     s'     JJ~t<=qCF===r  c                f    t        j                  d|       D cg c]  }t        |       c}S c c}w )a&  Returns a list of role IDs matching ``<@&role_id>`` in the string.

    .. versionadded:: 2.2

    Parameters
    ----------
    text: :class:`str`
        The string to get role mentions from.

    Returns
    -------
    List[:class:`int`]
        A list of role IDs found in the string.
    z<@&([0-9]+)>r  r  s     r>   r1   r1     s'     JJ=>qCF>>>r  c              #  x   K   g }d}| D ]&  }|j                  |       |dz  }||k(  s| g }d}( |r| y y wNr   r   appenditeratormax_sizeretnr   s        r>   _chunkr  /  sY     
C	A 

4	Q=ICA 	 s   %::c                  K   g }d}| 2 3 d {   }|j                  |       |dz  }||k(  s%| g }d}/7 *6 |r| y y wr  r  r  s        r>   _achunkr  =  sa     
C	A  d

4	Q=ICAh 	 s$   A:8:A
A:
Ac                     y rO   r;   r  r  s     r>   r2   r2   K  s    JMrA   c                     y rO   r;   r  s     r>   r2   r2   O  s    TWrA   c                r    |dk  rt        d      t        | t              rt        | |      S t	        | |      S )aY  A helper function that collects an iterator into chunks of a given size.

    .. versionadded:: 2.0

    .. warning::

        The last chunk collected may not be as large as ``max_size``.

    Parameters
    ----------
    iterator: Union[:class:`collections.abc.Iterator`, :class:`collections.abc.AsyncIterator`]
        The iterator to chunk, can be sync or async.
    max_size: :class:`int`
        The maximum chunk size.

    Returns
    -------
    Union[:class:`collections.abc.Iterator`, :class:`collections.abc.AsyncIterator`]
        A new iterator which yields chunks of a given size.
    r   z#Chunk sizes must be greater than 0.)r  r  r   r  r  r  s     r>   r2   r2   S  s;    * 1}>??(M*x**(H%%rA   )r   r"  c                    g }t        t        d         }| D ];  }t        ||      r|j                  |j                         +|j                  |       = t        |      S r`  )typer   r  extend__args__r  tuple)
parametersparamsliteral_clsps       r>   flatten_literal_paramsr  s  sV    Fwqz"K a%MM!**%MM!	
 =rA   c                J    t        d       t        fd| D              fz   S )Nc              3  ,   K   | ]  }|us|  y wrO   r;   )r   r  none_clss     r>   r   z,normalise_optional_params.<locals>.<genexpr>  s     <q!8*;<s   	)r  r  )r  r  s    @r>   normalise_optional_paramsr  ~  s$    DzH<J<<{JJrA   implicit_strc                  t        | t              r| j                  } dr9t        | t              r)| v r|    S t	        |       }|| <   t        |      S t        | d      r(dd}| j                  }t        | d      s;t        r3| j                  t        j                  u rt        |   }t        |      S | S | j                  t        u r?	 |j                  t        d             t!        |      dz
  k7  rt#        | j                        }| j                  t&        u rt        st)        | j                        }dd}t+        fd|D              }	|rt-        d |	D              st/        d      |	|k(  r| S 	 | j1                  |	      S | S # t$        $ r Y w xY w# t2        $ r | j                  |	   cY S w xY w)	NTr  F
__origin__r   c              3  >   K   | ]  }t        |         yw)r  N)evaluate_annotation)r   argcacheglobalsr  localss     r>   r   z&evaluate_annotation.<locals>.<genexpr>  s)      
  Wfe,WW
s   c           
   3  f   K   | ])  }t        |t        t        t        t	        d       f       + y wrO   )r  rI   r   rH   r  )r   r  s     r>   r   z&evaluate_annotation.<locals>.<genexpr>  s)      "
<=Jq3T4:67"
s   /1z>Literal arguments must be of type str, int, bool, or NoneType.)r  r   __forward_arg__rI   evalr  hasattrr  PY_310	__class__types	UnionTyper   r  r   r  r   r  r  r   r  r  r  	TypeError	copy_withr{   )
tpr  r  r  r  	evaluated
is_literalr   r  evaluated_argss
    ````     r>   r  r    s    "j!
2s+;9Wf-	b	"9gvuEEr:
{{r<(",,%//9!$K	*9gvuMMI==E!::d4j)SY]:4R[[AD ==G#-bkk: LJ 

 

 c "
AO"
 
 P  T!I	1<<// I9  2  	1==00	1s$   >F F$ 	F! F!$F?>F?c                    | t        d       S t        | t              rt        |       } ||n|}|i }t	        | |||      S rO   )r  r  rI   r   r  )
annotationglobalnslocalnsr  r  s        r>   resolve_annotationr    sN     Dz*c"
+
 XgF}z8VUCCrA   )rF  FdDtrp   Rc                   |dt        | j                                dS dt        | j                                d| dS )a  A helper function to format a :class:`datetime.datetime` for presentation within Discord.

    This allows for a locale-independent way of presenting data using Discord specific Markdown.

    +-------------+----------------------------+-----------------+
    |    Style    |       Example Output       |   Description   |
    +=============+============================+=================+
    | t           | 22:57                      | Short Time      |
    +-------------+----------------------------+-----------------+
    | T           | 22:57:58                   | Long Time       |
    +-------------+----------------------------+-----------------+
    | d           | 17/05/2016                 | Short Date      |
    +-------------+----------------------------+-----------------+
    | D           | 17 May 2016                | Long Date       |
    +-------------+----------------------------+-----------------+
    | f (default) | 17 May 2016 22:57          | Short Date Time |
    +-------------+----------------------------+-----------------+
    | F           | Tuesday, 17 May 2016 22:57 | Long Date Time  |
    +-------------+----------------------------+-----------------+
    | R           | 5 years ago                | Relative Time   |
    +-------------+----------------------------+-----------------+

    Note that the exact output depends on the user's locale setting in the client. The example output
    presented is using the ``en-GB`` locale.

    .. versionadded:: 2.0

    Parameters
    ----------
    dt: :class:`datetime.datetime`
        The datetime to format.
    style: :class:`str`
        The style to format the datetime with.

    Returns
    -------
    :class:`str`
        The formatted string.
    z<t:>r7  )r   r   )r   styles     r>   r3   r3     sF    P }S()++R\\^$%QugQ//rA   c                p    | xs
 t               } t        | j                         dz  t        z
        dz  dz  S )a  Returns a numeric snowflake pretending to be created at the given date but more accurate and random
    than :func:`time_snowflake`. If dt is not passed, it makes one from the current time using utcnow.

    Parameters
    ----------
    dt: :class:`datetime.datetime`
        A datetime object to convert to a snowflake.
        If naive, the timezone is assumed to be local time.

    Returns
    -------
    :class:`int`
        The snowflake representing the time given.
    r   r   r   )r)   r   r   r   )r   s    r>   r4   r4     s4      
vxBr||~$}45;hFFrA   c                     d fd}|S )a  A helper function to make a basic autocomplete for slash commands. This is a pretty standard autocomplete and
    will return any options that start with the value from the user, case-insensitive. If the ``values`` parameter is
    callable, it will be called with the AutocompleteContext.

    This is meant to be passed into the :attr:`discord.Option.autocomplete` attribute.

    Parameters
    ----------
    values: Union[Union[Iterable[:class:`.OptionChoice`], Iterable[:class:`str`], Iterable[:class:`int`], Iterable[:class:`float`]], Callable[[:class:`.AutocompleteContext`], Union[Union[Iterable[:class:`str`], Iterable[:class:`int`], Iterable[:class:`float`]], Awaitable[Union[Iterable[:class:`str`], Iterable[:class:`int`], Iterable[:class:`float`]]]]], Awaitable[Union[Iterable[:class:`str`], Iterable[:class:`int`], Iterable[:class:`float`]]]]
        Possible values for the option. Accepts an iterable of :class:`str`, a callable (sync or async) that takes a
        single argument of :class:`.AutocompleteContext`, or a coroutine. Must resolve to an iterable of :class:`str`.

    Returns
    -------
    Callable[[:class:`.AutocompleteContext`], Awaitable[Union[Iterable[:class:`.OptionChoice`], Iterable[:class:`str`], Iterable[:class:`int`], Iterable[:class:`float`]]]]
        A wrapped callback for the autocomplete.

    Note
    ----
    Autocomplete cannot be used for options that have specified choices.

    Example
    -------

    .. code-block:: python3

        Option(str, "color", autocomplete=basic_autocomplete(("red", "green", "blue")))

        # or

        async def autocomplete(ctx):
            return "foo", "bar", "baz", ctx.interaction.user.name

        Option(str, "name", autocomplete=basic_autocomplete(autocomplete))

    .. versionadded:: 2.0
    c                    K   }t        |      r |       }t        j                  |      r
| d {   }d fdfd|D        }t        t	        j
                  |d            S 7 4w)Nc                    t        | d|       } t        |       j                         j                  t        j                  xs d      j                               S )Nrv   r  )rX   rI   lowerr%  r_   )r   ctxs    r>   rH  z@basic_autocomplete.<locals>.autocomplete_callback.<locals>.checkN  sC    4.Dt9??$//CIIO0D0J0J0LMMrA   c              3  4   K   | ]  } |      s|  y wrO   r;   )r   valrH  s     r>   r   zDbasic_autocomplete.<locals>.autocomplete_callback.<locals>.<genexpr>R  s     4sss4s      r   )callabler   iscoroutiner   	itertoolsislice)r  _valuesrJ  rH  valuess   `  @r>   autocomplete_callbackz1basic_autocomplete.<locals>.autocomplete_callbackF  sa     GclGw'#mG	N 5g4I$$S"-.. $s   0A,A*5A,)r  rc   rG   Vr;   )r  r  s   ` r>   r5   r5     s    N/ ! rA   c                    |j                         D ]2  \  }}|| v s|| j                  |       | j                  |      | |<   4 | S )a  A helper function to filter out and replace certain keyword parameters

    Parameters
    ----------
    params: Dict[str, Any]
        The initial parameters to filter.
    **kwargs: Dict[str, Optional[str]]
        Key to value pairs where the key's contents would be moved to the
        value, or if the value is None, remove key's contents (see code example).

    Example
    -------
    .. code-block:: python3

        >>> params = {"param1": 12, "param2": 13}
        >>> filter_params(params, param1="param3", param2=None)
        {'param3': 12}
        # values of 'param1' is moved to 'param3'
        # and values of 'param2' are completely removed.
    )r  pop)r  r   	old_param	new_params       r>   r6   r6   X  sR    * !' :	9 

9%$*JJy$9y!: MrA   )rv   rI   rG   z<Callable[[Callable[[T], T_co]], CachedSlotProperty[T, T_co]])r   r=  r   r   )r   r}   rG   r}   )r   rI   rG   datetime.datetime)r   
str | NonerG   datetime.datetime | None)r   r   rG   zCallable[[T], T])NNNNr   )rv   rI   r   r  r   r  r   r  r   r  r   r   rG   r}   )r   r  r   r  r   r  r   r  r   r   r   rH   rG   z.Callable[[Callable[[P], T]], Callable[[P], T]])r   z	int | strr   rg   r   rb   r   rI   r   zIterable[str]r   rH   rG   rI   )r   r   rG   r  )F)r   r  r   rH   rG   r   )r   zCallable[[T], Any]r   Iterable[T]rG   r   )r  r  r  r   rG   r   )r  rI   r   r   r   r   rG   r   )r  r  rG   zlist[T])r  r   r  rI   rG   r  )r  bytes)r  r  rG   rI   )r  r   rG   rI   )r@  r   r;  rH   rG   r=  )r\  r   rG   zIterator[str])r   r  rO   )rf  r  rg  r   rG   r   )rG   r  )rl  r   rG   rH   )r  rI   rG   r   )r  zInvite | strrG   rI   )r  zTemplate | strrG   rI   )r  rI   r  rH   rG   rI   )r  rI   r  rH   r  rH   rG   rI   )r  rI   rG   rI   )r  rI   rG   z	list[int])r  zIterator[T]r  r   rG   zIterator[list[T]])r  zAsyncIterator[T]r  r   rG   zAsyncIterator[list[T]])r  z_Iter[T]r  r   rG   z_Iter[list[T]])r  zIterable[Any]rG   ztuple[Any, ...])
r  r   r  dict[str, Any]r  r  r  r  r  rH   )
r  r   r  r  r  dict[str, Any] | Noner  r  rG   r   )r  zTimestampStyle | Noner   r  rG   rI   )r   r  rG   r   )r  ValuesrG   AutocompleteFunc)rV   
__future__r   rt  r   collections.abccollectionsr   r   r  r1  r  sysr  r  r   base64r   bisectr   dataclassesr   inspectr   rE  r   r   operatorr	   typingr
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   errorsr   r   r0  HAS_MSGSPECModuleNotFoundError__all__r   r8   rM   rm   MissingFieldrS   typing_extensionsra   abcrb   commands.contextrc   commands.optionsrd   r  rf   r   rg   r  ri   rk   propertyrn   ro   rp   rq   _Iterrt   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r  r  r&  r.  r4  r*  
_from_jsonloadsrC  rG  rK  rX  r^  rd  r(   r)   rm  ro  compiler  r  r*   r+   r   _MARKDOWN_ESCAPE_SUBREGEX_MARKDOWN_ESCAPE_LINKS_MARKDOWN_ESCAPE_COMMONr  r  r  r  r  r,   r-   r.   r/   r0   r1   r  r  r2   version_infor  r  r  r  r  TimestampStyler3   r4   rI   r   r=  r  AVr  r  r5   r6   r;   rA   r>   <module>r>     s  2 #        	 
       / +     * 3 K6    ! !
 _5  +5.("#x # /:O#A 'OL CLv&hqk=++,D) 45GDM 5
A+GDM;??#;#; +8& 
 , 
 , 
 8 
 8 
 F 
 F$  *9
*9*9 *9 	*9
 *9 *9 
*9\  0 000 0 	0
 0 0 40l  '#!&11 1 	1
 1 1 1 	1hP"?44@F CJ 9x0$
>+ 8 $$JI J @E 	) #/ 	..*8 8
5EKK 5D BJJ()	 -6 T26  HH %;T%    **@)AB #./q1H0IKLL244 
 Y
34K3LAN  8< =F %**9
*9!*99=*9*9ZM4@$>$?$ 
 M 
 M 
 W 
 W&: 
		W	$K >>> > 	> >BDDD #D !	D
 	D" :;*0ZG( 
(<
 (3-#
OPq\	q(/0%2,>?C	D01256 6!rc(  Ks   N; ;OO