korone.modules.utils package

Subpackages

Submodules

class korone.modules.utils.pagination.Pagination(objects, page_data, item_data, item_title)[source]

Bases: object

Generate a paginated inline keyboard.

This class provides a utility for paginating a list of objects and generating an inline keyboard with navigation buttons to allow the user to move between pages. The pagination can be customized with functions to generate the page data, item data, and item title.

Parameters:
  • objects (list[typing.Any]) – The list of objects to be paginated.

  • page_data (typing.Callable[[int], str]) – A function that takes a page number as input and returns a string representation of the page.

  • item_data (typing.Callable[[typing.Any, int], str]) – A function that takes an item and a page number as input and returns a string representation of the item.

  • item_title (typing.Callable[[typing.Any, int], str]) – A function that takes an item and a page number as input and returns a string representation of the item title.

objects
page_data
item_data
item_title
static chunk_list(lst, size)[source]

Split a list into smaller chunks.

This function splits a list into smaller chunks of a specified size. The function returns an iterator that yields the chunks of the original list.

Parameters:
  • lst (typing.Sequence[typing.Any]) – The list to be chunked.

  • size (int) – The size of each chunk.

Yields:

typing.Iterator[typing.Sequence[typing.Any]] – An iterator that yields chunks of the original list.

Examples

>>> lst = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>> for chunk in chunk_list(lst, 3):
...     print(chunk)
[1, 2, 3]
[4, 5, 6]
[7, 8, 9]
[10]
create(page, lines=5, columns=1)[source]

Create a paginated inline keyboard.

This method creates a pagination with the specified parameters, including the current page number, the number of lines per page, and the number of columns per page. The pagination will include navigation buttons to allow the user to move between pages.

Parameters:
  • page (int) – The current page number.

  • lines (int, optional) – The number of lines per page. Defaults to 5.

  • columns (int, optional) – The number of columns per page. Defaults to 1.

Returns:

hairydogm.keyboard.InlineKeyboardBuilder – The created pagination.