
    cjh                    V   d Z ddlmZ ddlmZ ddlZddlmZ ddlm	Z	 ddl
mZ ddlmZ dd	lmZ dd
lmZ dZ G d dej&                  j(                        Z G d d      Z G d d      Z G d dej&                  j0                        Z G d dej&                  j4                        Zy)aF  
The MIT License (MIT)

Copyright (c) 2021-present Pycord Development

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

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

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
    )annotations)ListN)DiscordException)BridgeContext)Context)File)Member)User)PaginatorButton	Paginator	PageGroupPaginatorMenuPagec                       e Zd ZdZddej
                  j                  ddddf	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fdZddZ xZ	S )	r   a  Creates a button used to navigate the paginator.

    Parameters
    ----------
    button_type: :class:`str`
        The type of button being created.
        Must be one of ``first``, ``prev``, ``next``, ``last``, or ``page_indicator``.
    label: :class:`str`
        The label shown on the button.
        Defaults to a capitalized version of ``button_type`` (e.g. "Next", "Prev", etc.)
    emoji: Union[:class:`str`, :class:`discord.Emoji`, :class:`discord.PartialEmoji`]
        The emoji shown on the button in front of the label.
    disabled: :class:`bool`
        Whether to initially show the button as disabled.
    loop_label: :class:`str`
        The label shown on the button when ``loop_pages`` is set to ``True`` in the Paginator class.

    Attributes
    ----------
    paginator: :class:`Paginator`
        The paginator class where this button is being used.
        Assigned to the button when ``Paginator.add_button`` is called.
    NFr   c	                    t         	|   |s|r|n|j                         |||||       || _        |s|r|n|j                         | _        || _        || _        || _        |s| j                  n|| _        d | _	        y )N)labelemojistyledisabled	custom_idrow)
super__init__
capitalizebutton_typer   r   r   r   
loop_label	paginator)
selfr   r   r   r   r   r   r   r   	__class__s
            O/var/www/html/venv/lib/python3.12/site-packages/discord/ext/pages/pagination.pyr   zPaginatorButton.__init__G   s     	 E%{/E/E/G 	 	
 '#uU+2H2H2J
AF

 ,6$**J    c                `  K   | j                   j                  }| j                  dk(  rd}n| j                  dk(  rL| j                   j                  r0| j                   j                  dk(  r| j                   j                  }n|dz  }n| j                  dk(  rL| j                   j                  r0| j                   j                  | j                   j                  k(  rd}n+|dz  }n%| j                  dk(  r| j                   j                  }| j                   j                  ||       d{    y7 w)	z|coro|

        The coroutine that is called when the navigation button is clicked.

        Parameters
        ----------
        interaction: :class:`discord.Interaction`
            The interaction created by clicking the navigation button.
        firstr   prev   nextlast)page_numberinteractionN)r   current_pager   
loop_pages
page_count	goto_page)r   r)   new_pages      r    callbackzPaginatorButton.callbackb   s      >>..w&H'~~((T^^-H-HA-M>>44A'))NN//4>>3L3LLA'~~00Hnn&&8&UUUs   D$D.&D,'D.)r   strr   r0   r   *str | discord.Emoji | discord.PartialEmojir   zdiscord.ButtonStyler   boolr   r0   r   intr   r0   r)   discord.Interaction)
__name__
__module____qualname____doc__discordButtonStylegreenr   r/   __classcell__r   s   @r    r   r   .   s    6 <@%,%8%8%>%>  :	
 #    6Vr!   r   c                  "   e Zd ZdZ	 	 	 	 d	 	 	 	 	 	 	 ddZdddZddZedd       Zej                  dd       Zedd       Z
e
j                  dd	       Z
edd
       Zej                  dd       Zedd       Zej                  dd       Zy)r   a  Represents a page shown in the paginator.

    Allows for directly referencing and modifying each page as a class instance.

    Parameters
    ----------
    content: :class:`str`
        The content of the page. Corresponds to the :class:`discord.Message.content` attribute.
    embeds: Optional[List[Union[List[:class:`discord.Embed`], :class:`discord.Embed`]]]
        The embeds of the page. Corresponds to the :class:`discord.Message.embeds` attribute.
    files: Optional[List[:class:`discord.File`]]
        A list of local files to be shown with the page.
    custom_view: Optional[:class:`discord.ui.View`]
        The custom view shown when the page is visible. Overrides the `custom_view` attribute of the main paginator.
    Nc                ~    ||t        j                  d      || _        |xs g | _        || _        |xs g | _        y )Nz9A page cannot have both content and embeds equal to None.)r:   InvalidArgument_content_embeds_custom_view_files)r   contentembedscustom_viewfileskwargss         r    r   zPage.__init__   sJ     ?v~))K   |'krr!   c                   K   yw)a*  |coro|

        The coroutine associated to a specific page. If `Paginator.page_action()` is used, this coroutine is called.

        Parameters
        ----------
        interaction: Optional[:class:`discord.Interaction`]
            The interaction associated with the callback, if any.
        N r   r)   s     r    r/   zPage.callback   s     s   c                    | j                   D ]d  }|j                  j                  r*t        |j                  dd      x}rt	        |d      |_        |j                          d |j                  _        f | j                   S )zUpdates :class:`discord.File` objects so that they can be sent multiple
        times. This is called internally each time the page is sent.
        nameNrbc                      y NrL   rL   r!   r    <lambda>z#Page.update_files.<locals>.<lambda>   s    r!   )rE   fpclosedgetattropenresetclose)r   filefns      r    update_fileszPage.update_files   sf     KK 	)Dww~~&$)G#G2#Gr4.JJL(DGGM		)
 {{r!   c                    | j                   S )zGets the content for the page.rB   r   s    r    rF   zPage.content   s     }}r!   c                    || _         y)zSets the content for the page.Nr^   r   values     r    rF   zPage.content   s     r!   c                    | j                   S )zGets the embeds for the page.rC   r_   s    r    rG   zPage.embeds   s     ||r!   c                    || _         y)zSets the embeds for the page.Nrd   ra   s     r    rG   zPage.embeds   s     r!   c                    | j                   S )z*Gets the custom view assigned to the page.rD   r_   s    r    rH   zPage.custom_view   s        r!   c                    || _         y)z=Assigns a custom view to be shown when the page is displayed.Nrg   ra   s     r    rH   zPage.custom_view   s     "r!   c                    | j                   S )z(Gets the files associated with the page.rE   r_   s    r    rI   z
Page.files   s     {{r!   c                    || _         y)z(Sets the files associated with the page.Nrj   ra   s     r    rI   z
Page.files   s     r!   NNNN)rF   
str | NonerG   0list[list[discord.Embed] | discord.Embed] | NonerH   discord.ui.View | NonerI   list[discord.File] | NonerR   )r)   discord.Interaction | None)returnrp   )rr   rm   )rb   rm   )rr   rn   )rb   rn   )rr   ro   )rb   ro   )rb   rp   )r6   r7   r8   r9   r   r/   r\   propertyrF   setterrG   rH   rI   rL   r!   r    r   r      s    $ #CG.2+/"" A" ,	"
 )""		   ^^    ]]  ! ! " "   \\ r!   r   c                  t    e Zd ZdZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZy)r   a
  Creates a group of pages which the user can switch between.

    Each group of pages can have its own options, custom buttons, custom views, etc.

    .. note::

        If multiple :class:`PageGroup` objects have different options,
        they should all be set explicitly when creating each instance.

    Parameters
    ----------
    pages: Union[List[:class:`str`], List[:class:`Page`], List[Union[List[:class:`discord.Embed`], :class:`discord.Embed`]]]
        The list of :class:`Page` objects, strings, embeds, or list of embeds to include in the page group.
    label: :class:`str`
        The label shown on the corresponding PaginatorMenu dropdown option.
        Also used as the SelectOption value.
    description: Optional[:class:`str`]
        The description shown on the corresponding PaginatorMenu dropdown option.
    emoji: Union[:class:`str`, :class:`discord.Emoji`, :class:`discord.PartialEmoji`]
        The emoji shown on the corresponding PaginatorMenu dropdown option.
    default: Optional[:class:`bool`]
        Whether the page group should be the default page group initially shown when the paginator response is sent.
        Only one ``PageGroup`` can be the default page group.
    show_disabled: :class:`bool`
        Whether to show disabled buttons.
    show_indicator: :class:`bool`
        Whether to show the page indicator when using the default buttons.
    author_check: :class:`bool`
        Whether only the original user of the command can change pages.
    disable_on_timeout: :class:`bool`
        Whether the buttons get disabled when the paginator view times out.
    use_default_buttons: :class:`bool`
        Whether to use the default buttons (i.e. ``first``, ``prev``, ``page_indicator``, ``next``, ``last``)
    default_button_row: :class:`int`
        The row where the default paginator buttons are displayed. Has no effect if custom buttons are used.
    loop_pages: :class:`bool`
        Whether to loop the pages when clicking prev/next while at the first/last page in the list.
    custom_view: Optional[:class:`discord.ui.View`]
        A custom view whose items are appended below the pagination buttons.
    timeout: Optional[:class:`float`]
        Timeout in seconds from last interaction with the paginator before no longer accepting input.
    custom_buttons: Optional[List[:class:`PaginatorButton`]]
        A list of PaginatorButtons to initialize the Paginator with.
        If ``use_default_buttons`` is ``True``, this parameter is ignored.
    trigger_on_display: :class:`bool`
        Whether to automatically trigger the callback associated with a `Page` whenever it is displayed.
        Has no effect if no callback exists for a `Page`.
    Nc                    || _         || _        || _        || _        || _        || _        || _        || _        |	| _        |
| _	        || _
        || _        || _        || _        || _        || _        y rR   )r   descriptionr   pagesdefaultshow_disabledshow_indicatorauthor_checkdisable_on_timeoutuse_default_buttonsdefault_button_rowr+   rH   timeoutcustom_buttonstrigger_on_display)r   rx   r   rw   r   ry   rz   r{   r|   r}   r~   r   r+   rH   r   r   r   s                    r    r   zPageGroup.__init__  s~    & 
'2AF
LQ
$+*,("4#6 "4$,7%$2"4r!   )NNNNNNNNr   NNNNN) rx   zBlist[str] | list[Page] | list[list[discord.Embed] | discord.Embed]r   r0   rw   rm   r   r1   ry   bool | Nonerz   r   r{   r   r|   r   r}   r   r~   r   r   r3   r+   r   rH   ro   r   float | Noner   list[PaginatorButton] | Noner   r   )r6   r7   r8   r9   r   rL   r!   r    r   r      s    /j #'<@#%)&*$(*.+/"#"&.2 $7;*.#"5Q"5 "5  	"5
 :"5 "5 #"5 $"5 ""5 ("5 )"5  "5  "5 ,"5 "5  5!"5" (#"5r!   r   c                      e Zd ZdZ	 	 	 	 	 	 	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fdZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZddZ	 	 d	 	 	 	 	 ddZ	 	 d	 	 	 	 	 ddZdd dZ		 ddd		 	 	 	 	 d!d
Z
d"dZd Zd Zd#dZd$dZd%dZd&dZd'dZe	 	 	 	 d(d       Zd)d*dZ	 	 	 	 	 	 d+	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d,dZ	 	 	 	 d-	 	 	 	 	 	 	 	 	 	 	 d.dZ	 	 	 d/	 	 	 	 	 	 	 	 	 d0dZ xZS )1r   a+  Creates a paginator which can be sent as a message and uses buttons for navigation.

    Parameters
    ----------
    pages: Union[List[:class:`PageGroup`], List[:class:`Page`], List[:class:`str`], List[Union[List[:class:`discord.Embed`], :class:`discord.Embed`]]]
        The list of :class:`PageGroup` objects, :class:`Page` objects, strings, embeds, or list of embeds to paginate.
        If a list of :class:`PageGroup` objects is provided and `show_menu` is ``False``,
        only the first page group will be displayed.
    show_disabled: :class:`bool`
        Whether to show disabled buttons.
    show_indicator: :class:`bool`
        Whether to show the page indicator when using the default buttons.
    show_menu: :class:`bool`
        Whether to show a select menu that allows the user to switch between groups of pages.
    menu_placeholder: :class:`str`
        The placeholder text to show in the page group menu when no page group has been selected yet.
        Defaults to "Select Page Group" if not provided.
    author_check: :class:`bool`
        Whether only the original user of the command can change pages.
    disable_on_timeout: :class:`bool`
        Whether the buttons get disabled when the paginator view times out.
    use_default_buttons: :class:`bool`
        Whether to use the default buttons (i.e. ``first``, ``prev``, ``page_indicator``, ``next``, ``last``)
    default_button_row: :class:`int`
        The row where the default paginator buttons are displayed. Has no effect if custom buttons are used.
    loop_pages: :class:`bool`
        Whether to loop the pages when clicking prev/next while at the first/last page in the list.
    custom_view: Optional[:class:`discord.ui.View`]
        A custom view whose items are appended below the pagination components.
        If the currently displayed page has a `custom_view` assigned, it will replace these
        view components when that page is displayed.
    timeout: Optional[:class:`float`]
        Timeout in seconds from last interaction with the paginator before no longer accepting input.
    custom_buttons: Optional[List[:class:`PaginatorButton`]]
        A list of PaginatorButtons to initialize the Paginator with.
        If ``use_default_buttons`` is ``True``, this parameter is ignored.
    trigger_on_display: :class:`bool`
        Whether to automatically trigger the callback associated with a `Page` whenever it is displayed.
        Has no effect if no callback exists for a `Page`.

    Attributes
    ----------
    menu: Optional[List[:class:`PaginatorMenu`]]
        The page group select menu associated with this paginator.
    page_groups: Optional[List[:class:`PageGroup`]]
        List of :class:`PageGroup` objects the user can switch between.
    default_page_group: Optional[:class:`int`]
        The index of the default page group shown when the paginator is initially sent.
        Defined by setting ``default`` to ``True`` on a :class:`PageGroup`.
    current_page: :class:`int`
        A zero-indexed value showing the current page number.
    page_count: :class:`int`
        A zero-indexed value showing the total number of pages.
    buttons: Dict[:class:`str`, Dict[:class:`str`, Union[:class:`~PaginatorButton`, :class:`bool`]]]
        A dictionary containing the :class:`~PaginatorButton` objects included in this paginator.
    user: Optional[Union[:class:`~discord.User`, :class:`~discord.Member`]]
        The user or member that invoked the paginator.
    message: Union[:class:`~discord.Message`, :class:`~discord.WebhookMessage`]
        The message the paginator is attached to.
    Nc                   t         |   |       || _        || _        d| _        d | _        || _        || _        d | _        d| _	        t        d |D              r|r| j                  nd | _        t        d | j                  D              dkD  rt        d      | j                  D ]0  }|j                  s| j                  j                  |      | _	         n | j                  | j                  | j                           | _        t!        t#        | j                        dz
  d      | _        i | _        || _        || _        || _        || _        || _        |	| _        |
| _        || _        || _        d | _        | j(                  r%| j0                  s|D ]  }| j=                  |        n(| j(                  s| j0                  r| j?                          | j                  r| jA                          || _!        d | _"        y )N)r   r   c              3  <   K   | ]  }t        |t                y wrR   
isinstancer   .0pgs     r    	<genexpr>z%Paginator.__init__.<locals>.<genexpr>  s     9Rz"i(9   c              3  8   K   | ]  }|j                   d u   ywTNry   r   s     r    r   z%Paginator.__init__.<locals>.<genexpr>       A"2::%A   r%   -Only one PageGroup can be set as the default.)#r   r   r   rx   r*   menu	show_menumenu_placeholderpage_groupsdefault_page_groupallsum
ValueErrorry   indexget_page_group_contentmaxlenr,   buttonsr   rz   r{   r}   r~   r   r+   rH   r   message
add_buttonadd_default_buttonsadd_menu	usercheckuser)r   rx   rz   r{   r   r   r|   r}   r~   r   r+   rH   r   r   r   r   buttonr   s                    r    r   zPaginator.__init__w  s   , 	)%  	
 *.	" 037'(9599-6tzzDDA0@0@AAAE !PQQ&& ::.2.>.>.D.DR.HD+ &*%@%@  !8!89&DJ c$**o115$2*,"4#6 "4$,7"4HLt'?'?( ('($$)A)A$$&>>MMO%	r!   c                F  K   ||n| j                   | _         ||n| j                  | _        |t        d |D              r| j                  r| j                   nd| _        t	        d | j                  D              dkD  rt        d      | j                  D ]0  }|j                  s| j                  j                  |      | _         n | j                  | j                  | j                           | _         t        t        | j                         dz
  d      | _        || j                  k  r|nd| _        ||n| j                  | _        ||n| j                  | _        ||n| j                   | _        ||n| j"                  | _        ||n| j$                  | _        ||n| j&                  | _        |	|	n| j(                  | _        |
|
n| j*                  | _        |dn|| _        ||n| j.                  | _        ||n| j0                  | _        ||n| j2                  | _        i | _        | j&                  r| j7                          n.| j0                  r"| j0                  D ]  }| j9                  |        | j;                  | j                  |       d{    y7 w)a
  Updates the existing :class:`Paginator` instance with the provided options.

        Parameters
        ----------
        pages: Optional[Union[List[:class:`PageGroup`], List[:class:`Page`], List[:class:`str`], List[Union[List[:class:`discord.Embed`], :class:`discord.Embed`]]]]
            The list of :class:`PageGroup` objects, :class:`Page` objects, strings,
            embeds, or list of embeds to paginate.
        show_disabled: :class:`bool`
            Whether to show disabled buttons.
        show_indicator: :class:`bool`
            Whether to show the page indicator when using the default buttons.
        show_menu: :class:`bool`
            Whether to show a select menu that allows the user to switch between groups of pages.
        author_check: :class:`bool`
            Whether only the original user of the command can change pages.
        menu_placeholder: :class:`str`
            The placeholder text to show in the page group menu when no page group has been selected yet.
            Defaults to "Select Page Group" if not provided.
        disable_on_timeout: :class:`bool`
            Whether the buttons get disabled when the paginator view times out.
        use_default_buttons: :class:`bool`
            Whether to use the default buttons (i.e. ``first``, ``prev``, ``page_indicator``, ``next``, ``last``)
        default_button_row: Optional[:class:`int`]
            The row where the default paginator buttons are displayed. Has no effect if custom buttons are used.
        loop_pages: :class:`bool`
            Whether to loop the pages when clicking prev/next while at the first/last page in the list.
        custom_view: Optional[:class:`discord.ui.View`]
            A custom view whose items are appended below the pagination components.
        timeout: Optional[:class:`float`]
            Timeout in seconds from last interaction with the paginator before no longer accepting input.
        custom_buttons: Optional[List[:class:`PaginatorButton`]]
            A list of PaginatorButtons to initialize the Paginator with.
            If ``use_default_buttons`` is ``True``, this parameter is ignored.
        trigger_on_display: :class:`bool`
            Whether to automatically trigger the callback associated with a `Page` whenever it is displayed.
            Has no effect if no callback exists for a `Page`.
        interaction: Optional[:class:`discord.Interaction`]
            The interaction to use when updating the paginator. If not provided, the paginator will be updated
            by using its stored :attr:`message` attribute instead.
        current_page: :class:`int`
            The initial page number to display when updating the paginator.
        Nc              3  <   K   | ]  }t        |t                y wrR   r   r   s     r    r   z#Paginator.update.<locals>.<genexpr>  s     $O2ZI%>$Or   c              3  8   K   | ]  }|j                   d u   ywr   r   r   s     r    r   z#Paginator.update.<locals>.<genexpr>  r   r   r%   r   r   r)   )rx   r   r   r   r   r   ry   r   r   r   r   r   r,   r*   rz   r{   r   r   r}   r~   r   r+   rH   r   r   r   r   r   r   r-   )r   rx   rz   r{   r   r|   r   r}   r~   r   r+   rH   r   r   r   r)   r*   r   r   s                      r    updatezPaginator.update  s    R 'UTZZ 	
 '0&;$O$O!O-1^^tzzDA0@0@AAAE !PQQ&& ::.2.>.>.D.DR.HD+ &*%@%@  !8!89&DJ c$**o115,8DOO,KLQR +6MD<N<N 	 -8Nd>Q>Q 	 *6)At~~ 0 <$BWBW 	
 "- (( 	 #.  )) 	  "- (( 	
 )3(>*DOO4?4GD[)0)<g$,,,8Nd>Q>Q 	
 "- (( 	
 ##$$&  -- ('( nnT..KnHHHs   B#J!&G3J!JJ!c                "  K   | j                   r}| j                  D ]	  }d|_         | j                  | j                     }| j                  |      }|j                         }| j                  j                  | |xs g g        d{    yy7 w)z-Disables all buttons when the view times out.T)viewrI   attachmentsN)	r}   childrenr   rx   r*   get_page_contentr\   r   edit)r   itempagerI   s       r    
on_timeoutzPaginator.on_timeoutG  s     "" % $%::d//0D((.D%%'E,,##kr $    #s   BBBBc                v  K   | j                  |      }| j                  D ]0  }|s%| j                  r|| j                  j                  vs*d|_        2 |r;| j                  j                  |j                  |j                  |        d{    y| j                  j                  |        d{    y7 *7 w)az  Stops the paginator, disabling all of its components.

        Parameters
        ----------
        include_custom: :class:`bool`
            Whether to disable components added via custom views.
        page: Optional[Union[:class:`str`, Union[List[:class:`discord.Embed`], :class:`discord.Embed`]]]
            The page content to show after disabling the paginator.
        TrF   rG   r   Nr   )r   r   rH   r   r   r   rF   rG   )r   include_customr   r   s       r    disablezPaginator.disableU  s      $$T*MM 	%D''t//888 $	% ,,##{{ $    ,,###... /s+   AB9
A B9
B5$B9/B70B97B9c                  K   | j                   j                         }| j                  |      }|D ]:  }|s%| j                  r|| j                  j                   vs*| j	                  |       < |r;| j
                  j                  |j                  |j                  |        d{    y| j
                  j                  |        d{    y7 *7 w)a  Cancels the paginator, removing all of its components from the message.

        Parameters
        ----------
        include_custom: :class:`bool`
            Whether to remove components added via custom views.
        page: Optional[Union[:class:`str`, Union[List[:class:`discord.Embed`], :class:`discord.Embed`]]]
            The page content to show after canceling the paginator.
        r   Nr   )	r   copyr   rH   remove_itemr   r   rF   rG   )r   r   r   itemsr   s        r    cancelzPaginator.cancelt  s      ""$$$T* 	'D''t//888  &	' ,,##{{ $    ,,###... /s+   ACA
C$C%$C	C
CCc                    || _         | j                          | j                  |   }| j                  |      }|j                  r| j                  |j                         |j                         }||fS rR   )r*   update_buttonsrx   r   rH   update_custom_viewr\   )r   r(   r   rI   s       r    
_goto_pagezPaginator._goto_page  si    'zz+&$$T*##D$4$45!!#U{r!   r   c               ^  K   | j                   }| j                  |      \  }}	 |rx|j                  j                          d{    |j                  j                  | j                  j                  |j                  |j                  g |xs g |        d{    n@| j                  j                  |j                  |j                  g |xs g |        d{    | j                  r| j                  |       d{    yy7 7 o7 0# t        $ r | j                  |        w xY w7 +w)a  Updates the paginator message to show the specified page number.

        Parameters
        ----------
        page_number: :class:`int`
            The page to display.

            .. note::

                Page numbers are zero-indexed when referenced internally,
                but appear as one-indexed when shown to the user.

        interaction: Optional[:class:`discord.Interaction`]
            The interaction to use when editing the message. If not provided, the message will be
            edited using the paginator's stored :attr:`message` attribute instead.

        Returns
        -------
        :class:`~discord.Message`
            The message associated with the paginator.
        N)
message_idrF   rG   r   rI   r   )rF   rG   r   rI   r   r   )r*   r   responsedeferfollowupedit_messager   idrF   rG   r   r   r   page_action)r   r(   r)   old_pager   rI   s         r    r-   zPaginator.goto_page  s+    0 $$ook2e	!**00222!**77#|| LL;; "+2 8    ll'' LL;; "+2 (    """"{";;; #/ 3   	 OOH%		 <s`   !D-D DAD DA D D
D !D-?D+ D-D D 
D D((D-c                V   K   | j                   r| j                  |j                  k(  S yw)NT)r   r   rM   s     r    interaction_checkzPaginator.interaction_check  s%     >>99 0 000s   ')c                    t        | j                  | j                        | _        | | j                  _        | j                  | j                         y)zBAdds the default :class:`PaginatorMenu` instance to the paginator.)placeholderN)r   r   r   r   r   add_itemr_   s    r    r   zPaginator.add_menu  s8    !$"2"2@U@UV	"		dii r!   c           
        t        ddt        j                  j                  | j                        t        ddt        j                  j
                  d| j                        t        dt        j                  j                  d	| j                  
      t        ddt        j                  j                  d| j                        t        ddt        j                  j                  | j                        g}|D ]  }| j                  |        y)zAdds the full list of default buttons that can be used with the paginator.
        Includes ``first``, ``prev``, ``page_indicator``, ``next``, and ``last``.
        r#   z<<)r   r   r   r$   <u   ↪)r   r   r   r   page_indicatorT)r   r   r   r&   >u   ↩r'   z>>N)	r   r:   r;   blurpler   redgrayr<   r   )r   default_buttonsr   s      r    r   zPaginator.add_default_buttons  s    
 ))11++	 ))-- ++  ))..++	 ))// ++ ))11++	7!
D & 	$FOOF#	$r!   c                   t         j                  j                  |j                  |j                  s|j
                  r|j                  nI|j                  dk7  r|j                  j                         n | j                  dz    d| j                  dz    |j                  |j                  |j
                  |j                        |j                  |j                  |j                  dk7  r|j                  n| j                   d| j                  |j                  <   |j                   | j                  |j                     d   _        | |_        y)z1Adds a :class:`PaginatorButton` to the paginator.r   r%   /)r   r   r   r   r   r   )objectr   r   hiddenr   N)r:   uiButtonr   r   r   r   r   r*   r,   r   r   r   r   r{   r   r/   r   )r   r   s     r    r   zPaginator.add_button  s    jj''ll ||v|| LL "--1AA **557 $ 1 1A 56a!8K7LM   **llJJ (   \\ ++ %%)99 ,,,-,
V''(2 ?EooV''(2;r!   c                    || j                   j                         vrt        d| d      | j                   j                  |       y)z6Removes a :class:`PaginatorButton` from the paginator.zno button_type z was found in this paginator.N)r   keysr   pop)r   r   s     r    remove_buttonzPaginator.remove_button+  sE    dll//11!+.KL  	%r!   c                   | j                   j                         D ]^  \  }}|dk(  r+| j                  dk  rd|d<   !| j                  dk\  s1d|d<   7|dk(  rD| j                  | j                  dz
  k\  rd|d<   | j                  | j                  dz
  k  szd|d<   |dk(  rs| j                  | j                  k(  r-| j                  sd|d<   |d   |d	   _        |d
   |d	   _        | j                  | j                  k  sd|d<   |d   |d	   _        |dk(  s| j                  dk  r/| j                  sd|d<   |d   |d	   _        -|d
   |d	   _        <| j                  dk\  sMd|d<   |d   |d	   _        a | j                          | j                  r7	 | j                  dz    d| j                  dz    | j                   d   d	   _        | j                   j                         D ]{  \  }}|dk7  rP|d   r,d|d	   _	        | j                  s'| j                  |d	          <d|d	   _	        | j                  |d	          [| j                  sh| j                  |d	          } | j                  r| j                          | j                  r| j                  | j                         | j                   S # t        $ r Y w xY w)zUpdates the display state of the buttons (disabled/hidden)

        Returns
        -------
        Dict[:class:`str`, Dict[:class:`str`, Union[:class:`~PaginatorButton`, :class:`bool`]]]
            The dictionary of buttons that were updated.
        r#   r%   Tr   Fr'   r&   r   r   r   r$   r   r   r   )r   r   r*   r,   r+   r   clear_itemsr{   KeyErrorr   rz   r   r   r   rH   r   )r   keyr   s      r    r   zPaginator.update_buttons3  s     <<--/ 	=KCg~$$)'+F8$&&!+',F8$$$!(;;'+F8$$$t'::',F8$$$7??+/x(17x(.171Ex(.&&8',F8$-3G_F8$*$$)??+/x(17x(.171Ex(.&&!+',F8$-3G_F8$*=	=> 	 "..231T__q5H4IJ -.  <<--/ 
	0KC&&(#04F8$-))fX&6705F8$-MM&"23$$fX./
	0 >>MMO ##D$4$45||-  s   6J7 7	KKc                    t        | j                  t        j                  j                        r,| j                  j
                  D ]  }| j                  |        |j
                  D ]  }| j                  |        y)z/Updates the custom view shown on the paginator.N)r   rH   r:   r   Viewr   r   r   )r   rH   r   s      r    r   zPaginator.update_custom_viewx  sd    d&&

8((11 '  &'(( 	 DMM$	 r!   c                ^    |j                   D cg c]  }| j                  |       c}S c c}w )zfReturns a converted list of `Page` objects for the given page group based on the content of its pages.)rx   r   )r   
page_groupr   s      r    r   z Paginator.get_page_group_content  s'    8B8H8HI%%d+IIIs   *c                   t        | t              r| S t        | t              rt        | g g       S t        | t        j                        rt        d| gg       S t        | t        j
                        rt        dg | g      S t        | t              rKt        d | D              rt        d| g       S t        d | D              rt        dg |       S t        d      t        d      )zAConverts a page into a :class:`Page` object based on its content.)rF   rG   rI   Nc              3  P   K   | ]  }t        |t        j                           y wrR   )r   r:   Embedr   xs     r    r   z-Paginator.get_page_content.<locals>.<genexpr>  s     >A:a/>   $&c              3  P   K   | ]  }t        |t        j                           y wrR   )r   r:   r   r   s     r    r   z-Paginator.get_page_content.<locals>.<genexpr>  s     =1:a.=r   z'All list items must be embeds or files.zcPage content must be a Page object, string, an embed, a list of embeds, a file, or a list of files.)	r   r   r0   r:   r   r   r   r   	TypeError)r   s    r    r   zPaginator.get_page_content  s    
 dD!Kc"Rr::gmm,dV2>>gll+Rv>>d#>>>DR@@===D4@@ IJJ7 r!   c                   K   | j                  | j                  | j                           j                  rA| j                  | j                  | j                           j                  |       d{    yy7 w)zTriggers the callback associated with the current page, if any.

        Parameters
        ----------
        interaction: Optional[:class:`discord.Interaction`]
            The interaction that was used to trigger the page action.
        r   N)r   rx   r*   r/   rM   s     r    r   zPaginator.page_action  sq        D,=,=!>?HH''

43D3D(EFOO' P    Is   A.A90A71A9c           
     
  K   t        |t              st        d|j                        |<t        |t        j
                  j                        st        d|j                        |Qt        |t        j                  t        j                  t        j                  f      st        d|j                        |2t        |t        j                        st        d|j                        |(t        |t              st        d|j                        | j                          | j                  | j                     }| j                  |      }	|	j                   r| j#                  |	j                          |j$                  | _        |r!|r|j)                  ||||       d{    |}|j)                  |	j*                  |	j,                  |	j.                  | ||||       d{   | _        | j0                  S 7 V7 w)	a  Sends a message with the paginated items.

        Parameters
        ----------
        ctx: Union[:class:`~discord.ext.commands.Context`]
            A command's invocation context.
        target: Optional[:class:`~discord.abc.Messageable`]
            A target where the paginated message should be sent, if different from the original :class:`Context`
        target_message: Optional[:class:`str`]
            An optional message shown when the paginator message is sent elsewhere.
        reference: Optional[Union[:class:`discord.Message`, :class:`discord.MessageReference`, :class:`discord.PartialMessage`]]
            A reference to the :class:`~discord.Message` to which you are replying with the paginator.
            This can be created using :meth:`~discord.Message.to_reference` or passed directly as a
            :class:`~discord.Message`. You can control whether this mentions the author of the referenced message
            using the :attr:`~discord.AllowedMentions.replied_user` attribute of ``allowed_mentions`` or by
            setting ``mention_author``.
        allowed_mentions: Optional[:class:`~discord.AllowedMentions`]
            Controls the mentions being processed in this message. If this is
            passed, then the object is merged with :attr:`~discord.Client.allowed_mentions`.
            The merging behaviour only overrides attributes that have been explicitly passed
            to the object, otherwise it uses the attributes set in :attr:`~discord.Client.allowed_mentions`.
            If no object is passed at all then the defaults given by :attr:`~discord.Client.allowed_mentions`
            are used instead.
        mention_author: Optional[:class:`bool`]
            If set, overrides the :attr:`~discord.AllowedMentions.replied_user` attribute of ``allowed_mentions``.
        delete_after: Optional[:class:`float`]
            If set, deletes the paginator after the specified time.

        Returns
        -------
        :class:`~discord.Message`
            The message that was sent with the paginator.
        zexpected Context not Nexpected abc.Messageable not z:expected Message, MessageReference, or PartialMessage not zexpected AllowedMentions not zexpected bool not )	referenceallowed_mentionsmention_author)rF   rG   rI   r   r   r   r   delete_after)r   r   r   r   r:   abcMessageableMessageMessageReferencePartialMessageAllowedMentionsr2   r   rx   r*   r   rH   r   authorr   sendrF   rG   rI   r   )
r   ctxtargettarget_messager   r   r   r   r   page_contents
             r    r  zPaginator.send  s    Z #w'3CMM3DEFFj9P9P&Q;F<L<L;OPQQ __g668N8NO*
 ''*, 
 '
g551
 /0@0J0J/MN  %j.N01I1I0LMNNzz$++,,,T2####L$<$<=JJ	hh"'%5#1	     C XX ((&&$$-)% & 	
 	
 ||'	
s%   F&H(G?)A H)H*HHc           
     h  K   t        |t        j                        st        d|j                        | j                          | j                  | j                     }| j                  |      }|j                  r| j                  |j                         |xs | j                  | _        	 |j                  |j                  |j                  |j                  g | |||       d{   | _        | j                   S 7 # t        j"                  t        j$                  f$ r Y | j                   S w xY ww)am  Edits an existing message to replace it with the paginator contents.

        .. note::

            If invoked from an interaction, you will still need to respond to the interaction.

        Parameters
        ----------
        message: :class:`discord.Message`
            The message to edit with the paginator.
        suppress: :class:`bool`
            Whether to suppress embeds for the message. This removes
            all the embeds if set to ``True``. If set to ``False``
            this brings the embeds back if they were suppressed.
            Using this parameter requires :attr:`~.Permissions.manage_messages`.
        allowed_mentions: Optional[:class:`~discord.AllowedMentions`]
            Controls the mentions being processed in this message. If this is
            passed, then the object is merged with :attr:`~discord.Client.allowed_mentions`.
            The merging behaviour only overrides attributes that have been explicitly passed
            to the object, otherwise it uses the attributes set in :attr:`~discord.Client.allowed_mentions`.
            If no object is passed at all then the defaults given by :attr:`~discord.Client.allowed_mentions`
            are used instead.
        delete_after: Optional[:class:`float`]
            If set, deletes the paginator after the specified time.
        user: Optional[Union[:class:`~discord.User`, :class:`~discord.Member`]]
            If set, changes the user that this paginator belongs to.

        Returns
        -------
        Optional[:class:`discord.Message`]
            The message that was edited. Returns ``None`` if the operation failed.
        zexpected Message not )rF   rG   rI   r   r   suppressr   r   N)r   r:   r   r   r   r   rx   r*   r   rH   r   r   r   rF   rG   rI   r   NotFound	Forbidden)r   r   r
  r   r   r   r   r  s           r    r   zPaginator.edit  s    P '7??33G4E4E3HIJJAEB
 "2248####L$<$<=%DII		!($,,#**"((!!1) ". 	" 	DL ||	   '"3"34 	||	s<   B)D2,:C> &C<'	C> 0D2<C> >#D/!D2.D//D2c                V  K   t        |t        j                  t        f      st	        d|j
                        |<t        |t        j                  j                        st	        d|j
                        |r&| j                  dk\  s| j                  t        d      | j                          | j                  | j                     }| j                  |      }|j                  r| j                  |j                         t        |t        j                        rM|j                   | _        |rb|j"                  j%                  ||       d{    |j'                  |j(                  |j*                  |j,                  |        d{   }n|j"                  j/                         rw|j0                  j'                  |j(                  |j*                  |j,                  | |       d{   }|s|j2                  j5                  |j6                         d{   }n|j"                  j%                  |j(                  |j*                  |j,                  | |       d{   }n|}|j8                  | _        |rW|j;                  ||       d{    |j'                  |j(                  |j*                  |j,                  |        d{   }n;|j;                  |j(                  |j*                  |j,                  |        d{   }t        |t        j<                  t        j>                  f      r|| _         | j@                  S t        |t        j                        r|jC                          d{   | _         | j@                  S 7 A7 	7 7 }7 97 7 7 7 +w)	a  Sends an interaction response or followup with the paginated items.

        Parameters
        ----------
        interaction: Union[:class:`discord.Interaction`, :class:`BridgeContext`]
            The interaction or BridgeContext which invoked the paginator.
            If passing a BridgeContext object, you cannot make this an ephemeral paginator.
        ephemeral: :class:`bool`
            Whether the paginator message and its components are ephemeral.
            If ``target`` is specified, the ephemeral message content will be ``target_message`` instead.

            .. warning::

                If your paginator is ephemeral, it cannot have a timeout
                longer than 15 minutes (and cannot be persistent).

        target: Optional[:class:`~discord.abc.Messageable`]
            A target where the paginated message should be sent,
            if different from the original :class:`discord.Interaction`
        target_message: :class:`str`
            The content of the interaction response shown when the paginator message is sent elsewhere.

        Returns
        -------
        Union[:class:`~discord.Message`, :class:`~discord.WebhookMessage`]
            The :class:`~discord.Message` or :class:`~discord.WebhookMessage` that was sent with the paginator.
        z+expected Interaction or BridgeContext, not Nr   i  zYpaginator responses cannot be ephemeral if the paginator timeout is 15 minutes or greater)	ephemeral)rF   rG   rI   r   )rF   rG   rI   r   r  )"r   r:   Interactionr   r   r   r   r   r   r   r   rx   r*   r   rH   r   r   r   send_messager  rF   rG   rI   is_doner   channelfetch_messager   r  respondr   WebhookMessager   original_response)	r   r)   r  r  r  r   r  msgr  s	            r    r  zPaginator.respondX  sS    F +(;(;]'KL=k>S>S=VW  j9P9P&Q;F<L<L;OPQQ$,,#-1E& 
 	AEB
 "2248####L$<$<=k7#6#67#((DI!**77"i 8    #KK(00'..&,,	 (   %%--/'0055(00'..&,,' 6   ! # 9 9#&& AAC'00==(00'..&,,' >   C

DIkk.IkFFFHH(00'..&,,	 %    KK(00'..&,,	 (   cGOOW-C-CDEDL || W001!$!6!6!88DL||i B G 9s   EN)N:N)NA!N)-N./N)NAN)$N%0N)N :N)N#;N)N%A.N);N'<N)N)N)N)N) N)#N)%N)'N))TTFzSelect Page GroupTTTr   FNg     f@NN)rx   zTlist[PageGroup] | list[Page] | list[str] | list[list[discord.Embed] | discord.Embed]rz   r2   r   r0   r   r3   rH   ro   r   r   r   r   r   r   rr   None)NNNNNNNNNNNNNNNr   ) rx   z]None | (list[PageGroup] | list[Page] | list[str] | list[list[discord.Embed] | discord.Embed])rz   r   r{   r   r   r   r|   r   r   rm   r}   r   r~   r   r   z
int | Noner+   r   rH   ro   r   r   r   r   r   r   r)   rq   r*   r3   )rr   r  )FN)r   r2   r   z9None | (str | Page | list[discord.Embed] | discord.Embed)rr   r  )r   )r(   r3   rr   ztuple[Page, list[File] | None])r(   r3   r)   rq   rr   r  )r)   r5   rr   r2   )r   r   )r   r0   )rr   dict)rH   zdiscord.ui.View)r   r   rr   z
list[Page])r   z0Page | str | discord.Embed | list[discord.Embed]rr   r   rR   )r)   rq   rr   r  )NNNNNN)r  r   r  discord.abc.Messageable | Noner  rm   r   zLNone | (discord.Message | discord.MessageReference | discord.PartialMessage)r   discord.AllowedMentions | Noner   r   r   r   rr   discord.Messagerl   )r   r  r
  r   r   r  r   r   r   zUser | Member | Nonerr   zdiscord.Message | None)FNzPaginator sent!)
r)   z#discord.Interaction | BridgeContextr  r2   r  r  r  r0   rr   z(discord.Message | discord.WebhookMessage)r6   r7   r8   r9   r   r   r   r   r   r   r-   r   r   r   r   r   r   r   r   staticmethodr   r   r  r   r  r=   r>   s   @r    r   r   9  s   ;J # 3 "#.2 %7;*.)H8H H H  H" ,#H$ %H& 5'H( ()H* 
+Hb %)&*!%$('+*.+/)-"&.2 $7;*.26-DI
DI #DI $DI DI "DI %DI (DI )DI 'DI   !DI" ,#DI$ %DI& 5'DI( ()DI* 0+DI, -DIL   %JN// H/ 
	/B  %JN// H/ 
	/@ "#5<QU5<5<4N5<	5<n
!'$R <&CJ J >	 2  26%) ;?&*%)dd /d #	d

d 9d $d #d 
dR !%;?%)%)E E E 9	E
 #E #E 
 ET  15/s8s s /	s
 s 
2sr!   r   c                  <     e Zd ZdZ	 	 d	 	 	 	 	 d fdZddZ xZS )r   a  Creates a select menu used to switch between page groups, which can each have their own set of buttons.

    Parameters
    ----------
    placeholder: :class:`str`
        The placeholder text that is shown if nothing is selected.

    Attributes
    ----------
    paginator: :class:`Paginator`
        The paginator class where this menu is being used.
        Assigned to the menu when ``Paginator.add_menu`` is called.
    c           	        || _         d | _        | j                   D cg c]C  }t        j                  |j                  |j                  |j
                  |j                        E }}t        | !  |dd||       y c c}w )N)r   rb   rw   r   r%   )r   
max_values
min_valuesoptionsr   )	r   r   r:   SelectOptionr   rw   r   r   r   )r   r   r   r   r   optsr   s         r    r   zPaginatorMenu.__init__  s     '+/ #..
     && &&&22 &&	
 
 	# 	 	

s   AA=c                  K   | j                   d   }| j                  D ]  }||j                  k(  s| j                  j	                  |j
                  |j                  |j                  |j                  |j                  |j                  |j                  |j                  |j                  |j                  |j                  |j                   |       d{   c S  y7 w)z|coro|

        The coroutine that is called when a menu option is selected.

        Parameters
        ----------
        interaction: :class:`discord.Interaction`
            The interaction created by selecting the menu option.
        r   )rx   rz   r{   r|   r}   r~   r   r+   rH   r   r   r   r)   N)valuesr   r   r   r   rx   rz   r{   r|   r}   r~   r   r+   rH   r   r   r   )r   r)   	selectionr   s       r    r/   zPaginatorMenu.callback  s      KKN	** 	JJ,,,!^^22$**",":":#-#<#<!+!8!8'1'D'D(2(F(F'1'D'D)44 * 6 6&..#-#<#<'1'D'D + 3   	s   .CB#CC	C)NN)r   zlist[PageGroup]r   rm   r   rm   r4   )r6   r7   r8   r9   r   r/   r=   r>   s   @r    r   r     s6    " #' $	
$
  
 	
2r!   r   )r9   
__future__r   typingr   r:   discord.errorsr   discord.ext.bridger   discord.ext.commandsr   discord.filer   discord.memberr	   discord.userr
   __all__r   r   r   r   r   r   r   Selectr   rL   r!   r    <module>r2     s   0 #   + , (  ! PVgjj'' PVf^ ^BT5 T5nR

 RjCGJJ%% Cr!   