
    iG                       d 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 ddlZddlmZ ddlmZmZmZmZmZmZ dd	lmZ dd
lmZ ddlmZmZmZ  e
d          Z erEddl!m"Z"m#Z# ddl$m%Z% ddlm&Z& ee	e%e         geeee f         f         e	e%e         ge f         f         Z'dZ( G d d          Z)d*dZ*d+dZ+d,dZ,d,dZ-d-d"Z.ed#d.d(Z/ed#d/d)Z0dS )0a:  
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.
    )annotations)	Any	CoroutineDictHashableUnionCallableTypeVarOptionalTYPE_CHECKINGN   check)NoPrivateMessageMissingRoleMissingAnyRoleMissingPermissionsBotMissingPermissionsCommandOnCooldown   )User)Permissions)getMISSINGmaybe_coroutineT)SelfUnpack)Interaction)_PermissionsKwargs)has_rolehas_any_rolehas_permissionsbot_has_permissionscooldowndynamic_cooldownc                  Z    e Zd ZdZdZddZdddZdddZdddddZddZ	ddZ
ddZd	S ) Cooldowna  Represents a cooldown for a command.

    .. versionadded:: 2.0

    Attributes
    -----------
    rate: :class:`float`
        The total number of tokens available per :attr:`per` seconds.
    per: :class:`float`
        The length of the cooldown period in seconds.
    )rateper_window_tokens_lastr)   floatr*   returnNonec                    t          |          | _        t          |          | _        d| _        | j        | _        d| _        d S )N        )intr)   r.   r*   r+   r,   r-   )selfr)   r*   s      \/usr/local/lib/hermes-agent/venv/lib/python3.11/site-packages/discord/app_commands/checks.py__init__zCooldown.__init__\   s7    T	**! I


    NcurrentOptional[float]r3   c                    |st          j                     }t          | j        d          }|| j        | j        z   k    r| j        }|S )a  Returns the number of available tokens before rate limiting is applied.

        Parameters
        ------------
        current: Optional[:class:`float`]
            The time in seconds since Unix epoch to calculate tokens at.
            If not supplied then :func:`time.time()` is used.

        Returns
        --------
        :class:`int`
            The number of tokens available before the cooldown is to be applied.
        r   )timemaxr,   r+   r*   r)   r4   r8   tokenss      r5   
get_tokenszCooldown.get_tokensc   sJ      	"ikkG T\1%%T\DH,,,YFr7   c                    |pt          j                     }|                     |          }|dk    r| j        || j        z
  z
  S dS )a  Returns the time in seconds until the cooldown will be reset.

        Parameters
        -------------
        current: Optional[:class:`float`]
            The current time in seconds since Unix epoch.
            If not supplied, then :func:`time.time()` is used.

        Returns
        -------
        :class:`float`
            The number of seconds to wait before this cooldown will be reset.
        r   r2   )r;   r?   r*   r+   r=   s      r5   get_retry_afterzCooldown.get_retry_after{   sG     (TY[[))Q;;8w566sr7   r   )r>   r>   c                   |pt          j                     }|| _        |                     |          | _        | j        | j        k    r|| _        | xj        |z  c_        | j        dk     r| j        || j        z
  z
  S dS )a  Updates the cooldown rate limit.

        Parameters
        -------------
        current: Optional[:class:`float`]
            The time in seconds since Unix epoch to update the rate limit at.
            If not supplied, then :func:`time.time()` is used.
        tokens: :class:`int`
            The amount of tokens to deduct from the rate limit.

        Returns
        -------
        Optional[:class:`float`]
            The retry-after time in seconds if rate limited.
        r   N)r;   r-   r?   r,   r)   r+   r*   r=   s      r5   update_rate_limitzCooldown.update_rate_limit   s      (TY[[
w// <49$$"DL 	 <!8w566 r7   c                ,    | j         | _        d| _        dS )z(Reset the cooldown to its initial state.r2   N)r)   r,   r-   r4   s    r5   resetzCooldown.reset   s    y


r7   r   c                B    |                      | j        | j                  S )zCreates a copy of this cooldown.

        Returns
        --------
        :class:`Cooldown`
            A new instance of this cooldown.
        )	__class__r)   r*   rE   s    r5   copyzCooldown.copy   s     ~~di222r7   strc           	     H    d| j          d| j         d| j         d| j         d	S )Nz<Cooldown rate: z per: z	 window: z	 tokens: >)r)   r*   r+   r,   rE   s    r5   __repr__zCooldown.__repr__   s5    l$)ll48lldlll]a]illllr7   )r)   r.   r*   r.   r/   r0   N)r8   r9   r/   r3   )r8   r9   r/   r.   )r8   r9   r>   r3   r/   r9   )r/   r0   )r/   r   )r/   rJ   )__name__
__module____qualname____doc__	__slots__r6   r?   rA   rC   rF   rI   rM    r7   r5   r(   r(   M   s        
 
 ?I           0    ,7RS 7 7 7 7 7 7@   
3 3 3 3m m m m m mr7   r(   itemUnion[int, str]r/   Callable[[T], T]c               .     d fd}t          |          S )a  A :func:`~discord.app_commands.check` that is added that checks if the member invoking the
    command has the role specified via the name or ID specified.

    If a string is specified, you must give the exact name of the role, including
    caps and spelling.

    If an integer is specified, you must give the exact snowflake ID of the role.

    This check raises one of two special exceptions, :exc:`~discord.app_commands.MissingRole`
    if the user is missing a role, or :exc:`~discord.app_commands.NoPrivateMessage` if
    it is used in a private message. Both inherit from :exc:`~discord.app_commands.CheckFailure`.

    .. versionadded:: 2.0

    .. note::

        This is different from the permission system that Discord provides for application
        commands. This is done entirely locally in the program rather than being handled
        by Discord.

    Parameters
    -----------
    item: Union[:class:`int`, :class:`str`]
        The name or ID of the role to check.
    interactionr   r/   boolc                   t          | j        t                    rt                      t          t                    r| j                                      }nt          | j        j                  }|t                    dS )NnameT)	
isinstanceuserr   r   r3   get_role	utils_getrolesr   )rY   rolerU   s     r5   	predicatezhas_role.<locals>.predicate   s    k&-- 	%"$$$dC   	@#,,T22DD[-3$???D<d###tr7   rY   r   r/   rZ   r   )rU   rd   s   ` r5   r!   r!      s1    6      r7   itemsc                 .     d fd}t          |          S )a0  A :func:`~discord.app_commands.check` that is added that checks if the member
    invoking the command has **any** of the roles specified. This means that if they have
    one out of the three roles specified, then this check will return ``True``.

    Similar to :func:`has_role`\, the names or IDs passed in must be exact.

    This check raises one of two special exceptions, :exc:`~discord.app_commands.MissingAnyRole`
    if the user is missing all roles, or :exc:`~discord.app_commands.NoPrivateMessage` if
    it is used in a private message. Both inherit from :exc:`~discord.app_commands.CheckFailure`.

    .. versionadded:: 2.0

    .. note::

        This is different from the permission system that Discord provides for application
        commands. This is done entirely locally in the program rather than being handled
        by Discord.

    Parameters
    -----------
    items: List[Union[:class:`str`, :class:`int`]]
        An argument list of names or IDs to check that the member has roles wise.

    Example
    --------

    .. code-block:: python3

        @tree.command()
        @app_commands.checks.has_any_role('Library Devs', 'Moderators', 492212595072434186)
        async def cool(interaction: discord.Interaction):
            await interaction.response.send_message('You are cool indeed')
    rY   r   r/   rZ   c                     t           j        t                    rt                      t	           fdD                       rdS t          t                              )Nc              3     K   | ]R}t          |t                    rj                            |          d unt	          j        j        |          d uV  Sd S )Nr\   )r^   r3   r_   r`   ra   rb   ).0rU   rY   s     r5   	<genexpr>z2has_any_role.<locals>.predicate.<locals>.<genexpr>  s       
 
  $$$JK%%d++477;+1===TI
 
 
 
 
 
r7   T)r^   r_   r   r   anyr   list)rY   rf   s   `r5   rd   zhas_any_role.<locals>.predicate  sz    k&-- 	%"$$$ 
 
 
 
 	
 
 
 
 
 	 4T%[[)))r7   re   r   )rf   rd   s   ` r5   r"   r"      s2    F* * * * * * r7   permsUnpack[_PermissionsKwargs]c                                                        t          j                                         z
  }|r%t          dd                    |                     d fd}t          |          S )	a  A :func:`~discord.app_commands.check` that is added that checks if the member
    has all of the permissions necessary.

    Note that this check operates on the permissions given by
    :attr:`discord.Interaction.permissions`.

    The permissions passed in must be exactly like the properties shown under
    :class:`discord.Permissions`.

    This check raises a special exception, :exc:`~discord.app_commands.MissingPermissions`
    that is inherited from :exc:`~discord.app_commands.CheckFailure`.

    .. versionadded:: 2.0

    .. note::

        This is different from the permission system that Discord provides for application
        commands. This is done entirely locally in the program rather than being handled
        by Discord.

    Parameters
    ------------
    \*\*perms: :class:`bool`
        Keyword arguments denoting the permissions to check for.

    Example
    ---------

    .. code-block:: python3

        @tree.command()
        @app_commands.checks.has_permissions(manage_messages=True)
        async def test(interaction: discord.Interaction):
            await interaction.response.send_message('You can manage messages.')

    Invalid permission(s): , rY   r   r/   rZ   c                z    | j         fd                                D             }|sdS t          |          )Nc                B    g | ]\  }}t          |          |k    |S rT   getattrrj   permvaluepermissionss      r5   
<listcomp>z6has_permissions.<locals>.predicate.<locals>.<listcomp>O  3    ```KD%GKQU<V<VZ_<_<_4<_<_<_r7   T)rz   rf   r   rY   missingrz   rn   s     @r5   rd   z"has_permissions.<locals>.predicateL  sH    !-````5;;==``` 	4 )))r7   re   )keysr   VALID_FLAGS	TypeErrorjoinr   rn   invalidrd   s   `  r5   r#   r#   "  s    L jjll[499;;;G HF$))G2D2DFFGGG* * * * * * r7   c                      t                     t          t          j                  z
  }|r%t          dd                    |                     d fd}t          |          S )	ac  Similar to :func:`has_permissions` except checks if the bot itself has
    the permissions listed. This relies on :attr:`discord.Interaction.app_permissions`.

    This check raises a special exception, :exc:`~discord.app_commands.BotMissingPermissions`
    that is inherited from :exc:`~discord.app_commands.CheckFailure`.

    .. versionadded:: 2.0
    rq   rr   rY   r   r/   rZ   c                z    | j         fd                                D             }|sdS t          |          )Nc                B    g | ]\  }}t          |          |k    |S rT   ru   rw   s      r5   r{   z:bot_has_permissions.<locals>.predicate.<locals>.<listcomp>i  r|   r7   T)app_permissionsrf   r   r}   s     @r5   rd   z&bot_has_permissions.<locals>.predicateg  sH    !1````5;;==``` 	4#G,,,r7   re   )setr   r   r   r   r   r   s   `  r5   r$   r$   Y  sz     %jj3{6777G HF$))G2D2DFFGGG- - - - - - r7   keyCooldownFunction[Hashable]factory$CooldownFunction[Optional[Cooldown]]c                D    i }|| |ddddfd}t          |          S )N)mappingr   r   rY   r   r   Dict[Any, Cooldown]r   r   r   r   r/   Optional[Cooldown]c                 K   | j                                         fd|                                D             }|D ]}||= t          ||            d {V }||vrt          ||            d {V }||||<   n||         }|S )Nc                @    g | ]\  }}|j         |j        z   k    |S rT   )r-   r*   )rj   kvr8   s      r5   r{   zB_create_cooldown_decorator.<locals>.get_bucket.<locals>.<listcomp>  s/    PPP41ag!%6O6OQ6O6O6Or7   )
created_at	timestamprf   r   )rY   r   r   r   	dead_keysr   bucketr8   s          @r5   
get_bucketz._create_cooldown_decorator.<locals>.get_bucketx  s       (2244PPPP7==??PPP	 	 	A

!#{33333333G/>w/T/T)T)T)T)T)T)TF!#
QZFr7   rZ   c                   K    |            d {V }|dS |                     | j                                                  }|dS t          ||          )NT)rC   r   r   r   )rY   r   retry_afterr   s      r5   rd   z-_create_cooldown_decorator.<locals>.predicate  so      !z+........>4..{/E/O/O/Q/QRR4444r7   )
rY   r   r   r   r   r   r   r   r/   r   re   r   )r   r   r   rd   r   s       @r5   _create_cooldown_decoratorr   s  sa     $&G
 (/*-8?     ,	5 	5 	5 	5 	5 	5 r7   )r   r)   r.   r*   $Optional[CooldownFunction[Hashable]]c               \     |t           u rd }n|d }n|} fd}t          ||          S )aF  A decorator that adds a cooldown to a command.

    A cooldown allows a command to only be used a specific amount
    of times in a specific time frame. These cooldowns are based off
    of the ``key`` function provided. If a ``key`` is not provided
    then it defaults to a user-level cooldown. The ``key`` function
    must take a single parameter, the :class:`discord.Interaction` and
    return a value that is used as a key to the internal cooldown mapping.

    The ``key`` function can optionally be a coroutine.

    If a cooldown is triggered, then :exc:`~discord.app_commands.CommandOnCooldown` is
    raised to the error handlers.

    Examples
    ---------

    Setting a one per 5 seconds per member cooldown on a command:

    .. code-block:: python3

        @tree.command()
        @app_commands.checks.cooldown(1, 5.0, key=lambda i: (i.guild_id, i.user.id))
        async def test(interaction: discord.Interaction):
            await interaction.response.send_message('Hello')

        @test.error
        async def on_test_error(interaction: discord.Interaction, error: app_commands.AppCommandError):
            if isinstance(error, app_commands.CommandOnCooldown):
                await interaction.response.send_message(str(error), ephemeral=True)

    Parameters
    ------------
    rate: :class:`int`
        The number of times a command can be used before triggering a cooldown.
    per: :class:`float`
        The amount of seconds to wait for a cooldown when it's been triggered.
    key: Optional[Callable[[:class:`discord.Interaction`], :class:`collections.abc.Hashable`]]
        A function that returns a key to the mapping denoting the type of cooldown.
        Can optionally be a coroutine. If not given then defaults to a user-level
        cooldown. If ``None`` is passed then it is interpreted as a "global" cooldown.
    c                    | j         j        S rN   r_   idrY   s    r5   <lambda>zcooldown.<locals>.<lambda>      {'7': r7   Nc                    d S rN   rT   is    r5   r   zcooldown.<locals>.<lambda>      T r7   c                $    t                    S rN   )r(   )rY   r*   r)   s    r5   r   zcooldown.<locals>.<lambda>  s    (4"5"5 r7   r   r   )r)   r*   r   key_funcr   s   ``   r5   r%   r%     sN    b g~~::	!>55555G%h888r7   c               L    |t           u rd }n|d }n|}t          ||           S )a	  A decorator that adds a dynamic cooldown to a command.

    A cooldown allows a command to only be used a specific amount
    of times in a specific time frame. These cooldowns are based off
    of the ``key`` function provided. If a ``key`` is not provided
    then it defaults to a user-level cooldown. The ``key`` function
    must take a single parameter, the :class:`discord.Interaction` and
    return a value that is used as a key to the internal cooldown mapping.

    If a ``factory`` function is given, it must be a function that
    accepts a single parameter of type :class:`discord.Interaction` and must
    return a :class:`~discord.app_commands.Cooldown` or ``None``.
    If ``None`` is returned then that cooldown is effectively bypassed.

    Both ``key`` and ``factory`` can optionally be coroutines.

    If a cooldown is triggered, then :exc:`~discord.app_commands.CommandOnCooldown` is
    raised to the error handlers.

    Examples
    ---------

    Setting a cooldown for everyone but the owner.

    .. code-block:: python3

        def cooldown_for_everyone_but_me(interaction: discord.Interaction) -> Optional[app_commands.Cooldown]:
            if interaction.user.id == 80088516616269824:
                return None
            return app_commands.Cooldown(1, 10.0)

        @tree.command()
        @app_commands.checks.dynamic_cooldown(cooldown_for_everyone_but_me)
        async def test(interaction: discord.Interaction):
            await interaction.response.send_message('Hello')

        @test.error
        async def on_test_error(interaction: discord.Interaction, error: app_commands.AppCommandError):
            if isinstance(error, app_commands.CommandOnCooldown):
                await interaction.response.send_message(str(error), ephemeral=True)

    Parameters
    ------------
    factory: Optional[Callable[[:class:`discord.Interaction`], Optional[:class:`~discord.app_commands.Cooldown`]]]
        A function that takes an interaction and returns a cooldown that will apply to that interaction
        or ``None`` if the interaction should not have a cooldown.
    key: Optional[Callable[[:class:`discord.Interaction`], :class:`collections.abc.Hashable`]]
        A function that returns a key to the mapping denoting the type of cooldown.
        Can optionally be a coroutine. If not given then defaults to a user-level
        cooldown. If ``None`` is passed then it is interpreted as a "global" cooldown.
    c                    | j         j        S rN   r   r   s    r5   r   z"dynamic_cooldown.<locals>.<lambda>  r   r7   Nc                    d S rN   rT   r   s    r5   r   z"dynamic_cooldown.<locals>.<lambda>  r   r7   r   )r   r   r   s      r5   r&   r&     s;    r g~~::	!>%h888r7   )rU   rV   r/   rW   )rf   rV   r/   rW   )rn   ro   r/   rW   )r   r   r   r   r/   rW   )r)   r.   r*   r.   r   r   r/   rW   )r   r   r   r   r/   rW   )1rR   
__future__r   typingr   r   r   r   r   r	   r
   r   r   r;   commandsr   errorsr   r   r   r   r   r   r_   r   rz   r   utilsr   ra   r   r   r   typing_extensionsr   r   interactionsr   r    CooldownFunction__all__r(   r!   r"   r#   r$   r   r%   r&   rT   r7   r5   <module>r      s   0 # " " " " "
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
                             % % % % % % > > > > > > > > > >GCLL ........******000000+c"#YsC{%;;<+c"#Q&'	)
tm tm tm tm tm tm tm tmn( ( ( (V0 0 0 0f4 4 4 4n   4& & & &Z 18	:9 :9 :9 :9 :9 :9@ 18@9 @9 @9 @9 @9 @9 @9 @9r7   