
    i#                    .   d Z ddlmZ ddlZddl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mZ 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 d	dlmZ ddlmZ e	rddlm Z  ddlm!Z! ddl"m#Z$m%Z& ddl'm(Z( dZ) ej*        e+          Z, G d de          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.
    )annotationsN)deepcopy)TYPE_CHECKINGAnyDictOptionalSequenceClassVarList   )MISSINGfind)ClientT   )Item)BaseView)
BaseSelect)	TextInput)	Namespace)Self)Interaction)#ModalSubmitComponentInteractionDataResolvedData)
ResolveKey)Modalc                       e Zd ZU dZerded<   dZi Zded<   edd,d
Z	d-dZ
ededd. fdZd/dZd0dZd1dZd2d Zd3d"Zd4d%Zd5d'Zd6 fd+Z xZS )7r   ah  Represents a UI modal.

    This object must be inherited to create a modal popup window within discord.

    .. versionadded:: 2.0

    Examples
    ----------

    .. code-block:: python3

        import discord
        from discord import ui

        class Questionnaire(ui.Modal, title='Questionnaire Response'):
            name = ui.Label(text='Name', component=ui.TextInput())
            answer = ui.Label(text='Answer', component=ui.TextInput(style=discord.TextStyle.paragraph))

            async def on_submit(self, interaction: discord.Interaction):
                await interaction.response.send_message(f'Thanks for your response, {self.name.component.value}!', ephemeral=True)

    Parameters
    -----------
    title: :class:`str`
        The title of the modal.
        Can only be up to 45 characters.
    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.
    custom_id: :class:`str`
        The ID of the modal that gets received during an interaction.
        If not given then one is generated for you.
        Can only be up to 100 characters.

    Attributes
    ------------
    title: :class:`str`
        The title of the modal.
    custom_id: :class:`str`
        The ID of the modal that gets received during an interaction.
    strtitleTzClassVar[Dict[str, Item[Self]]]__modal_children_items__)r   returnNonec                   |t           ur|| _        i }t          | j                  D ];}|j                                        D ]\  }}t          |t                    r|||<    <|| _        d S N)	r   r   reversed__mro____dict__items
isinstancer   r   )clsr   childrenbasenamemembers         Q/usr/local/lib/hermes-agent/venv/lib/python3.11/site-packages/discord/ui/modal.py__init_subclass__zModal.__init_subclass__o   s    CIS[)) 	, 	,D $ 3 3 5 5 , ,ffd++ ,%+HTN, (0$$$    
List[Item]c                    g }| j                                         D ]A\  }}t          |          }t          | ||           | |_        |                    |           B|S r#   )r   r'   r   setattr_viewappend)selfr*   r,   items       r.   _init_childrenzModal._init_children{   sg    7==?? 	" 	"JD$D>>DD$%%%DJOOD!!!!r0   N)r   timeout	custom_idr9   Optional[float]r:   c               B   |t           u r,t          | dt                     t           u rt          d          |t           ur|| _        |t           u r&t	          j        d                                          n|| _        t                      	                    |           d S )Nr   zModal must have a title   )r9   )
r   getattr
ValueErrorr   osurandomhexr:   super__init__)r6   r   r9   r:   	__class__s       r.   rD   zModal.__init__   s     Ggw ? ?7 J J6777'!!DJ6?76J6Jbjnn00222PY)))))r0   interactionInteraction[ClientT]c               
   K   dS )z|coro|

        Called when the modal is submitted.

        Parameters
        -----------
        interaction: :class:`.Interaction`
            The interaction that submitted this modal.
        N )r6   rF   s     r.   	on_submitzModal.on_submit   s       	r0   error	Exceptionc               D   K   t                               d| |           dS )a  |coro|

        A callback that is called when :meth:`on_submit`
        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.
        zIgnoring exception in modal %r:)exc_infoN)_logrK   )r6   rF   rK   s      r.   on_errorzModal.on_error   s'       	

4dU
KKKKKr0   r   
components4Sequence[ModalSubmitComponentInteractionDataPayload]resolvedDict[ResolveKey, Any]c                   |D ]}|d         dk    r|                      ||d         |           ,|d         dk    r|                      ||d         g|           W|                    d          ot          fd|                                           }|t                              d           |                    |||           d S )	Ntyper   rQ      	componentr:   c                .    t          | dd           k    S )Nr:   )r>   )ir:   s    r.   <lambda>z Modal._refresh.<locals>.<lambda>   s    gad;;yH r0   zCModal interaction referencing unknown item custom_id %s. Discarding)_refreshgetr   walk_childrenrO   debug_handle_submit)r6   rF   rQ   rS   rX   r7   r:   s         @r.   r\   zModal._refresh   s     $ 	F 	FI A%%k9\+BHMMMM6"b((kIk,B+CXNNNN%MM+66	$HHHH&&((  <JJdfoppp##KHEEEE%	F 	Fr0   0List[ModalSubmitComponentInteractionDataPayload]c                d  K   	 |                                   |                     |||           |                     |           d {V }|sd S |                     |           d {V  |                                  d S # t
          $ r&}|                     ||           d {V cY d }~S d }~ww xY wr#   )_refresh_timeoutr\   interaction_checkrJ   stoprL   rP   )r6   rF   rQ   rS   allowes         r.   _scheduled_taskzModal._scheduled_task   s      	!!###MM+z8<<<00========E ..--------- IIKKKKK  	7 	7 	7{A66666666666666	7s$   AA? A? ?
B/	B*$B/*B/List[Dict[str, Any]]c                &   d	d}t          | j        |          }g }|D ]q}t          |t          t          f          r,|                    d|                                gd           J|                    |                                           r|S )
Nr7   r   r    intc                "    | j         p| j        pdS )Nr   )_rendered_rowrow)r7   s    r.   keyz Modal.to_components.<locals>.key   s    %66Q6r0   )ro   r   )rV   rQ   )r7   r   r    rk   )sorted	_childrenr(   r   r   r5   to_component_dict)r6   ro   r*   rQ   childs        r.   to_componentszModal.to_components   s    	7 	7 	7 	7 $.c222+-
 	= 	=E%*i!899 = !! !','>'>'@'@&A     !!%"9"9";";<<<<r0   ResolvedDataPayloadasyncio.Task[None]c                    	 t          j        ||          }n# t          $ r i }Y nw xY wt          j        |                     |||          d| j                   S )Nzdiscord-ui-modal-dispatch-)r,   )r   _get_resolved_itemsKeyErrorasynciocreate_taskrh   id)r6   rF   rQ   rS   	namespaces        r.   _dispatch_submitzModal._dispatch_submit   s    	!5k8LLII 	 	 	III	 "  j)DDKqhlhoKqKq
 
 
 	
s    ''Dict[str, Any]c                J    | j         | j        |                                 d}|S )N)r:   r   rQ   )r:   r   rt   )r6   payloads     r.   to_dictzModal.to_dict  s.    Z,,..
 
 r0   r7   	Item[Any]r   c                    t          | j                  dk    rt          d          t                                          |          S )N   z'maximum number of children exceeded (5))lenrq   r?   rC   add_item)r6   r7   rE   s     r.   r   zModal.add_item  s?    t~!##FGGGww%%%r0   )r   r   r    r!   )r    r1   )r   r   r9   r;   r:   r   r    r!   )rF   rG   r    r!   )rF   rG   rK   rL   r    r!   )rF   r   rQ   rR   rS   rT   r    r!   )rF   r   rQ   ra   rS   rT   )r    ri   )rF   r   rQ   ra   rS   ru   r    rv   )r    r   )r7   r   r    r   )__name__
__module____qualname____doc__r   __annotations____discord_ui_modal__r   r   r/   r8   rD   rJ   rP   r\   rh   rt   r~   r   r   __classcell__)rE   s   @r.   r   r   >   sq        ( (T  


@BBBBB/6 
0 
0 
0 
0 
0 
0    #' * * * * * * * *
 
 
 
L L L L"F F F F4   ,   ,
 
 
 
   & & & & & & & & & &r0   r   ).r   
__future__r   rz   loggingr@   copyr   typingr   r   r   r   r	   r
   r   utilsr   r   _typesr   r7   r   viewr   selectr   
text_inputr   interactionsr   typing_extensionsr   r   types.interactionsr   *ModalSubmitComponentInteractionDataPayloadr   ru   app_commands.namespacer   __all__	getLoggerr   rO   r   rI   r0   r.   <module>r      s   0 # " " " " "   				       O O O O O O O O O O O O O O O O O O ! ! ! ! ! ! ! !                         ! ! ! ! ! ! $ $ $ $ $ $ 4&&&&&&******        433333 w""S& S& S& S& S&H S& S& S& S& S&r0   