aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar SebastiaanZ <[email protected]>2019-01-03 16:26:13 +0100
committerGravatar SebastiaanZ <[email protected]>2019-01-03 16:26:13 +0100
commit0aa4c1b2690096c1e491446e6a64bed434166abd (patch)
tree6d738740807a2173084c8ce50b56a3351f0a1dda
parentClarifying log.debug messages for empty embeds for both Paginators (diff)
Adding optional kwarg to raise Exception on empty paginator embed instead of sending empty embed
Diffstat (limited to '')
-rw-r--r--bot/pagination.py18
1 files changed, 16 insertions, 2 deletions
diff --git a/bot/pagination.py b/bot/pagination.py
index 97468857c..72cfd83ef 100644
--- a/bot/pagination.py
+++ b/bot/pagination.py
@@ -17,6 +17,10 @@ PAGINATION_EMOJI = [FIRST_EMOJI, LEFT_EMOJI, RIGHT_EMOJI, LAST_EMOJI, DELETE_EMO
log = logging.getLogger(__name__)
+class EmptyPaginatorEmbed(Exception):
+ pass
+
+
class LinePaginator(Paginator):
"""
A class that aids in paginating code blocks for Discord messages.
@@ -96,7 +100,8 @@ class LinePaginator(Paginator):
async def paginate(cls, lines: Iterable[str], ctx: Context, embed: Embed,
prefix: str = "", suffix: str = "", max_lines: Optional[int] = None, max_size: int = 500,
empty: bool = True, restrict_to_user: User = None, timeout: int = 300,
- footer_text: str = None):
+ footer_text: str = None,
+ exception_on_empty_embed: bool = False):
"""
Use a paginator and set of reactions to provide pagination over a set of lines. The reactions are used to
switch page, or to finish with pagination.
@@ -152,6 +157,10 @@ class LinePaginator(Paginator):
current_page = 0
if not lines:
+ if exception_on_empty_embed:
+ log.exception(f"Pagination asked for empty lines iterable")
+ raise EmptyPaginatorEmbed("No lines to paginate")
+
log.debug("No lines to add to paginator, adding '(nothing to display)' message")
lines.append("(nothing to display)")
@@ -319,7 +328,8 @@ class ImagePaginator(Paginator):
@classmethod
async def paginate(cls, pages: List[Tuple[str, str]], ctx: Context, embed: Embed,
- prefix: str = "", suffix: str = "", timeout: int = 300):
+ prefix: str = "", suffix: str = "", timeout: int = 300,
+ exception_on_empty_embed: bool = False):
"""
Use a paginator and set of reactions to provide
pagination over a set of title/image pairs.The reactions are
@@ -366,6 +376,10 @@ class ImagePaginator(Paginator):
current_page = 0
if not pages:
+ if exception_on_empty_embed:
+ log.exception(f"Pagination asked for empty image list")
+ raise EmptyPaginatorEmbed("No images to paginate")
+
log.debug("No images to add to paginator, adding '(no images to display)' message")
pages.append(("(no images to display)", ""))