Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add boostrap_line_paginator_with_emojis util #262

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
Changelog
=========

- :release:`11.4.0 <28th July 2024>`
- :feature:`262` Add :obj:`pydis_core.utils.pagination.boostrap_line_paginator_with_emojis` to boostrap paginators with custom emojis and remove boilerplate code.

- :release:`11.3.1 <25th July 2024>`
- :bug:`-` Correct the docstring of :obj:`pydis_core.utils.interactions.ViewWithUserAndRoleCheck`.

Expand Down
47 changes: 47 additions & 0 deletions pydis_core/utils/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,3 +395,50 @@ async def paginate(
# Suppress if trying to act on an archived thread.
if e.code != 50083:
raise


def boostrap_line_paginator_with_emojis(pagination_emojis: PaginationEmojis) -> type[LinePaginator]:
"""Bootsrap a LinePaginator class with custom emojis."""
class _LinePaginator(LinePaginator):
@classmethod
async def paginate(
cls,
lines: list[str],
ctx: Context | discord.Interaction,
embed: discord.Embed,
*,
prefix: str = "",
suffix: str = "",
max_lines: int | None = None,
max_size: int = 500,
scale_to_size: int = 4000,
empty: bool = True,
restrict_to_user: User | None = None,
timeout: int = 300, # noqa: ASYNC109
footer_text: str | None = None,
url: str | None = None,
exception_on_empty_embed: bool = False,
reply: bool = False,
allowed_roles: Sequence[int] | None = None,
) -> discord.Message | None:
return await super().paginate(
pagination_emojis=pagination_emojis,
lines=lines,
ctx=ctx,
embed=embed,
prefix=prefix,
suffix=suffix,
max_lines=max_lines,
max_size=max_size,
scale_to_size=scale_to_size,
empty=empty,
restrict_to_user=restrict_to_user,
timeout=timeout,
footer_text=footer_text,
url=url,
exception_on_empty_embed=exception_on_empty_embed,
reply=reply,
allowed_roles=allowed_roles
)

return _LinePaginator
Loading