Skip to content

yuyo.pagination#

Utilities used for quick pagination handling within reaction and component executors.

BLACK_CROSS module-attribute #

BLACK_CROSS = UnicodeEmoji('✖️')

The emoji used to close a menu in a component context.

EntryT module-attribute #

EntryT = Union[tuple[UndefinedOr[str], UndefinedOr[Embed]], 'AbstractPage']

A type hint used to represent a paginator entry.

This may be either AbstractPage or tuple[hikari.UndefinedOr[str], hikari.UndefinedOr[hikari.Embed]] where tuple[0] is the message content and tuple[1] is an embed to send.

LEFT_DOUBLE_TRIANGLE module-attribute #

LEFT_DOUBLE_TRIANGLE = UnicodeEmoji('⏮️')

The emoji used to go back to the first entry.

LEFT_TRIANGLE module-attribute #

LEFT_TRIANGLE = UnicodeEmoji('◀️')

The emoji used to go back an entry.

LocalizedPage module-attribute #

LocalizedPage = LocalisedPage

Alias of LocalisedPage.

RIGHT_DOUBLE_TRIANGLE module-attribute #

RIGHT_DOUBLE_TRIANGLE = UnicodeEmoji('⏭️')

The emoji used for the (not enabled by default) skip to last entry button.

RIGHT_TRIANGLE module-attribute #

RIGHT_TRIANGLE = UnicodeEmoji('▶️')

The emoji used to continue to the next entry.

SELECT_PAGE_SYMBOL module-attribute #

SELECT_PAGE_SYMBOL = UnicodeEmoji('🔢')

The emoji used for the select specific page button which triggers a modal.

STOP_SQUARE module-attribute #

STOP_SQUARE = UnicodeEmoji('⏹️')

The emoji used to close a menu in a reaction context.

AbstractPage #

Bases: ABC

Abstract representation of a paginated response.

ctx_to_kwargs abstractmethod #

ctx_to_kwargs(ctx)

Form create message **kwargs for this page based on a component or modal context.

Returns:

to_kwargs abstractmethod #

to_kwargs()

Form create message **kwargs for this page.

Returns:

LocalisedPage #

Bases: AbstractPage

Implementation of a paginated response which returns locale specific pages..

Page #

Bases: AbstractPage

Represents a pagianted response.

__init__ #

__init__(content=hikari.UNDEFINED, *, attachment=hikari.UNDEFINED, attachments=hikari.UNDEFINED, embed=hikari.UNDEFINED, embeds=hikari.UNDEFINED)

Initialise a response page.

Parameters:

Raises:

  • ValueError

    Raised for any of the following reasons:

    • When both attachment and attachments are provided.
    • When both embed and embeds are passed.

ctx_to_kwargs #

ctx_to_kwargs(_)

Form create message **kwargs for this page based on a component or modal context.

Returns:

from_entry classmethod #

from_entry(entry)

Create a Page from a EntryT.

Parameters:

Returns:

to_kwargs #

to_kwargs()

Form create message **kwargs for this page.

Returns:

Paginator #

Standard implementation of a stateful paginator.

To use this with components or reactions see the following classes:

has_finished_iterating property #

has_finished_iterating

Whether this has finished iterating over the original iterator.

__init__ #

__init__(iterator)

Initialise a paginator.

Parameters:

close #

close()

Close the paginator.

jump_to_first #

jump_to_first()

Jump to the first page.

Returns:

  • AbstractPage | None

    The first page in this paginator.

    This will be None if this is already on the first page or if the paginator hasn't been moved forward to the first entry yet.

jump_to_last async #

jump_to_last()

Jump to the last page.

Returns:

  • AbstractPage | None

    The last page in this paginator, or None if this is already on the last page.

step_back #

step_back()

Move back a page.

Returns:

  • AbstractPage | None

    The previous page in this paginator.

    This will be None if this is already on the first page or if the paginator hasn't been moved forward to the first entry yet.

step_forward async #

step_forward()

Move this forward a page.

Returns:

  • AbstractPage | None

    The next page in this paginator, or None if this is already on the last page.

ResponseKwargs #

Bases: TypedDict

Typed dict of a message response's basic kwargs.

This is returned by AbstractPage.to_kwargs and AbstractPage.ctx_to_kwargs.

attachments instance-attribute #

attachments

A sequence of attachments to send.

content instance-attribute #

content

String message content to send.

embeds instance-attribute #

embeds

A sequence of embeds to send.

aenumerate async #

aenumerate(iterable)

Async equivalent of enumerate.

Parameters:

  • iterable (AsyncIterable[_T]) –

    The async iterable to enumerate.

Returns:

  • AsyncIterator[tuple[int, _T]]

    The enumerated async iterator.

async_paginate_string async #

async_paginate_string(lines, /, *, char_limit=2000, line_limit=25, wrapper=None)

Lazily paginate an iterator of lines.

Parameters:

  • lines (AsyncIterable[str]) –

    The asynchronous iterator of lines to paginate.

  • char_limit (int, default: 2000 ) –

    The limit for how many characters should be included per yielded page.

  • line_limit (int, default: 25 ) –

    The limit for how many lines should be included per yielded page.

  • wrapper (Optional[str], default: None ) –

    A wrapper for each yielded page. This should leave "{}" in it to be replaced by the page's content.

Returns:

  • AsyncIterator[str]

    An async iterator of each page's content.

paginate_string #

paginate_string(lines, /, *, char_limit=2000, line_limit=25, wrapper=None)

Lazily paginate an iterator of lines.

Parameters:

  • lines (Iterator[str] | AsyncIterator[str]) –

    The iterator of lines to paginate. This iterator may be asynchronous or synchronous.

  • char_limit (int, default: 2000 ) –

    The limit for how many characters should be included per yielded page.

  • line_limit (int, default: 25 ) –

    The limit for how many lines should be included per yielded page.

  • wrapper (Optional[str], default: None ) –

    A wrapper for each yielded page. This should leave "{}" in it to be replaced by the page's content.

Returns:

  • AsyncIterator[str] | Iterator[str]

    An iterator of each page's content.

sync_paginate_string #

sync_paginate_string(lines, /, *, char_limit=2000, line_limit=25, wrapper=None)

Lazily paginate an iterator of lines.

Parameters:

  • lines (Iterable[str]) –

    The iterator of lines to paginate.

  • char_limit (int, default: 2000 ) –

    The limit for how many characters should be included per yielded page.

  • line_limit (int, default: 25 ) –

    The limit for how many lines should be included per yielded page.

  • wrapper (Optional[str], default: None ) –

    A wrapper for each yielded page. This should leave "{}" in it to be replaced by the page's content.

Returns:

  • Iterator[str]

    An iterator of each page's content.