diff --git a/README.md b/README.md index d628f09..c3320ca 100644 --- a/README.md +++ b/README.md @@ -9,13 +9,13 @@ buttons) behind previous / jump / next navigation, with an optional cache button `requirements.txt`: ``` -dpy_paginator @ git+ssh://git@git.rethinkstudios.io/rethink-public/dpy_paginator.git@v0.1.0 +dpy_paginator @ git+ssh://git@git.rethinkstudios.io/rethink-public/dpy_paginator.git@v0.1.1 ``` Direct: ```bash -pip install "dpy_paginator @ git+ssh://git@git.rethinkstudios.io/rethink-public/dpy_paginator.git@v0.1.0" +pip install "dpy_paginator @ git+ssh://git@git.rethinkstudios.io/rethink-public/dpy_paginator.git@v0.1.1" ``` Requires `discord.py` (pulled transitively). @@ -116,7 +116,8 @@ await ButtonPaginator(pages, cache=cache, cache_sleep=1.0).start(ctx) ``` Omit `cache` or pass `None`/`[]` and the button never appears. When set, `cache` -must have one entry per rendered page. +must have one entry per rendered page — a shorter `cache` raises `ValueError` at +construction rather than failing with an `IndexError` mid-navigation. ## Constructor options diff --git a/src/dpy_paginator/dpy_paginator.py b/src/dpy_paginator/dpy_paginator.py index 1335e88..2ce0599 100644 --- a/src/dpy_paginator/dpy_paginator.py +++ b/src/dpy_paginator/dpy_paginator.py @@ -176,6 +176,11 @@ class ButtonPaginator(Generic[PageT_co], discord.ui.View): total_pages, left_over = divmod(len(self.pages), self.per_page) self.max_pages: int = total_pages + (1 if left_over else 0) + if cache is not None and len(cache) < self.max_pages: + raise ValueError( + f"cache has {len(cache)} entries but there are {self.max_pages} pages; " + "cache needs one entry per page" + ) self._page_kwargs: Dict[str, Any] = self._fresh_kwargs() def _fresh_kwargs(self) -> Dict[str, Any]: @@ -204,7 +209,7 @@ class ButtonPaginator(Generic[PageT_co], discord.ui.View): """return the content for a page index, wrapping out-of-range to 0""" if page_number < 0 or page_number >= self.max_pages: self.current_page = 0 - return self.pages[self.current_page] + return self.get_page(0) if self.per_page == 1: return self.pages[page_number] base = page_number * self.per_page