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.
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:
-
ResponseKwargs
–The create message kwargs for this page.
to_kwargs abstractmethod
#
to_kwargs()
Form create message **kwargs
for this page.
Returns:
-
ResponseKwargs
–The create message kwargs for this page.
LocalisedPage #
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:
-
content
(Union[str, Embed, Resourceish, UndefinedType]
, default:UNDEFINED
) –The message content to send.
If this is a hikari.Embed and no
embed
norembeds
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 noattachments
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
andattachments
are provided. - When both
embed
andembeds
are passed.
- When both
ctx_to_kwargs #
ctx_to_kwargs(_)
Form create message **kwargs
for this page based on a component or modal context.
Returns:
-
ResponseKwargs
–The create message kwargs for this page.
from_entry classmethod
#
from_entry(entry)
to_kwargs #
to_kwargs()
Form create message **kwargs
for this page.
Returns:
-
ResponseKwargs
–The create message kwargs for this page.
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:
-
iterator
(Iterator[EntryT] | AsyncIterator[EntryT]
) –The iterator to paginate.
This should be an iterator of AbstractPages.
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.
aenumerate async
#
aenumerate(iterable)
Async equivalent of enumerate.
Parameters:
-
iterable
(AsyncIterable[_T]
) –The async iterable to enumerate.
Returns:
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:
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.