Compare commits
No commits in common. "main" and "v0.1.3" have entirely different histories.
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,5 +1,5 @@
|
||||
# claude
|
||||
.claude/
|
||||
CLAUDE.md
|
||||
|
||||
# python
|
||||
__pycache__/
|
||||
|
||||
@ -9,18 +9,18 @@ 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.4
|
||||
dpy_paginator @ git+ssh://git@git.rethinkstudios.io/rethink-public/dpy_paginator.git@v0.1.3
|
||||
```
|
||||
|
||||
Direct:
|
||||
|
||||
```bash
|
||||
pip install "dpy_paginator @ git+ssh://git@git.rethinkstudios.io/rethink-public/dpy_paginator.git@v0.1.4"
|
||||
pip install "dpy_paginator @ git+ssh://git@git.rethinkstudios.io/rethink-public/dpy_paginator.git@v0.1.3"
|
||||
```
|
||||
|
||||
Requires `discord.py` (pulled transitively).
|
||||
|
||||
Drop the `@v0.1.4` suffix from the line above to install the latest unpinned.
|
||||
Drop the `@v0.1.3` suffix from the line above to install the latest unpinned.
|
||||
|
||||
## Basic usage
|
||||
|
||||
@ -99,8 +99,6 @@ echoes its `data`.
|
||||
## Cache button (mention priming)
|
||||
|
||||
Discord clients render `<@id>` as a raw id until the user object is cached locally.
|
||||
Omit `cache` (or pass `None` / `[]`) and the button never appears; a non-empty cache
|
||||
must have one entry per page or construction raises.
|
||||
The cache button fixes that: pass `cache=[...]` with one entry per page, where each
|
||||
entry is a string of the user mentions on that page (`"<@111> <@222> <@333>"`).
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
||||
|
||||
[project]
|
||||
name = "dpy_paginator"
|
||||
version = "0.1.4"
|
||||
version = "0.1.3"
|
||||
description = "Button-navigated paginator for discord.py — config-free, injectable emojis, installable."
|
||||
requires-python = ">=3.10"
|
||||
dependencies = [
|
||||
|
||||
@ -29,7 +29,6 @@ config-free: no host config import; everything is passed at construction.
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
from typing import (
|
||||
Any,
|
||||
Dict,
|
||||
@ -70,8 +69,6 @@ DEFAULT_EMOJIS = {
|
||||
"cache": "\U0001f5c2\ufe0f", # 🗂️
|
||||
}
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
PageT_co = TypeVar("PageT_co", bound=Page, covariant=True)
|
||||
|
||||
|
||||
@ -164,10 +161,6 @@ class ButtonPaginator(Generic[PageT_co], discord.ui.View):
|
||||
super().__init__(timeout=timeout)
|
||||
if not pages:
|
||||
raise ValueError("ButtonPaginator requires at least one page")
|
||||
if per_page < 1:
|
||||
# per_page <= 0 would ZeroDivisionError (==0) or yield a negative max_pages
|
||||
# (<0) at the divmod below; fail loud like the other construction guards
|
||||
raise ValueError("per_page must be >= 1")
|
||||
self.author_id: Optional[int] = author_id
|
||||
self.delete_message_after: bool = delete_message_after
|
||||
self.mentions_allowed = mentions_allowed or discord.AllowedMentions.all()
|
||||
@ -183,9 +176,7 @@ 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)
|
||||
# a falsy cache (None or []) disables the cache button (see the render path's
|
||||
# `if self.cache:`); only a non-empty cache must have one entry per page
|
||||
if cache and len(cache) < self.max_pages:
|
||||
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"
|
||||
@ -303,13 +294,9 @@ class ButtonPaginator(Generic[PageT_co], discord.ui.View):
|
||||
nav=False rebuilds with only the page's custom buttons and no navigation
|
||||
items (prev/jump/cache/next) — a single-page result that still carries
|
||||
custom buttons keeps them (and their live callbacks) without a nav row.
|
||||
the nav row is also suppressed for a single page (max_pages < 2) even when
|
||||
nav is left at its default, so a re-render (update_page) never resurrects it.
|
||||
"""
|
||||
self.clear_items()
|
||||
|
||||
nav = nav and self.max_pages >= 2
|
||||
|
||||
if nav:
|
||||
self.previous_page.emoji = self.emojis["previous"]
|
||||
self.previous_page.disabled = self.current_page <= 0
|
||||
@ -395,13 +382,15 @@ class ButtonPaginator(Generic[PageT_co], discord.ui.View):
|
||||
) -> Optional[Union[discord.Message, discord.WebhookMessage]]:
|
||||
"""send the first page; obj is an Interaction or a Messageable"""
|
||||
kwargs = await self.get_page_kwargs(self.get_page(self.current_page))
|
||||
# update_buttons already suppresses the nav row for a single page (max_pages < 2),
|
||||
# keeping only the page's custom buttons — so a single page with custom buttons
|
||||
# renders them (live callbacks) with no nav row
|
||||
self.update_buttons()
|
||||
|
||||
if self.max_pages < 2 and not self.current_page_buttons:
|
||||
# single page, no custom buttons: no interactive row at all, drop the view
|
||||
if self.max_pages < 2:
|
||||
if self.current_page_buttons:
|
||||
# single page WITH custom buttons: keep the view live so the
|
||||
# buttons' callbacks still fire; strip only the navigation row
|
||||
self.update_buttons(nav=False)
|
||||
else:
|
||||
# single page, no custom buttons: no interactive row at all
|
||||
self.stop()
|
||||
kwargs.pop("view", None)
|
||||
|
||||
@ -434,7 +423,3 @@ class ButtonPaginator(Generic[PageT_co], discord.ui.View):
|
||||
await self.message.delete()
|
||||
except (discord.NotFound, discord.Forbidden):
|
||||
pass
|
||||
except discord.HTTPException:
|
||||
# on_timeout runs as a fire-and-forget task; a transient delete failure must
|
||||
# not surface as an unretrieved-task traceback on a best-effort cleanup
|
||||
log.warning("paginator on_timeout: failed to delete message", exc_info=True)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user