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]], 'Page']

A type hint used to represent a paginator entry.

This may be either Page 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.

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.

STOP_SQUARE module-attribute #

STOP_SQUARE = UnicodeEmoji('⏹️')

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

Page #

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.

from_entry classmethod #

from_entry(entry)

Create a Page from a EntryT.

Parameters:

Returns:

  • Page

    The created page.

to_kwargs #

to_kwargs()

Form create message **kwargs for this page.

Returns:

  • dict[str, Any]

    The create message kwargs for this page.

Paginator #

Standard implementation of a 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:

  • Page | 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:

  • Page | 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:

  • Page | 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:

  • Page | None

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

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.