
    iY                       d Z ddlmZ ddl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mZmZ ddlmZ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&m'Z'm(Z( d	dl)m*Z* d	dl+m,Z,m-Z. erIddl/m0Z0 ddl1m2Z2 ddlm3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9 d	dl:m;Z; d	dl"m<Z< ddl=m>Z> ddl?m@Z@ eede3f         ge3f         ZA eded         d          ZB eddd          ZCd
ZD G d deeC                   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)TYPE_CHECKINGAnyCallableClassVarDict	GeneratorListLiteralOptionalSequenceTypeTypeVarUnionoverload   )ItemContainedItemCallbackType_ItemCallback)Buttonbutton)selectSelect
UserSelect
RoleSelectChannelSelectMentionableSelect   )	ActionRow)ButtonStyleComponentTypeChannelType)PartialEmoji)MISSINGget)Self)
LayoutView)BaseSelectTValidDefaultValuesMentionableSelectTChannelSelectTRoleSelectTUserSelectTSelectT)Emoji)SelectOption)	Container)DynamicItemS)r   r1   r'   T)bound	covariantVr'   c                      e Zd ZU dZg Zded<   dZded<   dZdddd fdZde fdZ	dfdZ
dgdZdedZdhdZdhdZd ZdidZdjd!Zed"             Zedkd$            Zedld&            Zedmd(            Zdnd*Zdkd+Zdod/Zdod0Zdpd2Zdqd3Zdrd5Zddd6ej        ddd7dsd@Z e!e"e#         e$dAdAdAdAdAdAdAdB	dtdM            Z%e!e&e#         e$dAdAdAdAdAdAdAdAdN
dudS            Z%e!e'e#         e$dAdAdAdAdAdAdAdAdN
dvdV            Z%e!e(e#         e$dAdAdAdAdAdAdAdAdN
dwdY            Z%e!e)e#         e$e$dAdAdAdAdAdAdAdN
dxd\            Z%e"e#         e$e$de$d]d]d6e$ddN
dyd`Z%e*dzdc            Z+ xZ,S ){r   a  Represents a UI action row.

    This is a top-level layout component that can only be used on :class:`LayoutView`
    and can contain :class:`Button`\s and :class:`Select`\s in it.

    Action rows can only have 5 children. This can be inherited.

    .. versionadded:: 2.6

    Examples
    --------

    .. code-block:: python3

        import discord
        from discord import ui

        # you can subclass it and add components with the decorators
        class MyActionRow(ui.ActionRow):
            @ui.button(label='Click Me!')
            async def click_me(self, interaction: discord.Interaction, button: discord.ui.Button):
                await interaction.response.send_message('You clicked me!')

        # or use it directly on LayoutView
        class MyView(ui.LayoutView):
            row = ui.ActionRow()
            # or you can use your subclass:
            # row = MyActionRow()

            # you can add items with row.button and row.select
            @row.button(label='A button!')
            async def row_button(self, interaction: discord.Interaction, button: discord.ui.Button):
                await interaction.response.send_message('You clicked a button!')

    Parameters
    ----------
    \*children: :class:`Item`
        The initial children of this action row.
    id: Optional[:class:`int`]
        The ID of this component. This must be unique across the view.
    z+ClassVar[List[ItemCallbackType[Self, Any]]]__action_row_children_items__TzClassVar[bool]__discord_ui_action_row__idNchildrenItem[V]r;   Optional[int]returnNonec               6   t                                                       |                                 | _        t	          d | j        D                       | _        |D ]}|                     |           | j        dk    rt          d          || _        d S )Nc              3  $   K   | ]}|j         V  d S N)width).0is     V/usr/local/lib/hermes-agent/venv/lib/python3.11/site-packages/discord/ui/action_row.py	<genexpr>z%ActionRow.__init__.<locals>.<genexpr>   s$      @@A@@@@@@       #maximum number of children exceeded)	super__init___init_children	_childrensum_weightadd_item
ValueErrorr;   )selfr;   r<   child	__class__s       rG   rM   zActionRow.__init__~   s    
 	(,(;(;(=(=@@@@@@@ 	! 	!EMM%    <!BCCCrI   c                r   t                                                       i }t          | j                  D ]6}|j                                        D ]\  }}t          |d          r|||<   7t          |          dk    rt          d          t          |
                                          | _        d S )N__discord_ui_model_type__rJ   z*ActionRow cannot have more than 5 children)rL   __init_subclass__reversed__mro____dict__itemshasattrlen	TypeErrorlistvaluesr8   )clsr<   basenamememberrV   s        rG   rY   zActionRow.__init_subclass__   s    !!###;=S[)) 	, 	,D $ 3 3 5 5 , ,f6#>?? ,%+HTN, x==1HIII,01B1B,C,C)))rI   strc                L    d| j         j         dt          | j                   dS )N<z
 children=>)rV   __name__r_   rO   rT   s    rG   __repr__zActionRow.__repr__   s*    L4>*LLc$.6I6ILLLLrI   List[Item[Any]]c                    g }| j         D ]\} |j        di |j        }t          || |          |_        | |_        t          | |j        |           |                    |           ]|S )N )	r8   rX   __discord_ui_model_kwargs__r   callback_parentsetattrrk   append)rT   r<   funcitems       rG   rN   zActionRow._init_children   s|    6 	" 	"D77[[$:Z[[D)$d;;DMDLD$-...OOD!!!!rI   c                6    || _         | j        D ]	}||_         
d S rC   )_viewrO   )rT   viewrU   s      rG   _update_viewzActionRow._update_view   s-    
^ 	 	EEKK	 	rI   ActionRow[V]c                L   t          j         |           }g }|j        D ]X}|                                 }||_        t          |j        t
                    r||j        _        |                    |           Y||_        | j        |_        |                    | j	                   |S rC   )
copyrO   rs   
isinstancerr   r   parentru   r{   rz   )rT   newr<   rU   newchs        rG   r~   zActionRow.copy   s    ioo] 	# 	#EJJLLEEM%.-88 ,(+%OOE"""" l###
rI   c                *    |                                  S rC   )r~   )rT   memos     rG   __deepcopy__zActionRow.__deepcopy__   s    yy{{rI   c                    dS NTrp   rl   s    rG   _has_childrenzActionRow._has_children   s    trI   boolc                    dS r   rp   rl   s    rG   _is_v2zActionRow._is_v2   s	     trI   rd   r   r   r2   	custom_idc                N    | j                             |          }|| j         |<   d S rC   )rO   index)rT   rd   r   r   child_indexs        rG   
_swap_itemzActionRow._swap_item   s)    n**400&){###rI   c                    dS )NrJ   rp   rl   s    rG   rD   zActionRow.width   s    qrI   intc                0    dt          | j                  z   S )Nr   )r_   rO   rl   s    rG   _total_countzActionRow._total_count   s     3t~&&&&rI   !Literal[ComponentType.action_row]c                    t           j        S rC   )r!   
action_rowrl   s    rG   typezActionRow.type   s    ''rI   List[Item[V]]c                4    | j                                         S )zFList[:class:`Item`]: The list of children attached to this action row.)rO   r~   rl   s    rG   r<   zActionRow.children   s     ~""$$$rI   Generator[Item[V], Any, None]c              #  $   K   | j         E d{V  dS )zAn iterator that recursively walks through all the children of this action row
        and its children, if applicable.

        Yields
        ------
        :class:`Item`
            An item in the action row.
        N)r<   rl   s    rG   walk_childrenzActionRow.walk_children   s(       =         rI   c                P    ddl m t          fd| j        D                       S )zN:class:`int`: Returns the total length of all text content in this action row.r   )TextDisplayc              3  `   K   | ](}t          |          t          |j                  V  )d S rC   )r   r_   content)rE   rw   r   s     rG   rH   z+ActionRow.content_length.<locals>.<genexpr>   s=      aa:dT_C`C`a3t|$$aaaaaarI   )text_displayr   rP   rO   )rT   r   s    @rG   content_lengthzActionRow.content_length   s:    ------aaaaaaaaaarI   rw   	Item[Any]r&   c                   | j         |j        z   dk    rt          d          t          | j                  dk    rt          d          t          |t                    st          d|j        j	                   | j
        r| j
                            d           |                    | j                   | |_        | xj         dz  c_         | j                            |           | S )a  Adds an item to this action row.

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

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

        Raises
        ------
        TypeError
            An :class:`Item` was not passed.
        ValueError
            Maximum number of children has been exceeded (5)
            or (40) for the entire view.
        rJ   rK   zexpected Item not r   )rQ   rD   rS   r_   rO   r   r   r`   rV   rk   ry   
_add_countr{   rz   rs   ru   rT   rw   s     rG   rR   zActionRow.add_item   s    ( L4:%**BCCCt~!##BCCC$%% 	LJ1HJJKKK: 	%J!!!$$$$)$$$d###rI   c                    	 | j                             |           | j        r| j                            d           | xj        dz  c_        n# t
          $ r Y nw xY w| S )a  Removes an item from the action row.

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

        Parameters
        ----------
        item: :class:`Item`
            The item to remove from the action row.
        r   )rO   removery   r   rQ   rS   r   s     rG   remove_itemzActionRow.remove_item  sz    	N!!$''' z *
%%b)))LLALLL  	 	 	D	 s   A 
AAOptional[Item[V]]c               H    t          |                                 |          S )ax  Gets an item with :attr:`Item.id` set as ``id``, or ``None`` if
        not found.

        .. warning::

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

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

        Returns
        -------
        Optional[:class:`Item`]
            The item found, or ``None``.
        r:   )
_utils_getr   )rT   r;   s     rG   	find_itemzActionRow.find_item1  s#    $ $,,..26666rI   c                    | j         r-| j                             t          | j                              | j                                         d| _        | S )zRemoves all items from the action row.

        This function returns the class instance to allow for fluent-style
        chaining.
        r   )ry   r   r_   rO   clearrQ   rl   s    rG   clear_itemszActionRow.clear_itemsE  sQ     : 	8J!!3t~#6#6"6777rI   Dict[str, Any]c                    g }| j         D ])}|                    |                                           *| j        j        |d}| j        
| j        |d<   |S )N)r   
componentsr;   )r<   ru   to_component_dictr   valuer;   )rT   r   	componentrd   s       rG   r   zActionRow.to_component_dictQ  sm    
 	= 	=Ii99;;<<<< IO$
 
 7DJrI   F)labelr   disabledstyleemojir;   r   Optional[str]r   r   r    r   )Optional[Union[str, Emoji, PartialEmoji]]5Callable[[ItemCallbackType[S, Button[V]]], Button[V]]c               ,     d fd}|S )az  A decorator that attaches a button to the action row.

        The function being decorated should have three parameters, ``self`` representing
        the :class:`discord.ui.ActionRow`, the :class:`discord.Interaction` you receive and
        the :class:`discord.ui.Button` being pressed.

        .. note::

            Buttons with a URL or a SKU cannot be created with this function.
            Consider creating a :class:`Button` manually and adding it via
            :meth:`ActionRow.add_item` instead. This is beacuse these buttons
            cannot have a callback associated with them since Discord does not
            do any processing with them.

        Parameters
        ----------
        label: Optional[:class:`str`]
            The label of the button, if any.
            Can only be up to 80 characters.
        custom_id: Optional[:class:`str`]
            The ID of the button that gets received during an interaction.
            It is recommended to not set this parameters to prevent conflicts.
            Can only be up to 100 characters.
        style: :class:`.ButtonStyle`
            The style of the button. Defaults to :attr:`.ButtonStyle.grey`.
        disabled: :class:`bool`
            Whether the button is disabled or not. Defaults to ``False``.
        emoji: Optional[Union[:class:`str`, :class:`.Emoji`, :class:`.PartialEmoji`]]
            The emoji of the button. This can be in string form or a :class:`.PartialEmoji`
            or a full :class:`.Emoji`.
        id: Optional[:class:`int`]
            The ID of the component. This must be unique across the view.

            .. versionadded:: 2.6
        rv   ItemCallbackType[S, Button[V]]r?   c           
     T     t          d           |           }|_        |S )N)r   r   r   r   r   rowr;   )_button__discord_ui_parent__)	rv   retr   r   r   r;   r   rT   r   s	     rG   	decoratorz#ActionRow.button.<locals>.decorator  sN    '#!    C )-C%JrI   )rv   r   r?   r   rp   )rT   r   r   r   r   r   r;   r   s   ``````` rG   r   zActionRow.button^  sN    \	 	 	 	 	 	 	 	 	 	 	 	 rI   .)	rc   optionschannel_typesplaceholderr   
min_values
max_valuesr   r;   rc   Type[SelectT]r   List[SelectOption]r   List[ChannelType]r   r   r   #SelectCallbackDecorator[S, SelectT]c       	            d S rC   rp   )
rT   rc   r   r   r   r   r   r   r   r;   s
             rG   r   zActionRow.select  s	     /2crI   )
rc   r   r   r   r   r   r   r   default_valuesr;   Type[UserSelectT]r   Sequence[ValidDefaultValues]'SelectCallbackDecorator[S, UserSelectT]c       
            d S rC   rp   rT   rc   r   r   r   r   r   r   r   r   r;   s              rG   r   zActionRow.select  	     36#rI   Type[RoleSelectT]'SelectCallbackDecorator[S, RoleSelectT]c       
            d S rC   rp   r   s              rG   r   zActionRow.select  r   rI   Type[ChannelSelectT]*SelectCallbackDecorator[S, ChannelSelectT]c       
            d S rC   rp   r   s              rG   r   zActionRow.select  s	     69SrI   Type[MentionableSelectT].SelectCallbackDecorator[S, MentionableSelectT]c       
            d S rC   rp   r   s              rG   r   zActionRow.select  s	     :=rI   r   Type[BaseSelectT]'SelectCallbackDecorator[S, BaseSelectT]c       
        <    	
 d	
 fd}|S )a&  A decorator that attaches a select menu to the action row.

        The function being decorated should have three parameters, ``self`` representing
        the :class:`discord.ui.ActionRow`, the :class:`discord.Interaction` you receive and
        the chosen select class.

        To obtain the selected values inside the callback, you can use the ``values`` attribute of the chosen class in the callback. The list of values
        will depend on the type of select menu used. View the table below for more information.

        +----------------------------------------+-----------------------------------------------------------------------------------------------------------------+
        | Select Type                            | Resolved Values                                                                                                 |
        +========================================+=================================================================================================================+
        | :class:`discord.ui.Select`             | List[:class:`str`]                                                                                              |
        +----------------------------------------+-----------------------------------------------------------------------------------------------------------------+
        | :class:`discord.ui.UserSelect`         | List[Union[:class:`discord.Member`, :class:`discord.User`]]                                                     |
        +----------------------------------------+-----------------------------------------------------------------------------------------------------------------+
        | :class:`discord.ui.RoleSelect`         | List[:class:`discord.Role`]                                                                                     |
        +----------------------------------------+-----------------------------------------------------------------------------------------------------------------+
        | :class:`discord.ui.MentionableSelect`  | List[Union[:class:`discord.Role`, :class:`discord.Member`, :class:`discord.User`]]                              |
        +----------------------------------------+-----------------------------------------------------------------------------------------------------------------+
        | :class:`discord.ui.ChannelSelect`      | List[Union[:class:`~discord.app_commands.AppCommandChannel`, :class:`~discord.app_commands.AppCommandThread`]]  |
        +----------------------------------------+-----------------------------------------------------------------------------------------------------------------+

        Example
        ---------
        .. code-block:: python3

            class MyView(discord.ui.LayoutView):
                action_row = discord.ui.ActionRow()

                @action_row.select(cls=ChannelSelect, channel_types=[discord.ChannelType.text])
                async def select_channels(self, interaction: discord.Interaction, select: ChannelSelect):
                    return await interaction.response.send_message(f'You selected {select.values[0].mention}')

        Parameters
        ------------
        cls: Union[Type[:class:`discord.ui.Select`], Type[:class:`discord.ui.UserSelect`], Type[:class:`discord.ui.RoleSelect`],             Type[:class:`discord.ui.MentionableSelect`], Type[:class:`discord.ui.ChannelSelect`]]
            The class to use for the select menu. Defaults to :class:`discord.ui.Select`. You can use other
            select types to display different select menus to the user. See the table above for the different
            values you can get from each select type. Subclasses work as well, however the callback in the subclass will
            get overridden.
        placeholder: Optional[:class:`str`]
            The placeholder text that is shown if nothing is selected, if any.
            Can only be up to 150 characters.
        custom_id: :class:`str`
            The ID of the select menu that gets received during an interaction.
            It is recommended not to set this parameter to prevent conflicts.
            Can only be up to 100 characters.
        min_values: :class:`int`
            The minimum number of items that must be chosen for this select menu.
            Defaults to 1 and must be between 0 and 25.
        max_values: :class:`int`
            The maximum number of items that must be chosen for this select menu.
            Defaults to 1 and must be between 1 and 25.
        options: List[:class:`discord.SelectOption`]
            A list of options that can be selected in this menu. This can only be used with
            :class:`Select` instances.
            Can only contain up to 25 items.
        channel_types: List[:class:`~discord.ChannelType`]
            The types of channels to show in the select menu. Defaults to all channels. This can only be used
            with :class:`ChannelSelect` instances.
        disabled: :class:`bool`
            Whether the select is disabled or not. Defaults to ``False``.
        default_values: Sequence[:class:`~discord.abc.Snowflake`]
            A list of objects representing the default values for the select menu. This cannot be used with regular :class:`Select` instances.
            If ``cls`` is :class:`MentionableSelect` and :class:`.Object` is passed, then the type must be specified in the constructor.
            Number of items must be in range of ``min_values`` and ``max_values``.
        id: Optional[:class:`int`]
            The ID of the component. This must be unique across the view.

            .. versionadded:: 2.6
        rv    ItemCallbackType[S, BaseSelectT]r?   c                Z     t          	

  
        |           }|_        |S )N)
rc   r   r   r   r   r   r   r   r   r;   )_selectr   )rv   rr   rc   r   r   r   r;   r   r   r   r   rT   s     rG   r   z#ActionRow.select.<locals>.decoratorB  sW    '#%%+!-    A '+A#HrI   )rv   r   r?   r   rp   )rT   rc   r   r   r   r   r   r   r   r   r;   r   s   ``````````` rG   r   zActionRow.select  sf    p	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	  rI   r   ActionRowComponentc                    ddl m}  | |j                  }|j        D ]!}|                     |||                     "|S )Nr   )_component_to_itemr:   )rz   r   r;   r<   rR   )rc   r   r   rT   cmps        rG   from_componentzActionRow.from_componentT  sb    ,,,,,,sil###% 	9 	9CMM,,S$778888rI   )r<   r=   r;   r>   r?   r@   )r?   r@   )r?   rg   )r?   rn   )r?   r|   )r?   r   )rd   r   r   r2   r   rg   r?   r@   )r?   r   )r?   r   )r?   r   )r?   r   )rw   r   r?   r&   )r;   r   r?   r   )r?   r&   )r?   r   )r   r   r   r   r   r   r   r    r   r   r;   r>   r?   r   )rc   r   r   r   r   r   r   r   r   rg   r   r   r   r   r   r   r;   r>   r?   r   )rc   r   r   r   r   r   r   r   r   rg   r   r   r   r   r   r   r   r   r;   r>   r?   r   )rc   r   r   r   r   r   r   r   r   rg   r   r   r   r   r   r   r   r   r;   r>   r?   r   )rc   r   r   r   r   r   r   r   r   rg   r   r   r   r   r   r   r   r   r;   r>   r?   r   )rc   r   r   r   r   r   r   r   r   rg   r   r   r   r   r   r   r   r   r;   r>   r?   r   )rc   r   r   r   r   r   r   r   r   rg   r   r   r   r   r   r   r   r   r;   r>   r?   r   )r   r   r?   r   )-rk   
__module____qualname____doc__r8   __annotations__r9   __item_repr_attributes__rM   rY   rm   rN   r{   r~   r   r   r   r   propertyrD   r   r   r<   r   r   rR   r   r   r   r   r    	secondaryr   r   r   r   r$   r   r   r   r   r   classmethodr   __classcell__)rV   s   @rG   r   r   O   sz        ( (T RT!SSSS044444&
 !        D D D D D DM M M M	 	 	 	   
           * * * *   X ' ' ' X' ( ( ( X( % % % X%
! 
! 
! 
!b b b b% % % %N   .7 7 7 7(
 
 
 
      $#'(2;? ; ; ; ; ; ;z  $C[&-+.%(2 2 2 2 2 X2  ",C&-+.%(7:6 6 6 6 6 X6  ",C&-+.%(7:6 6 6 6 6 X6  %2#$6&-+.%(7:9 9 9 9 9 X9  ):#(>&-+2%(7:= = = = = X=$ "(&-+2%) 7> h h h h h hT    [    rI   r   )Er   
__future__r   r~   typingr   r   r   r   r   r	   r
   r   r   r   r   r   r   r   rw   r   r   ItemCallbackTyper   r   r   r   r   r   r   r   r   r   r   r   r   r   enumsr    r!   r"   partial_emojir#   utilsr$   r%   r   typing_extensionsr&   rz   r'   r(   r)   r*   r+   r,   r-   r.   r   r/   r0   	containerr1   dynamicr2   SelectCallbackDecoratorr3   r6   __all__rp   rI   rG   <module>r     s   0 # " " " " "                                " U T T T T T T T T T - - - - - - - - g g g g g g g g g g g g g g g g 8 8 8 8 8 8 ; ; ; ; ; ; ; ; ; ; ( ( ( ( ( ( . . . . . . . . Z&&&&&&                        ))))))$$$$$$$$$$$$&(8k9I(J'K['XYGCuCDPTUUUGC|t444
L L L L LQ L L L L LrI   