diff options
-rw-r--r-- | docs/changelog.rst | 3 | ||||
-rw-r--r-- | pydis_core/utils/pagination.py | 47 |
2 files changed, 50 insertions, 0 deletions
diff --git a/docs/changelog.rst b/docs/changelog.rst index f2abd8f3..a63ba98d 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -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`. diff --git a/pydis_core/utils/pagination.py b/pydis_core/utils/pagination.py index b4c62408..59401cc0 100644 --- a/pydis_core/utils/pagination.py +++ b/pydis_core/utils/pagination.py @@ -395,3 +395,50 @@ class LinePaginator(Paginator): # 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 |