Skip to content

Paginator #101

Description

@PenguinBoi12

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

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions