Skip to content

yuyo.pagination#

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

BLACK_CROSS module-attribute #

BLACK_CROSS = hikari.UnicodeEmoji('✖️')

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

EntryT module-attribute #

EntryT = typing.Union[tuple[hikari.UndefinedOr[str], hikari.UndefinedOr[hikari.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 = hikari.UnicodeEmoji('⏮️')

The emoji used to go back to the first entry.

LEFT_TRIANGLE module-attribute #

LEFT_TRIANGLE = hikari.UnicodeEmoji('◀️')

The emoji used to go back an entry.

RIGHT_DOUBLE_TRIANGLE module-attribute #

RIGHT_DOUBLE_TRIANGLE = hikari.UnicodeEmoji('⏭️')

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

RIGHT_TRIANGLE module-attribute #

RIGHT_TRIANGLE = hikari.UnicodeEmoji('▶️')

The emoji used to continue to the next entry.

STOP_SQUARE module-attribute #

STOP_SQUARE = hikari.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:

  • content (Union[str, Embed, Resourceish, UndefinedType], default: UNDEFINED ) –

    The message content to send.

    If this is a hikari.Embed and no embed nor embeds kwarg is provided, then this will instead be treated as an embed. This allows for simpler syntax when sending an embed alone.

    Likewise, if this is a hikari.Resource, then the content is instead treated as an attachment if no attachment and no attachments kwargs are provided.

  • attachment (UndefinedOr[Resourceish], default: UNDEFINED ) –

    A singular attachment to send.

  • attachments (UndefinedOr[Sequence[Resourceish]], default: UNDEFINED ) –

    Up to 10 attachments to include in the response.

  • embed (UndefinedOr[Embed], default: UNDEFINED ) –

    A singular embed to send.

  • embeds (UndefinedOr[Sequence[Embed]], default: UNDEFINED ) –

    Up to 10 embeds to include in the response.

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.