
    cjhK?                       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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 ddlmZ dd	lmZmZ dd
lmZ erddlmZ ddlmZ dZej>                  j@                  Z de!d<    ed      Z" edd      Z# edd      Z$ddZ%	 	 	 	 d dZ&d!dZ' G d deejP                  jR                        Z* G d de*ejV                        Z+ G d de*ejX                        Z,y)"ae  
The MIT License (MIT)

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

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

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

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
    )annotationsN)TYPE_CHECKINGAnyCallable	CoroutineIterableTypeVar   )errors)Context)
GroupMixin)DefaultHelpCommandHelpCommand)
StringView)Message)CoroFunc)when_mentionedwhen_mentioned_orBotAutoShardedBotr   MISSINGTCFTr   )boundCXTr   c                j    d| j                   j                   dd| j                   j                   dgS )zA callable that implements a command prefix equivalent to being mentioned.

    These are meant to be passed into the :attr:`.Bot.command_prefix` attribute.
    z<@z> z<@!)userid)botmsgs     K/var/www/html/venv/lib/python3.12/site-packages/discord/ext/commands/bot.pyr   r   =   s1     R C}B"788    c                       fd}|S )a  A callable that implements when mentioned or other prefixes provided.

    These are meant to be passed into the :attr:`.Bot.command_prefix` attribute.

    See Also
    --------
    :func:`.when_mentioned`

    Example
    -------

    .. code-block:: python3

        bot = commands.Bot(command_prefix=commands.when_mentioned_or('!'))

    .. note::

        This callable returns another callable, so if this is done inside a custom
        callable, you must call the returned callable, for example:

        .. code-block:: python3

            async def get_prefix(bot, message):
                extras = await prefixes_for(message.guild) # returns a list
                return commands.when_mentioned_or(*extras)(bot, message)
    c                <    t              }t        | |      |z   }|S N)listr   )r   r    rprefixess      r!   innerz when_mentioned_or.<locals>.innerd   s"    N3$q(r"    )r(   r)   s   ` r!   r   r   F   s    <
 Lr"   c                8    | |k(  xs |j                  |  d      S )N.)
startswith)parentchilds     r!   _is_submoduler0   l   s"    U?<e..&|<<r"   c                  *    e Zd ZdZdZeef	 	 	 d fdZej                  j                  ej                  j                        d fd       Z	 	 	 	 	 	 ddZddddZedd	       Zej"                  dd
       ZddZedddZddZddZd Z xZS )BotBaseNTc                    t        |   di | || _        |t        u r
t	               n|| _        |j                  dd      | _        y )Nstrip_after_prefixFr*   )super__init__command_prefixr   r   help_commandgetr4   )selfr7   r8   options	__class__s       r!   r6   zBotBase.__init__t   sK     	#7#,$0G$;  	 #*++.BE"Jr"   c                *  K   t        | j                        D ]  }	 | j                  |        t        | j                        D ]  }	 | j                  |        t        |           d {    y # t        $ r Y ew xY w# t        $ r Y Hw xY w7 #wr%   )tuple_BotBase__extensionsunload_extension	Exception_BotBase__cogs
remove_cogr5   close)r:   	extensioncogr<   s      r!   rD   zBotBase.close   s     t001 	I%%i0	 % 	C$	 gmo     	sW   BA3B	BB-B.B3	A?<B>A??B	BBBBc                  K   | j                   j                  dd      ry|j                  }|r|j                         ry|j                  }|r|j                         ryt        d|j                   dt        j                         t        j                  t        |      ||j                  t        j                         yw)a!  |coro|

        The default command error handler provided by the bot.

        By default, this prints to :data:`sys.stderr` however it could be
        overridden to have a different implementation.

        This only fires if you do not specify any listeners for command error.
        on_command_errorNzIgnoring exception in command :)file)_event_handlersr9   commandhas_error_handlerrF   printsysstderr	tracebackprint_exceptiontype__traceback__)r:   context	exceptionrL   rF   s        r!   rH   zBotBase.on_command_error   s      ##$6=//w002kk3((*.w.?qA

S!!OY	(?(?cjj	
s   C CF	call_oncec                  K   |r| j                   n| j                  }t        |      dk(  ryt        j                  j                  fd|D               d {   S 7 w)Nr   Tc              3  .   K   | ]  } |        y wr%   r*   ).0fctxs     r!   	<genexpr>z"BotBase.can_run.<locals>.<genexpr>   s     ,BQsV,Bs   )_check_once_checkslendiscordutils	async_all)r:   r]   rX   datas    `  r!   can_runzBotBase.can_run   sK     #,t$,,t9> ]],,,BT,BBBBBs   AAAAc                    | j                   S r%   )_help_command)r:   s    r!   r8   zBotBase.help_command   s    !!!r"   c                *   |[t        |t              st        d      | j                  | j                  j	                  |        || _        |j                  |        y | j                  #| j                  j	                  |        d | _        y d | _        y )Nz.help_command must be a subclass of HelpCommand)
isinstancer   	TypeErrorrh   _remove_from_bot_add_to_bot)r:   values     r!   r8   zBotBase.help_command   s    e[1 PQQ!!-""33D9!&Dd#+//5!%D!%Dr"   c                  K   | j                   x}}t        |      r)t        j                  j	                  || |       d{   }t        |t              s	 t        |      }|st        d      |S 7 /# t        $ rH t        |t        j                  j                        r t        d|j                  j                         w xY ww)a  |coro|

        Retrieves the prefix the bot is listening to
        with the message as a context.

        Parameters
        ----------
        message: :class:`discord.Message`
            The message context to get the prefix of.

        Returns
        -------
        Union[List[:class:`str`], :class:`str`]
            A list of prefixes or a single prefix that the bot is
            listening for.
        Nzecommand_prefix must be plain string, iterable of strings, or callable returning either of these, not z8Iterable command_prefix must contain at least one prefix)r7   callablerb   rc   maybe_coroutinerj   strr&   rk   collectionsabcr   r<   __name__
ValueError)r:   messageprefixrets       r!   
get_prefixzBotBase.get_prefix   s     " ***F55fdGLLC#s#3i  N  
+ M
  	 c;??#;#;<@@C@V@V?WY 	s*   >C A0CA2 !C2ACC)clsc               z  K   t        |j                        } |d|| |      }|j                  j                  | j                  j                  k(  r|S | j                  |       d{   }|}t        |t              r|j                  |      sU|S 	 |j                  j                  t        |            r+t        j                  j                  |j                  |      }n|S 	 | j$                  r|j'                          |j)                         }||_        ||_        | j.                  j1                  |      |_        |S 7 # t        $ rm t        |t              s"t        d|j                   j"                         |D ]4  }t        |t              rt        d|j                   j"                           w xY ww)a  |coro|

        Returns the invocation context from the message.

        This is a more low-level counter-part for :meth:`.process_commands`
        to allow users more fine-grained control over the processing.

        The returned context is not guaranteed to be a valid invocation
        context, :attr:`.Context.valid` must be checked to make sure it is.
        If the context is not valid then it is not a valid candidate to be
        invoked under :meth:`~.Bot.invoke`.

        Parameters
        -----------
        message: :class:`discord.Message`
            The message to get the invocation context from.
        cls
            The factory class that will be used to create the context.
            By default, this is :class:`.Context`. Should a custom
            class be provided, it must be similar enough to :class:`.Context`\'s
            interface.

        Returns
        --------
        :class:`.Context`
            The invocation context. The type of this can change via the
            ``cls`` parameter.
        N)rx   viewr   rw   z@get_prefix must return either a string or a list of string, not zXIterable command_prefix or list returned from get_prefix must contain only strings, not )r   contentauthorr   r   rz   rj   rr   skip_stringr-   r>   rb   rc   findrk   r&   r<   ru   r4   skip_wsget_wordinvoked_withrx   prefixed_commandsr9   rL   )	r:   rw   r{   r}   r]   rx   invoked_prefixrn   invokers	            r!   get_contextzBotBase.get_context   s    < '//*DdGD>>		,Jw//fc"##F+
 ??--eFm<%,]]%7%78H8H&%QNJ #. ""LLN--/"#
,,009
U 0  !&$/#%//889;  $ E%eS1'  % 8 89;  #s3   A%F;'E ()F;AE "AF;AF8%F88F;c                2  K   |j                   {| j                  d|       	 | j                  |d       d{   r$|j                   j                  |       d{    nt	        j
                  d      	 | j                  d|       y|j                  r7t	        j                  d|j                   d      }| j                  d	||       yy7 7 t# t        j                  $ r/}|j                   j                  ||       d{  7   Y d}~yd}~ww xY ww)
a  |coro|

        Invokes the command given under the invocation context and
        handles all the internal event dispatch mechanisms.

        Parameters
        ----------
        ctx: :class:`.Context`
            The invocation context to invoke.
        NrL   TrW   z'The global check once functions failed.command_completionz	Command "z" is not foundcommand_error)
rL   dispatchrf   invoker   CheckFailureCommandErrordispatch_errorr   CommandNotFound)r:   r]   excs      r!   r   zBotBase.invokeN  s      ;;"MM)S)9cT:::++,,S111 --.WXX 2 2C8((9S5E5E4Fn)UVCMM/34  ;1 && ;kk00c:::;s]   DC C"C CC 7ADC C D%DDD
DDDc                   K   |j                   j                  ry| j                  |       d{   }| j                  |       d{    y7 7 w)a@  |coro|

        This function processes the commands that have been registered
        to the bot and other groups. Without this coroutine, none of the
        commands will be triggered.

        By default, this coroutine is called inside the :func:`.on_message`
        event. If you choose to override the :func:`.on_message` event, then
        you should invoke this coroutine as well.

        This is built using other low level tools, and is equivalent to a
        call to :meth:`~.Bot.get_context` followed by a call to :meth:`~.Bot.invoke`.

        This also checks if the message's author is a bot and doesn't
        call :meth:`~.Bot.get_context` or :meth:`~.Bot.invoke` if so.

        Parameters
        ----------
        message: :class:`discord.Message`
            The message to process commands for.
        N)r   r   r   r   )r:   rw   r]   s      r!   process_commandszBotBase.process_commandsh  sF     , >>$$W--kk# .s!   ,AAAAAAc                B   K   | j                  |       d {    y 7 wr%   )r   )r:   rw   s     r!   
on_messagezBotBase.on_message  s     ##G,,,s   )r7   zstr | Iterable[str] | Callable[[Bot | AutoShardedBot, Message], str | Iterable[str] | Coroutine[Any, Any, str | Iterable[str]]]r8   HelpCommand | None)returnNone)rU   r   rV   zerrors.CommandErrorr   r   )r]   r   rX   boolr   r   )r   r   )rn   r   r   r   )rw   r   r   zlist[str] | str)rw   r   r{   z	type[CXT]r   r   )r]   r   r   r   )rw   r   r   r   )ru   
__module____qualname__rh   _supports_prefixed_commandsr   r   r6   rb   rc   copy_docClientrD   rH   rf   propertyr8   setterrz   r   r   r   r   r   __classcell__)r<   s   @r!   r2   r2   p   s    M"& +2KK )K( ]]GNN001 2

+>
	
8 @E C " " & & (T GN N`548-r"   r2   c                      e Zd ZdZy)r   aP  Represents a discord bot.

    This class is a subclass of :class:`discord.Bot` and as a result
    anything that you can do with a :class:`discord.Bot` you can do with
    this bot.

    This class also subclasses :class:`.GroupMixin` to provide the functionality
    to manage commands.

    .. note::

        Using prefixed commands requires :attr:`discord.Intents.message_content` to be enabled.

    Attributes
    ----------
    command_prefix
        The command prefix is what the message content must contain initially
        to have a command invoked. This prefix could either be a string to
        indicate what the prefix should be, or a callable that takes in the bot
        as its first parameter and :class:`discord.Message` as its second
        parameter and returns the prefix. This is to facilitate "dynamic"
        command prefixes. This callable can be either a regular function or
        a coroutine.

        An empty string as the prefix always matches, enabling prefix-less
        command invocation. While this may be useful in DMs it should be avoided
        in servers, as it's likely to cause performance issues and unintended
        command invocations.

        The command prefix could also be an iterable of strings indicating that
        multiple checks for the prefix should be used and the first one to
        match will be the invocation prefix. You can get this prefix via
        :attr:`.Context.prefix`. To avoid confusion empty iterables are not
        allowed.

        .. note::

            When passing multiple prefixes be careful to not pass a prefix
            that matches a longer prefix occurring later in the sequence.  For
            example, if the command prefix is ``('!', '!?')``  the ``'!?'``
            prefix will never be matched to any message as the previous one
            matches messages starting with ``!?``. This is especially important
            when passing an empty string, it should always be last as no prefix
            after it will be matched.
    case_insensitive: :class:`bool`
        Whether the commands should be case-insensitive. Defaults to ``False``. This
        attribute does not carry over to groups. You must set it to every group if
        you require group commands to be case-insensitive as well.
    help_command: Optional[:class:`.HelpCommand`]
        The help command implementation to use. This can be dynamically
        set at runtime. To remove the help command pass ``None``. For more
        information on implementing a help command, see :ref:`ext_commands_help_command`.
    strip_after_prefix: :class:`bool`
        Whether to strip whitespace characters after encountering the command
        prefix. This allows for ``!   hello`` and ``!hello`` to both work if
        the ``command_prefix`` is set to ``!``. Defaults to ``False``.

        .. versionadded:: 1.7
    Nru   r   r   __doc__r*   r"   r!   r   r     s    :r"   r   c                      e Zd ZdZy)r   zsThis is similar to :class:`.Bot` except that it is inherited from
    :class:`discord.AutoShardedBot` instead.
    Nr   r*   r"   r!   r   r     s    r"   r   )r   zBot | AutoShardedBotr    r   r   z	list[str])r(   rr   r   z4Callable[[Bot | AutoShardedBot, Message], list[str]])r.   rr   r/   rr   r   r   )-r   
__future__r   rs   collections.abcrO   rQ   typingr   r   r   r   r   r	   rb    r   rU   r   corer   helpr   r   r}   r   discord.messager   _typesr   __all__rc   r   __annotations__r   r   r   r   r   r0   rF   CogMixinr2   r   r   r*   r"   r!   <module>r      s   2 #   
  M M     1 '  }}$$ $CLe:&e9%9##9#L=U-j'++.. U-p;'7;; ;|Wg44 r"   