Code-Society-Lab / Code-Society-Lab/matrixpy

Paginator

Open
#101 0 comments 0 reactions 0 assignees View on GitHub
blocked feature
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.