Skip to content
This repository has been archived by the owner on Mar 13, 2023. It is now read-only.

Commit

Permalink
feat: add paginator.create_from_list
Browse files Browse the repository at this point in the history
  • Loading branch information
LordOfPolls committed Apr 5, 2022
1 parent b6df102 commit af64022
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions dis_snek/ext/paginators.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,29 @@ def create_from_string(
pages = [Page(c, prefix=prefix, suffix=suffix) for c in content_pages]
return cls(client, pages=pages, timeout_interval=timeout)

@classmethod
def create_from_list(
cls,
client: "Snake",
content: list[str],
prefix: str = "",
suffix: str = "",
page_size: int = 4000,
timeout: int = 0,
) -> "Paginator":
"""Create a paginator from a list of strings. Useful to maintain formatting."""
pages = []
page = ""
for entry in content:
if len(page) + len(f"\n{entry}") <= page_size:
page += f"{entry}\n"
else:
pages.append(Page(page, prefix=prefix, suffix=suffix))
page = ""
if page != "":
pages.append(Page(page, prefix=prefix, suffix=suffix))
return cls(client, pages=pages, timeout_interval=timeout)

def create_components(self, disable: bool = False) -> List[ActionRow]:
"""
Create the components for the paginator message.
Expand Down

0 comments on commit af64022

Please sign in to comment.