
    i]               	         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mZ ddlZddlmZ ddlmZ d	Z e
d
dd          Zer#ddlm
Z
mZ ddlmZ ddlmZ ddlmZ ddlmZmZ nexZZ G d dee         eeeef                            Z dS )a:  
The MIT License (MIT)

Copyright (c) 2015-present Rapptz

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

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

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
    )annotations)
ClassVarDictGenericOptionalTupleTypeTypeVarTYPE_CHECKINGAnyUnionN   )Item   )ClientT)DynamicItemBaseT	Item[Any]T)bound	covariant)r
   Self)Interaction)	Component)ComponentType)View
LayoutViewc                      e Zd ZU dZdZded<   ded<   d8 fdZddd9 fdZed:d            Z	d;dZ
d<dZd=dZed>d!            Zed?d#            Zd@d%Zd@d&ZedAd(            Zej        dBd*            ZedCd+            Zej        dDd,            ZedEd.            ZedEd/            ZedFd4            ZdGd6ZdHd7Z xZS )Ir   a  Represents an item with a dynamic ``custom_id`` that can be used to store state within
    that ``custom_id``.

    The ``custom_id`` parsing is done using the ``re`` module by passing a ``template``
    parameter to the class parameter list.

    This item is generated every time the component is dispatched. This means that
    any variable that holds an instance of this class will eventually be out of date
    and should not be used long term. Their only purpose is to act as a "template"
    for the actual dispatched item.

    When this item is generated, :attr:`view` is set to a regular :class:`View` instance,
    but to a :class:`LayoutView` if the component was sent with one, this is obtained from
    the original message given from the interaction. This means that custom view subclasses
    cannot be accessed from this item.

    .. versionadded:: 2.4

    Parameters
    ------------
    item: :class:`Item`
        The item to wrap with dynamic custom ID parsing.
    template: Union[:class:`str`, ``re.Pattern``]
        The template to use for parsing the ``custom_id``. This can be a string or a compiled
        regular expression. This must be passed as a keyword argument to the class creation.
    row: Optional[:class:`int`]
        The relative row this button belongs to. A Discord component can only have 5
        rows. By default, items are arranged automatically into those 5 rows. If you'd
        like to control the relative positioning of the row then passing an index is advised.
        For example, row=1 will show up before row=2. Defaults to ``None``, which is automatic
        ordering. The row number must be between 0 and 4 (i.e. zero indexed).

    Attributes
    -----------
    item: :class:`Item`
        The item that is wrapped with dynamic custom ID parsing.
    )itemtemplatezTuple[str, ...]__item_repr_attributes__zClassVar[re.Pattern[str]] __discord_ui_compiled_template__r   Union[str, re.Pattern[str]]returnNonec                  t                                                       t          |t                    rt	          j        |          n|| _        t          | j        t          j                  st          d          d S )Nz&template must be a str or a re.Pattern)	super__init_subclass__
isinstancestrrecompiler!   Pattern	TypeError)clsr   	__class__s     S/usr/local/lib/hermes-agent/venv/lib/python3.11/site-packages/discord/ui/dynamic.pyr'   zDynamicItem.__init_subclass__\   su    !!###GQRZ\_G`G`/nrz(/C/C/Cfn,#>
KK 	FDEEE	F 	F    N)rowr   r   r2   Optional[int]c               >   t                                                       || _        ||| _        | j                                        st          d          | j                            | j                  s$t          d| j        d| j        j
                  d S )Nz0item must be dispatchable, e.g. not a URL buttonzitem custom_id z must match the template )r&   __init__r   r2   is_dispatchabler-   r   match	custom_id
ValueErrorpattern)selfr   r2   r/   s      r0   r5   zDynamicItem.__init__b   s     		?DHy((** 	PNOOO}""4>22 	ust~ssZ^ZgZossttt	u 	ur1   re.Pattern[str]c                    | j         j        S )zX``re.Pattern``: The compiled regular expression that is used to parse the ``custom_id``.)r/   r!   r;   s    r0   r   zDynamicItem.templates   s     ~>>r1   Dict[str, Any]c                4    | j                                         S N)r   to_component_dictr>   s    r0   rB   zDynamicItem.to_component_dictx   s    y**,,,r1   	componentr   c                :    | j                             |           d S rA   )r   _refresh_component)r;   rC   s     r0   rE   zDynamicItem._refresh_component{   s    	$$Y/////r1   interactionr   datac                <    | j                             ||           d S rA   )r   _refresh_state)r;   rF   rG   s      r0   rI   zDynamicItem._refresh_state~   s     	  d33333r1   r.   
Type[Self]r   c                     t          d          )Nz/Dynamic items cannot be created from components)r-   )r.   rC   s     r0   from_componentzDynamicItem.from_component   s    IJJJr1   r   c                    | j         j        S rA   )r   typer>   s    r0   rN   zDynamicItem.type       y~r1   boolc                4    | j                                         S rA   )r   r6   r>   s    r0   r6   zDynamicItem.is_dispatchable   s    y((***r1   c                    dS )NT r>   s    r0   is_persistentzDynamicItem.is_persistent   s    tr1   r)   c                    | j         j        S )zR:class:`str`: The ID of the dynamic item that gets received during an interaction.)r   r8   r>   s    r0   r8   zDynamicItem.custom_id   s     y""r1   valuec                    t          |t                    st          d          | j                            |          st          d| j        j                  || j        _        d| _	        d S )Nzcustom_id must be a strz"custom_id must match the template T)
r(   r)   r-   r   r7   r9   r:   r   r8   _provided_custom_idr;   rV   s     r0   r8   zDynamicItem.custom_id   sp    %%% 	75666}""5)) 	][$-BW[[\\\#	#'   r1   c                    | j         j        S rA   )r   _rowr>   s    r0   r2   zDynamicItem.row   rO   r1   c                    || j         _        d S rA   )r   r2   rY   s     r0   r2   zDynamicItem.row   s    	r1   intc                    | j         j        S rA   )r   widthr>   s    r0   r_   zDynamicItem.width   s    yr1   c                    | j         j        S rA   )r   _total_countr>   s    r0   ra   zDynamicItem._total_count   s    y%%r1   Interaction[ClientT]r   r7   re.Match[str]c                  K   t           )a  |coro|

        A classmethod that is called when the ``custom_id`` of a component matches the
        ``template`` of the class. This is called when the component is dispatched.

        It must return a new instance of the :class:`DynamicItem`.

        Subclasses *must* implement this method.

        Exceptions raised in this method are logged and ignored.

        .. warning::

            This method is called before the callback is dispatched, therefore
            it means that it is subject to the same timing restrictions as the callback.
            Ergo, you must reply to an interaction within 3 seconds of it being
            dispatched.

        Parameters
        ------------
        interaction: :class:`~discord.Interaction`
            The interaction that the component belongs to.
        item: :class:`~discord.ui.Item`
            The base item that is being dispatched.
        match: ``re.Match``
            The match object that was created from the ``template``
            matching the ``custom_id``.

        Returns
        --------
        :class:`DynamicItem`
            The new instance of the :class:`DynamicItem` with information
            from the ``match`` object.
        )NotImplementedError)r.   rF   r   r7   s       r0   from_custom_idzDynamicItem.from_custom_id   s      L "!r1   r   c                F   K   | j                             |           d {V S rA   )r   callbackr;   rF   s     r0   rh   zDynamicItem.callback   s.      Y''444444444r1   c               F   K   | j                             |           d {V S rA   )r   interaction_checkri   s     r0   rk   zDynamicItem.interaction_check   s.      Y00=========r1   )r   r"   r#   r$   )r   r   r2   r3   r#   r$   )r#   r<   )r#   r?   )rC   r   r#   r$   )rF   r   rG   r?   r#   r$   )r.   rJ   rC   r   r#   r   )r#   r   )r#   rP   )r#   r)   )rV   r)   r#   r$   )r#   r3   )rV   r3   r#   r$   )r#   r]   )
r.   rJ   rF   rb   r   r   r7   rc   r#   r   )rF   rb   r#   r   )rF   rb   r#   rP   )__name__
__module____qualname____doc__r    __annotations__r'   r5   propertyr   rB   rE   rI   classmethodrL   rN   r6   rT   r8   setterr2   r_   ra   rf   rh   rk   __classcell__)r/   s   @r0   r   r   .   s        $ $L1    
 @???F F F F F F "	u u u u u u u u" ? ? ? X?- - - -0 0 0 04 4 4 4 K K K [K    X+ + + +    # # # X# ( ( ( (    X 	Z   Z    X & & & X& %" %" %" [%"N5 5 5 5> > > > > > > >r1   r   )!ro   
__future__r   typingr   r   r   r   r   r	   r
   r   r   r   r*   r   r   _typesr   __all__r   typing_extensionsr   interactionsr   
componentsr   enumsr   viewr   r   r   rS   r1   r0   <module>r~      s   0 # " " " " " e e e e e e e e e e e e e e e e e e e e e e e e 				            
{d;;; ////////******&&&&&&%%%%%%&&&&&&&&&D:m> m> m> m> m>'%.$uT:-='>"? m> m> m> m> m>r1   