
    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mZmZmZmZ ddlmZ ddlmZ ddlZddlZddlZddlZddlZddlmZmZ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/m0Z0m1Z1m2Z2m3Z4m5Z5 ddl6m7Z8m9Z: dZ;erNddl<m=Z= ddl>Z>ddl?m@Z@ ddlAmBZB ddlCmDZD ddlEmFZG ddlHmIZJmKZL ddlMmNZN ddlOmPZP eeeef         ee         f         ZQ ejR        eS          ZTd.dZUd/d0d!ZV G d" d#          ZW G d$ d%          ZX G d& d'          ZY G d( d)eY          ZZ G d* d+eY          Z[ G d, d-          Z\dS )1a:  
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CallableClassVarDict	GeneratorIteratorListOptionalSequenceTYPE_CHECKINGSetTupleTypeUnion)partial)groupbyN   )ItemItemCallbackType_ItemCallback)Select)DynamicItem   )	Component	ActionRow_component_factoryButton
SelectMenuSectionComponentTextDisplayMediaGalleryComponentFileComponentSeparatorComponentThumbnailComponent	ContainerLabelComponent)getfind)View
LayoutView)Self)Interaction)ClientT)Message)ComponentBase)#ModalSubmitComponentInteractionDataResolvedData)ConnectionState)Modal
componentsList[Component]returnIterator[Component]c              #    K   | D ]}t          |t                    r|j        E d {V  %t          |t                    rt	          |j                  E d {V  Ut          |t
                    r|j        E d {V  |j        V  |V  d S N)
isinstanceActionRowComponentchildrenContainerComponent_walk_all_componentsr    	accessory)r5   items     P/usr/local/lib/hermes-agent/venv/lib/python3.11/site-packages/discord/ui/view.pyr?   r?   e   s       	 	d.// 	}$$$$$$$$011 	+DM::::::::::.// 	}$$$$$$$.    JJJJ	 	    	componentr   parentOptional[Item]r   c                ~   t          | t                    rddlm} |                    |           }nt          | t
                    rddlm} |                    |           }nt          | t                    rddl	m
} |                    |           }nt          | t                    rddlm} |                    |           }nmt          | t                    rddlm} |                    |           }n;t          | t"                    rddlm} |                    |           }n	t          | t(                    rddlm}	 |	                    |           }nt          | t.                    rdd	lm}
 |
                    |           }nt          | t4                    rdd
lm} |                    |           }nvt          | t:                    rddlm} |                    |           }nEt          | t@                    rddl!m"} |                    |           }ntG          j        |           }||_$        |S )Nr   )r   )r   )
BaseSelect)Sectionr!   )MediaGallery)File)	Separator)	Thumbnail)r&   )Label)%r;   r<   
action_rowr   from_componentButtonComponentbuttonr   SelectComponentselectrH   r    sectionrI   TextDisplayComponenttext_displayr!   r"   media_galleryrK   r#   filerL   r$   	separatorrM   r%   	thumbnailrN   r>   	containerr&   r'   labelrO   r   _parent)rD   rE   r   rA   r   rH   rI   r!   rK   rL   rM   rN   r&   rO   s                 rB   _component_to_itemr`   r   s   )/00 -.))))))''	22	I	/	/ ).""""""$$Y//	I	/	/ %.&&&&&&((33	I/	0	0 !.$$$$$$%%i00	I3	4	4 .------)))44	I4	5	5 .//////**955	I}	-	- .""9--	I1	2	2 .((((((''	22	I1	2	2 .((((((''	22	I1	2	2 	.((((((''	22	I~	.	. .      ##I.."9--DLKrC   c                  :    e Zd ZdZddZdd	ZddZddZddZdS )_ViewWeightsweightsr=   
List[Item]c                    g d| _         d }t          ||          }t          ||          D ]\  }}|D ]}|                     |            d S )Nr   r   r   r   r   c                6    | j         t          j        n| j         S r:   )rowsysmaxsize)is    rB   <lambda>z'_ViewWeights.__init__.<locals>.<lambda>   s    qu}!% rC   key)rd   sortedr   add_item)selfr=   ro   ri   grouprA   s         rB   __init__z_ViewWeights.__init__   sz    "1//??(,,,!(444 	$ 	$JC $ $d####$	$ 	$rC   rA   r   r7   intc                x    t          | j                  D ]\  }}||j        z   dk    r|c S t          d          )N   z"could not find open space for item)	enumeraterd   width
ValueError)rr   rA   indexweights       rB   find_open_spacez_ViewWeights.find_open_space   sP    &t|44 	 	ME6
"a'' ( =>>>rC   Nonec                0   |j         X| j        |j                  |j        z   }|dk    rt          d|j          d| d          || j        |j         <   |j         |_        d S |                     |          }| j        |xx         |j        z  cc<   ||_        d S )Nrw   zitem would not fit at row z (z > 5 width))ri   rd   ry   rz   _rendered_rowr}   )rr   rA   totalr{   s       rB   rq   z_ViewWeights.add_item   s    8L*TZ7Eqyy !\dh!\!\%!\!\!\]]]%*DL"!%D((..EL4:-!&DrC   c                d    |j         (| j        |j         xx         |j        z  cc<   d |_         d S d S r:   )r   rd   ry   rr   rA   s     rB   remove_itemz_ViewWeights.remove_item   sD    )L+,,,
:,,,!%D *)rC   c                    g d| _         d S )Nrg   rc   rr   s    rB   clearz_ViewWeights.clear   s    &rC   N)r=   re   rA   r   r7   ru   )rA   r   r7   r~   r7   r~   )	__name__
__module____qualname__	__slots__rt   r}   rq   r   r    rC   rB   rb   rb      s        I
$ $ $ $? ? ? ?
' 
' 
' 
'& & & &
' ' ' ' ' 'rC   rb   c                  :    e Zd ZdZddZedd            Zdd
ZdS )_ViewCacheSnapshotitemsdynamic_itemsr7   r~   c                R    t                      | _        t                      | _        d S r:   )setr   r   r   s    rB   rt   z_ViewCacheSnapshot.__init__   s    +.55
3655rC   oldernewerr,   c                j     |             }|j         |j         z
  |_         |j        |j        z
  |_        |S r:   r   )clsr   r   rr   s       rB   diffz_ViewCacheSnapshot.diff   s5    suu[5;.
"053FFrC   strc                (    d| j         d| j        dS )Nz<_ViewCacheSnapshot items=z dynamic_items=>r   r   s    rB   __repr__z_ViewCacheSnapshot.__repr__   s     `DJ``I[````rC   Nr   )r   r   r   r   r7   r,   r7   r   )r   r   r   r   rt   classmethodr   r   r   rC   rB   r   r      sg        *I9 9 9 9    [a a a a a arC   r   c                     e Zd ZU dZded<   dZded<   i Zded<   dddRdZdSdZdTdZ	dUdZ
dVdZdSdZdSdZdWdZdVdZdXdZedYd             Zej        dZd"            Zd[d$Zed\d&            Zd\d'Zd]d)ZedUd*            Zed^d+            Zeddd_d/            Zd`d3Zd`d4Zdad5Zdbd8Zdcd;Z dVd<Z!ddd?Z"ded@Z#dfdCZ$dD Z%dgdFZ&dhdIZ'dVdJZ(dSdKZ)dSdLZ*dSdMZ+dSdNZ,didPZ-dQS )jBaseViewFClassVar[bool]__discord_ui_view____discord_ui_modal__zClassVar[Dict[str, ItemLike]]__view_children_items__     f@timeoutr   Optional[float]r7   r~   c                  || _         |                                 | _        t          j        d                                          | _        d | _        d | _        d | _	        d | _
        d | _        	 t          j                    }|                                | _        n# t           $ r
 d | _        Y nw xY wt#          t%          |                                                     | _        d S )N   )_BaseView__timeout_init_children	_childrenosurandomhexid
_cache_key_BaseView__cancel_callback_BaseView__timeout_expiry_BaseView__timeout_task_BaseView__snapshotasyncioget_running_loopcreate_future_BaseView__stoppedRuntimeErrorlentuplewalk_children_total_children)rr   r   loops      rB   rt   zBaseView.__init__   s     +/+>+>+@+@z"~~))++)-GK15<@8<	R+--D >B=O=O=Q=QDNN  	B 	B 	B=ADNNN	B
 %(d.@.@.B.B(C(C$D$Ds   0B B10B1boolc                    dS )NFr   r   s    rB   
_is_layoutzBaseView._is_layout   s    urC   r   c                \    d| j         j         d| j         dt          | j                   dS )N<z	 timeout=z
 children=r   )	__class__r   r   r   r   r   s    rB   r   zBaseView.__repr__   s6    c4>*ccT\ccSQUQ_M`M`ccccrC   List[Item[Self]]c                .   g }i }| j                                         D ]u\  }}t          |t                    r|                                }t          | ||           |                    |            t          |dd           }|r|j        |                    |            |	                    |           |||<    |j
        di |j        }t          || |          |_        |                    |            t          |t                    rd |j        D             |_        t          | |j        |           t          |dd           }|r0|                    ||          j        	                    |           `|	                    |           w|S )N__discord_ui_parent__c                6    g | ]}|                                 S r   )copy).0options     rB   
<listcomp>z+BaseView._init_children.<locals>.<listcomp>  s     #M#M#MfFKKMM#M#M#MrC   r   )r   r   r;   r   r   setattr_update_viewgetattr_viewappend__discord_ui_model_type____discord_ui_model_kwargs__r   callbackr   optionsr   r(   r   )rr   r=   parentsnamerawrA   rE   s          rB   r   zBaseView._init_children  s   5;;== 	& 	&ID##t$$ &xxzzdD)))!!$''' '>EE .fl2''---%%%#:S:]]S=\]] -c4 > >!!$'''dF++ N#M#M#M#M#MDLclD111 &=tDD KK//9@@FFF%%%%rC   c                   K   	 | j         d S | j        |                                 S t          j                    }|| j        k    r|                                 S t          j        | j        |z
             d {V  yr:   )r   r   _dispatch_timeouttime	monotonicr   sleep)rr   nows     rB   __timeout_task_implzBaseView.__timeout_task_impl  s      	=|#$,--/// .""Cd+++--/// - 5 ;<<<<<<<<<	=rC   c                X    t          d |                                 D                       S )Nc              3  >   K   | ]}|                                 V  d S r:   )is_dispatchabler   rA   s     rB   	<genexpr>z+BaseView.is_dispatchable.<locals>.<genexpr>4  s.      KKd4''))KKKKKKrC   )anyr   r   s    rB   r   zBaseView.is_dispatchable0  s-     KKd6H6H6J6JKKKKKKrC   c                >    t          d | j        D                       S )Nc              3  >   K   | ]}|                                 V  d S r:   )_is_v2)r   cs     rB   r   z-BaseView.has_components_v2.<locals>.<genexpr>7  s*      55!188::555555rC   )r   r=   r   s    rB   has_components_v2zBaseView.has_components_v26  s!    55t}555555rC   List[Dict[str, Any]]c                    t           S r:   )NotImplementedr   s    rB   to_componentszBaseView.to_components9  s    rC   c                X    | j         r"t          j                    | j         z   | _        d S d S r:   )r   r   r   r   r   s    rB   _refresh_timeoutzBaseView._refresh_timeout<  s6    > 	F$(N$4$4t~$ED!!!	F 	FrC   baser   newr   	custom_idc                N    | j                             |          }|| j         |<   d S r:   )r   r{   )rr   r   r   r   child_indexs        rB   
_swap_itemzBaseView._swap_item@  s+     n**400&){###rC   c                    | j         S )zOptional[:class:`float`]: The timeout in seconds from last interaction with the UI before no longer accepting input.
        If ``None`` then there is no timeout.
        )r   r   s    rB   r   zBaseView.timeoutF  s    
 ~rC   valuec                l    | j         %|t          j                    |z   | _        nd | _        || _        d S r:   )r   r   r   r   r   rr   r   s     rB   r   zBaseView.timeoutM  s>     * (,(8(85(@%%(,%rC   ru   c                @    t          d| j        |z             | _        d S Nr   )maxr   r   s     rB   
_add_countzBaseView._add_countY  s"    "1d&:U&BCCrC   Optional[_ViewCacheSnapshot]c                    | j         S r:   )r   r   s    rB   	_snapshotzBaseView._snapshot\  s
    rC   c                    | j         |                                 | _         d S |                                 }t                              | j         |          }|| _         |S )N)r   r   )r   _get_snapshotr   r   )rr   r   r   s      rB   _get_snapshot_diffzBaseView._get_snapshot_diff`  sY    ?""0022DO4""$$!&&T_E&JJrC   r   c                <   t                      }|                                 D ]x}t          |t                    r |j                            |j                   7|                                r-|j        }|j	                            |j
        j        |f           y|S r:   )r   r   r;   r   r   add __discord_ui_compiled_template__r   r   r   typer   )rr   snapshotrA   r   s       rB   r  zBaseView._get_snapshotk  s    %''&&(( 	A 	AD$,, A&**4+PQQQQ%%'' A N	""DIOY#?@@@rC   c                4    | j                                         S )z@List[:class:`Item`]: The list of children attached to this view.)r   r   r   s    rB   r=   zBaseView.childrenu  s     ~""$$$rC   c                    | j         S )zz:class:`int`: The total number of children in this view, including those from nested items.

        .. versionadded:: 2.6)r   r   s    rB   total_children_countzBaseView.total_children_countz  s    
 ##rC   messager/   Union[View, LayoutView]c                 t          | t                    rt          }n,t          | t                    rt          }nt          d           ||          }d}|j        D ]#}|                                st          |t                    rw|j        D ]i}t          |          }||_
        |                                r(t          |j        j         d|j        j                   |                    |           j|dz  }t          |          }||_
        |                                r<|                                s(t          |j        j         d|j        j                   |                    |           |dz  }%|S )a  Converts a message's components into a :class:`View`
        or :class:`LayoutView`.

        The :attr:`.Message.components` of a message are read-only
        and separate types from those in the ``discord.ui`` namespace.
        In order to modify and edit message components they must be
        converted into a :class:`View` or :class:`LayoutView` first.

        If the message has any v2 components, then you must use
        :class:`LayoutView` in order for them to be converted into
        their respective items. :class:`View` does not support v2 components.

        Parameters
        -----------
        message: :class:`discord.Message`
            The message with components to convert into a view.
        timeout: Optional[:class:`float`]
            The timeout of the converted view.

        Returns
        -------
        Union[:class:`View`, :class:`LayoutView`]
            The converted view. This will always return one of :class:`View` or
            :class:`LayoutView`, and not one of its subclasses.
        zunreachable exceptionr   r   z cannot be added to r   )
issubclassr*   r+   	TypeErrorr5   r   r;   r<   r=   r`   ri   r   rz   r   r   rq   )	r   r  r   view_clsviewri   rD   childrA   s	            rB   from_messagezBaseView.from_message  s   8 c4   	5HHZ(( 	5!HH3444x((( + 	 	I??$$ 
I?Q)R)R 
&/ ( (E-e44D"DH {{}} t(DN,C)r)rY]YgYp)r)rsssMM$''''q%i00DDH{{}} lT__%6%6 l DN$;!j!jQUQ_Qh!j!jkkkMM$1HCCrC   rA   	Item[Any]r,   c                    t          |t                    st          d|j        j                   |                    |            |                     |j                   | j        	                    |           | S )a  Adds an item to the view.

        This function returns the class instance to allow for fluent-style
        chaining.

        Parameters
        -----------
        item: :class:`Item`
            The item to add to the view.

        Raises
        --------
        TypeError
            An :class:`Item` was not passed.
        ValueError
            Maximum number of children has been exceeded, the
            row the item is trying to be added to is full or the item
            you tried to add is not allowed in this View.
        zexpected Item not )
r;   r   r  r   r   r   r  _total_countr   r   r   s     rB   rq   zBaseView.add_item  sw    * $%% 	LJ1HJJKKK$)***d###rC   c                    	 | j                             |           |                     |j                    |                    d           n# t
          $ r Y nw xY w| S )zRemoves an item from the view.

        This function returns the class instance to allow for fluent-style
        chaining.

        Parameters
        -----------
        item: :class:`Item`
            The item to remove from the view.
        N)r   remover  r  r   rz   r   s     rB   r   zBaseView.remove_item  sw    	$N!!$''' OOT..///d####	  	 	 	D	 s   A 
AAc                    | j         D ]}|                    d           | j                                          d| _        | S )zRemoves all items from the view.

        This function returns the class instance to allow for fluent-style
        chaining.
        Nr   )r   r   r   r   rr   r  s     rB   clear_itemszBaseView.clear_items  sM     ^ 	% 	%Et$$$$ rC   r   Optional[Item[Self]]c               H    t          |                                 |          S )a  Gets an item with :attr:`Item.id` set as ``id``, or ``None`` if
        not found.

        .. warning::

            This is **not the same** as ``custom_id``.

        .. versionadded:: 2.6

        Parameters
        ----------
        id: :class:`int`
            The ID of the component.

        Returns
        -------
        Optional[:class:`Item`]
            The item found, or ``None``.
        )r   )
_utils_getr   )rr   r   s     rB   	find_itemzBaseView.find_item  s#    ( $,,..26666rC   interactionInteraction[ClientT]c               
   K   dS )a  |coro|

        A callback that is called when an interaction happens within the view
        that checks whether the view should process item callbacks for the interaction.

        This is useful to override if, for example, you want to ensure that the
        interaction author is a given user.

        The default implementation of this returns ``True``.

        .. note::

            If an exception occurs within the body then the check
            is considered a failure and :meth:`on_error` is called.

        Parameters
        -----------
        interaction: :class:`~discord.Interaction`
            The interaction that occurred.

        Returns
        ---------
        :class:`bool`
            Whether the view children's callbacks should be called.
        Tr   )rr   r&  s     rB   interaction_checkzBaseView.interaction_check  s      4 trC   c                
   K   dS )zr|coro|

        A callback that is called when a view's timeout elapses without being explicitly stopped.
        Nr   r   s    rB   
on_timeoutzBaseView.on_timeout1  s      
 	rC   error	Exceptionc               F   K   t                               d| ||           dS )a  |coro|

        A callback that is called when an item's callback or :meth:`interaction_check`
        fails with an error.

        The default implementation logs to the library logger.

        Parameters
        -----------
        interaction: :class:`~discord.Interaction`
            The interaction that led to the failure.
        error: :class:`Exception`
            The exception that was raised.
        item: :class:`Item`
            The item that failed the dispatch.
        z)Ignoring exception in view %r for item %r)exc_infoN)_logr,  )rr   r&  r,  rA   s       rB   on_errorzBaseView.on_error8  s*      " 	

>dUZ
[[[[[rC   c                  K   	 |                     ||j                   |                    |           d {V o|                     |           d {V }|sd S | j        r t          j                    | j        z   | _        |                    |           d {V  d S # t          $ r'}| 
                    |||           d {V cY d }~S d }~ww xY wr:   )_refresh_statedata_run_checksr)  r   r   r   r   r   r-  r1  )rr   rA   r&  allowes        rB   _scheduled_taskzBaseView._scheduled_taskK  s     	=[-=>>>**;77777777e$BXBXYdBeBe<e<e<e<e<e<eE | H(,(8(84<(G%--,,,,,,,,,,, 	= 	= 	={At<<<<<<<<<<<<<<	=s%   AB AB 
C'C	C	Cstore	ViewStorec                    t          |j                  | _        | j        rm| j        | j                                         t          j                    | j        z   | _        t          j
        |                                           | _        d S d S r:   )r   remove_viewr   r   r   cancelr   r   r   r   create_task_BaseView__timeout_task_impl)rr   r9  s     rB   _start_listening_from_storez$BaseView._start_listening_from_storeZ  s    !():!;!;< 	R".#**,,,$(N$4$4t|$CD!")"5d6N6N6P6P"Q"QD	R 	RrC   c                $   | j         | j                                         rd S | j        r|                     |            d | _        | j                             d           t	          j        |                                 d| j                    d S )NTzdiscord-ui-view-timeout-r   )r   doner   
set_resultr   r>  r+  r   r   s    rB   r   zBaseView._dispatch_timeoutc  s    >!T^%8%8%:%:!F! 	*""4(((%)D"!!$'''DOO--4Xtw4X4XYYYYYYrC   Optional[asyncio.Task[None]]c                    | j         | j                                         rd S t          j        |                     ||          d| j                   S )Nzdiscord-ui-view-dispatch-rB  )r   rC  r   r>  r8  r   )rr   rA   r&  s      rB   _dispatch_itemzBaseView._dispatch_itemn  sU    >!T^%8%8%:%:!4"4#7#7k#J#JQvmqmtQvQvwwwwrC   r5   r6   c                    d |                                  D             }t          |          D ]_}t          |dd           }|	 ||         }|                    |           5# t          $ r t
                              d|           Y \w xY wd S )Nc                F    i | ]}|                                 |j        |S r   )r   r   r   s     rB   
<dictcomp>z%BaseView._refresh.<locals>.<dictcomp>v  s>     +
 +
 +
##%%+
ND+
 +
 +
rC   r   zDView interaction referenced an unknown item custom_id %s. Discarding)r   r?   r   _refresh_componentKeyErrorr0  debug)rr   r5   	old_staterD   r   r   s         rB   _refreshzBaseView._refresht  s    +
 +
**,,+
 +
 +
	 .j99 	4 	4I	;==I 4!),
 ((3333	    

aclmmm	4 	4s   A##%B
Bc                    | j         3| j                                         s| j                             d           d| _        | j         | j                                         d| _        | j        r|                     |            d| _        dS dS )zhStops listening to interaction events from this view.

        This operation cannot be undone.
        NF)r   rC  rD  r   r   r=  r   r   s    rB   stopzBaseView.stop  s    
 >%dn.A.A.C.C%N%%e,,, $*&&((("&D! 	*""4(((%)D"""	* 	*rC   c                F    | j         dS | j                                         S )z9:class:`bool`: Whether the view has finished interacting.NF)r   rC  r   s    rB   is_finishedzBaseView.is_finished  s#    >!5~""$$$rC   c                    | j         duS )zH:class:`bool`: Whether the view has been added for dispatching purposes.N)r   r   s    rB   is_dispatchingzBaseView.is_dispatching  s    %T11rC   c                P    | j         du ot          d | j        D                       S )z:class:`bool`: Whether the view is set up as persistent.

        A persistent view has all their components with a set ``custom_id`` and
        a :attr:`timeout` set to ``None``.
        Nc              3  >   K   | ]}|                                 V  d S r:   )is_persistentr   s     rB   r   z)BaseView.is_persistent.<locals>.<genexpr>  s.      +\+\TD,>,>,@,@+\+\+\+\+\+\rC   )r   allr   r   s    rB   rX  zBaseView.is_persistent  s/     |t#\+\+\T^+\+\+\(\(\\rC   c                   K   | j         *t          j                                                    | _         | j          d{V S )aG  |coro|

        Waits until the view has finished interacting.

        A view is considered finished when :meth:`stop` is called
        or it times out.

        Returns
        --------
        :class:`bool`
            If ``True``, then the view timed out. If ``False`` then
            the view finished normally.
        N)r   r   r   r   r   s    rB   waitzBaseView.wait  sF       >!$577EEGGDN^#######rC    Generator[Item[Any], None, None]c              #     K   | j         D ]4}|V  |                                r|                                E d{V  5dS )zAn iterator that recursively walks through all the children of this view
        and its children, if applicable.

        .. versionadded:: 2.6

        Yields
        ------
        :class:`Item`
            An item in the view.
        N)r=   _has_childrenr   r   s     rB   r   zBaseView.walk_children  se       ] 	1 	1EKKK""$$ 1 ..000000000		1 	1rC   Nr   r   r7   r~   r7   r   r   )r7   r   r   r7   r   )r   r   r   r   r   r   r7   r~   )r7   r   )r   r   r7   r~   r   ru   r7   r~   )r7   r  )r7   r   r7   ru   )r  r/   r   r   r7   r  rA   r  r7   r,   r7   r,   )r   ru   r7   r"  )r&  r'  r7   r   )r&  r'  r,  r-  rA   r  r7   r~   )rA   r  r&  r'  )r9  r:  r7   r~   )rA   r  r&  r'  r7   rE  )r5   r6   r7   r~   )r7   r\  ).r   r   r   r   __annotations__r   r   rt   r   r   r   r?  r   r   r   r   r   propertyr   setterr  r  r  r  r=   r  r   r  rq   r   r!  r%  r)  r+  r1  r8  r@  r   rG  rO  rQ  rS  rU  rX  r[  r   r   rC   rB   r   r      s        */////+00000=?????5: E E E E E E&   d d d d   := = = ="L L L L6 6 6 6   F F F F* * * *    X ^	 	 	 ^	D D D D    X	 	 	 	    % % % X% $ $ $ X$ MR ; ; ; ; ; [;z   :   ,   7 7 7 7,   8   \ \ \ \&= = = =R R R R	Z 	Z 	Zx x x x4 4 4 4,* * * *"% % % %2 2 2 2] ] ] ]$ $ $ $&1 1 1 1 1 1rC   r   c                       e Zd ZU dZdZded<   eredddd            Zd fdZ	ddd fdZ
ddZd fdZddZd fdZ xZS )r*   aJ  Represents a UI view.

    This object must be inherited to create a UI within Discord.

    .. versionadded:: 2.0

    Parameters
    -----------
    timeout: Optional[:class:`float`]
        Timeout in seconds from last interaction with the UI before no longer accepting input.
        If ``None`` then there is no timeout.
    Tr   r   r   r   r  r/   r   r   r7   c                  d S r:   r   r   r  r   s      rB   r  zView.from_message  s    adadrC   r~   c                   t                                                       i }t          | j                  D ]r}|j                                        D ]V\  }}t          |d          r|||<   t          |t                    r&|	                                rt          | d          Wst          |          dk    rt          d          || _        d S )Nr   z cannot be added to this View   z&View cannot have more than 25 children)super__init_subclass__reversed__mro____dict__r   hasattrr;   r   r   rz   r   r  r   )r   r=   r   r   memberr   s        rB   ro  zView.__init_subclass__  s    !!###(*S[)) 	M 	MD $ 3 3 5 5 M Mf6#>?? M%+HTNN-- M&--// M$%K%K%KLLL	M x==2DEEE&.###rC   c               ~    t                                          |           t          | j                  | _        d S )Nr   )rn  rt   rb   r   _View__weightsrr   r   r   s     rB   rt   zView.__init__  s3    )))%dn55rC   r   c                    d
d}t          | j        |          }g }t          ||          D ],\  }}d |D             }|s|                    d|d	           -|S )NrA   r   r7   ru   c                    | j         pdS r   )r   )rA   s    rB   ro   zView.to_components.<locals>.key  s    %**rC   rn   c                6    g | ]}|                                 S r   )to_component_dictr   s     rB   r   z&View.to_components.<locals>.<listcomp>  s$    CCCT..00CCCrC   r   )r  r5   r   )rp   r   r   r   )rr   ro   r=   r5   _rs   s         rB   r   zView.to_components  s    	+ 	+ 	+ 	+ $.c222+-
c222 
	 
	HAuCCUCCCH "*     rC   rA   r  r,   c                r   t          | j                  dk    rt          d          |                                rt          d          t	                                          |           	 | j                            |           n.# t          $ r!}| j                            |           |d }~ww xY w| S )Nrm  z#maximum number of children exceededz%v2 items cannot be added to this view)r   r   rz   r   rn  rq   rv  r  )rr   rA   r7  r   s      rB   rq   zView.add_item  s    t~"$$BCCC;;== 	FDEEE	N##D)))) 	 	 	N!!$'''G	
 s   .B	 	
B4B//B4c                    	 | j                             |           | j                            |           |                    d            n# t
          $ r Y nw xY w| S r:   )r   r  rv  r   r   rz   r   s     rB   r   zView.remove_item"  su    	$N!!$''' N&&t,,,d####	  	 	 	D	 s   A 
AAc                z    t                                                       | j                                         | S r:   )rn  r!  rv  r   )rr   r   s    rB   r!  zView.clear_items-  s2    rC   )r  r/   r   r   r7   r*   r   )r   r   ra  rd  re  )r   r   r   __doc__r   rf  r   r   r  ro  rt   r   rq   r   r!  __classcell__r   s   @rB   r*   r*     s          +/.... e	QVddddd 
d/ / / / / /  6; 6 6 6 6 6 6 6 6   (     "	 	 	 	         rC   r*   c                       e Zd ZdZeredddd	            Zddd fdZd fdZddZ	ddZ
d Zd fdZddZ xZS )r+   a-  Represents a layout view for components.

    This object must be inherited to create a UI within Discord.

    This differs from a :class:`View` in that it supports all component types
    and uses what Discord refers to as "v2 components".

    You can find usage examples in the :resource:`repository <examples>`

    .. versionadded:: 2.6

    Parameters
    ----------
    timeout: Optional[:class:`float`]
        Timeout in seconds from last interaction with the UI before no longer accepting input.
        If ``None`` then there is no timeout.
    r   r   r  r/   r   r   r7   c                  d S r:   r   rk  s      rB   r  zLayoutView.from_messageH  s    gjgjrC   r~   c                   t                                          |           | j        dk    rt          d          d S )Nr   (   (maximum number of children exceeded (40))rn  rt   r   rz   rw  s     rB   rt   zLayoutView.__init__K  sC    )))"$$GHHH %$rC   c                   t                                                       i }i }t          | j                  D ]v}|j                                        D ]Z\  }}t          |t                    r|j        "|j	        |_
        |||<   4t          |d          rt          |dd           r|||<   [w|                    |           || _        d S )Nr   r   )rn  ro  rp  rq  rr  r   r;   r   r_   _rowr   rs  r   updater   )r   r=   callback_childrenr   r   rt  r   s         rB   ro  zLayoutView.__init_subclass__Q  s    !!###(*CES[)) 		5 		5D $ 3 3 5 5 5 5ffd++ 5~1 +1;F(%+HTNNV%@AA 5gfVmosFtFt 5.4%d+5 	)***&.###rC   r   c                    dS )NTr   r   s    rB   r   zLayoutView._is_layoute  s    trC   r   ru   c                z    | j         |z   dk    rt          d          t          d| j         |z             | _         d S )Nr  r  r   )r   rz   r  r   s     rB   r  zLayoutView._add_counth  sD    %'",,GHHH"1d&:U&BCCrC   c                l    g }| j         D ])}|                    |                                           *|S r:   )r   r   r{  )rr   r5   rl   s      rB   r   zLayoutView.to_componentsn  sA    +-
 	5 	5Aa11334444rC   rA   r  r,   c                ~    | j         dk    rt          d          t                                          |           | S )Nr  r  )r   rz   rn  rq   )rr   rA   r   s     rB   rq   zLayoutView.add_itemu  s=    2%%GHHHrC   c                j    ddl m t          fd|                                 D                       S )z:class:`int`: Returns the total length of all text content in the view's items.

        A view is allowed to have a maximum of 4000 display characters across all its items.
        r   rJ   c              3  `   K   | ](}t          |          t          |j                  V  )d S r:   )r;   r   content)r   rA   r!   s     rB   r   z,LayoutView.content_length.<locals>.<genexpr>  s>      ggTXZeIfIfg3t|$$ggggggrC   )rX   r!   sumr   )rr   r!   s    @rB   content_lengthzLayoutView.content_length{  sF    
 	.-----gggg1C1C1E1EggggggrC   )r  r/   r   r   r7   r+   r_  r   r`  rb  rd  rc  )r   r   r   r  r   r   r  rt   ro  r   r  r   rq   r  r  r  s   @rB   r+   r+   3  s        $  k	QVjjjjj 
j5: I I I I I I I I/ / / / / /(   D D D D       h h h h h h h hrC   r+   c                      e Zd Zd.dZed/d            Zd0d
Zd1dZd1dZd2d3dZ	d4dZ
d5dZd6d Zd6d!Zd7d&Zd8d(Zd9d*Zd:d-ZdS );r:  stater3   c                r    i | _         i | _        i | _        i | _        || _        t                      | _        d S r:   )_views_synced_message_views_modals_dynamic_items_stater   _ViewStore__tasks)rr   r  s     rB   rt   zViewStore.__init__  s6    RT:<")+SU',03rC   r7   Sequence[BaseView]c                    d | j                                         D             }t          |                                          S )Nc                    i | ]K}|                                 D ]4}|j        	|j                                        "|j        j        |j        5LS r   )valuesr  rX  r   )r   r   rA   s      rB   rJ  z.ViewStore.persistent_views.<locals>.<dictcomp>  so     
 
 

 
 y	
 "Y4466	
IL$)
 
 
 
rC   )r  r  list)rr   viewss     rB   persistent_viewszViewStore.persistent_views  sF    
 
++--
 
 
 ELLNN###rC   taskasyncio.Task[None]r~   c                x    | j                             |           |                    | j         j                   d S r:   )r  r
  add_done_callbackdiscard)rr   r  s     rB   add_taskzViewStore.add_task  s7    t|344444rC   r   Type[DynamicItem[Item[Any]]]c                2    |D ]}|j         }|| j        |<   d S r:   )r  r  rr   r   rA   patterns       rB   add_dynamic_itemszViewStore.add_dynamic_items  s3     	0 	0D;G+/D((	0 	0rC   c                T    |D ]$}|j         }| j                            |d            %d S r:   )r  r  popr  s       rB   remove_dynamic_itemszViewStore.remove_dynamic_items  s?     	3 	3D;G##GT2222	3 	3rC   Nr  r   
message_idOptional[int]c                x   |                     |            |j        r|| j        |j        <   d S | j                            |i           }d}|                                }|                                D ]Z}t          |t                    r|j
        }|j        | j        |<   .|                                r|||j        j        |j        f<   d}[|E|j        D ]}|                    |d            |j        D ]}| j                            |d            ||_        |r
|| j        |<   ||s|| j        |<   d S d S d S )NTF)r@  r   r  r   r  r(   r  r   r;   r   r  r   r  r   r  r   r   r  r   r   r  )	rr   r  r  dispatch_infois_fully_dynamicr  rA   r  ro   s	            rB   add_viewzViewStore.add_view  s}   ((...$ 	+/DL(F
B77**,,&&(( 	) 	)D$,, )?/3~#G,,%%'' )CGty?@#( ~ - -!!#t,,,,- 3 3#''T2222$ 	4&3DK
#!*:!59D&z222 "!!!rC   c                   |j         r"| j                            |j        d            d S | j                            |j                  }|j        }|rG|rE|j        D ]}|                    |d            |j	        D ]}| j
                            |d            |3t          |          dk    r | j                            |j        d            | j                            |j        d            d S r   )r   r  r  r   r  r(   r   r  r   r   r  r   r  )rr   r  r  r  ro   s        rB   r<  zViewStore.remove_view  s    $ 	LT^T222F88> 	3X 	3~ - -!!#t,,,,- 3 3#''T2222$]););q)@)@KOODOT222"&&t=====rC   component_typeru   factoryr&  r'  r   r   matchre.Match[str]c                8  K   |j         d S |j         j        j        st          nt          }|                    |j         d           }t          fd|                                          }|sd S 	 |                    |||           d {V }	n,# t          $ r t                              d|           Y d S w xY w|j        p|}
	 |
                    ||	           n# t          $ r Y d S w xY w||	_        |j        |	_        |	                    ||j                   	 |	                    |           d {V }n# t          $ r d}Y nw xY w|sd S 	 |	                    |           d {V  d S # t          $ r t                              d|	           Y d S w xY w)Nr   c                N    | j         j        k    ot          | dd           k    S )Nr   )r  r   r   )rl   r  r   s    rB   rm   z6ViewStore.schedule_dynamic_item_call.<locals>.<lambda>  s(    afln4cKQU9V9VZc9c rC   z2Ignoring exception in dynamic item creation for %rFz2Ignoring exception in dynamic item callback for %r)r  flagscomponents_v2r*   r+   r  _utils_findr   from_custom_idr-  r0  	exceptionr_   r   rz   r   r   r3  r4  r)  r   )rr   r  r  r&  r   r  r  r  	base_itemrA   rE   r6  s    `  `       rB   schedule_dynamic_item_callz$ViewStore.schedule_dynamic_item_call  s9      &F*28FV44J$$[%8$$GGccccc  
 
	  	F	 //YNNNNNNNNDD 	 	 	NNOQXYYYFF	 "*d	iy9999 	 	 	FF	 
&4K)9:::	00========EE 	 	 	EEE	  	F	W--,,,,,,,,,,, 	W 	W 	WNNOQUVVVVVV	WsH   4B %B;:B;C   
C.-C. D< <E
EE0 0%FFc                   | j                                         D ]g\  }}|                    |          }|K|                     t	          j        |                     |||||          d|j         d|                      hd S )Nzdiscord-ui-dynamic-item--rB  )r  r   	fullmatchr  r   r>  r  r   )rr   r  r   r&  r  rA   r  s          rB   dispatch_dynamic_itemsz ViewStore.dispatch_dynamic_items  s    !06688 	 	MGT%%i00E '77k[dfkllSSS	SS    	 	rC   c                   |                      |||           d }|j        }||j        }||f}d }|.| j                            |i                               |          }|.| j                            d i                               |          }|d S |j        t                              d|           d S |j                            ||          }|| 	                    |           d S d S )NzAView interaction referencing unknown view for item %s. Discarding)
r  r  r   r  r(   r  r0  warningrG  r  )	rr   r  r   r&  r  msgro   rA   r  s	            rB   dispatch_viewzViewStore.dispatch_view  s   ##NI{KKK$(
 !?Jy) *.!;??:r2266s;;D< ;??4,,0055D <F9LL\^bcccFy''k::MM$ rC   r5   0List[ModalSubmitComponentInteractionDataPayload]resolvedResolvedDataPayloadc                    | j                             |          }|t                              d|           d S |                     |                    |||                     d S )Nz>Modal interaction referencing unknown custom_id %s. Discarding)r  r(   r0  rM  r  _dispatch_submit)rr   r   r&  r5   r  modals         rB   dispatch_modalzViewStore.dispatch_modal?  sc       ++=JJWYbcccFe,,[*hOOPPPPPrC   r   c                    || j         v S r:   )r  rr   r  s     rB   is_message_trackedzViewStore.is_message_trackedM  s    T777rC   Optional[BaseView]c                8    | j                             |d           S r:   )r  r  r  s     rB   remove_message_trackingz!ViewStore.remove_message_trackingP  s    )--j$???rC   r4  List[ComponentBasePayload]c                    g }|D ].}t          || j                  }||                    |           /| j        |         }|                    |           d S r:   )r   r  r   r  rO  )rr   r  r4  r5   component_datarD   r  s          rB   update_from_messagezViewStore.update_from_messageS  si    &(
" 	- 	-N*>4;GGI$!!),,, )*5j!!!!!rC   )r  r3   )r7   r  )r  r  r7   r~   )r   r  r7   r~   r:   )r  r   r  r  r7   r~   )r  r   r7   r~   )r  ru   r  r  r&  r'  r   r   r  r  r7   r~   )r  ru   r   r   r&  r'  r7   r~   )
r   r   r&  r'  r5   r  r  r  r7   r~   )r  ru   r7   r   )r  ru   r7   r  )r  ru   r4  r  r7   r~   )r   r   r   rt   rg  r  r  r  r  r  r<  r  r  r  r  r  r  r  r   rC   rB   r:  r:    sK       
6 
6 
6 
6 	$ 	$ 	$ X	$5 5 5 50 0 0 0
3 3 3 3
: : : : :<> > > >$5W 5W 5W 5Wn	 	 	 	       BQ Q Q Q8 8 8 8@ @ @ @" " " " " "rC   r:  )r5   r6   r7   r8   r:   )rD   r   rE   rF   r7   r   )]r  
__future__r   typingr   r   r   r   r   r	   r
   r   r   r   r   r   r   r   	functoolsr   	itertoolsr   r   loggingrj   r   r   rA   r   r   r   rU   r   dynamicr   r5   r   r   r<   r   r   rR   r   rT   r    r!   rW   r"   r#   r$   r%   r&   r>   r'   utilsr(   r$  r)   r  __all__typing_extensionsr,   reinteractionsr-   _typesr.   r  r/   types.componentsr0   ComponentBasePayloadtypes.interactionsr1   *ModalSubmitComponentInteractionDataPayloadr2   r  r  r3   r  r4   ItemLike	getLoggerr   r0  r?   r`   rb   r   r   r*   r+   r:  r   rC   rB   <module>r     s]   0 # " " " " "                                               



  				 7 7 7 7 7 7 7 7 7 7                                                ; : : : : : : :  <&&&&&&III******      !!!!!!HHHHHH        ('''''%c3h/c:;H w""
 
 
 
1 1 1 1 1h)' )' )' )' )' )' )' )'Xa a a a a a a a$m1 m1 m1 m1 m1 m1 m1 m1`\ \ \ \ \8 \ \ \~Oh Oh Oh Oh Oh Oh Oh OhdY" Y" Y" Y" Y" Y" Y" Y" Y" Y"rC   