Code-Society-Lab / Code-Society-Lab/matrixpy
Paginator
- Dominant language
- Python
- Stars
- 14
- Forks
- 7
- Avg merge
- 8d 19h
- Merged PRs (30d)
- 5
Description
A `Paginator` class already exists in `matrix/help/pagination.py` and is used internally by the help command. It is not exported from the public API and provides no way to send pages to a room with reaction-based navigation, it only slices lists into `Page` objects.
The idea is to make `Paginator` a first-class public utility and extend it with a `send` method that posts the first page and handles ⬅️ / ➡️ reactions to let users navigate, making it straightforward to paginate any long output from a command.
**Proposed API**
```python
from matrix import Paginator
@bot.command()
async def members(ctx):
all_members = await ctx.room.get_members()
pages = Paginator(all_members, per_page=10, formatter=lambda m: f"- {m}")
await pages.send(ctx)
```
The existing `Paginator` and `Page` classes handle slicing correctly already; the work is adding the interactive layer. `send` would post the first page, add navigation reactions, then use `wait_for` (see related issue) to listen for reactions from the original sender and update the message in place. Editing a Matrix message uses the `m.replace` relationship type. The main question is whether to edit in place or post new messages per page, editing is cleaner but requires the bot to have the original event ID; posting new messages is simpler but noisy. Also worth exporting `Paginator` and `Page` from `matrix/__init__.py`.
Contributor guide
Assessment
This issue has not been assessed yet.