Coder Social home page Coder Social logo

eris-pagination's Introduction

Eris Pagination

Eris Pagination is a super simple to use Embed Paginator for the Node.js Discord library Eris.

The API is very straight forward but also offers a big amount of customizability as well!

Getting Started

Simply install Eris Pagination via NPM by typing npm install eris-pagination into your existing project and require the module wherever you need. That's it!

API

There's only a single asynchronous method needed for creating paginated Embeds with Eris:

EmbedPaginator.createPaginationEmbed(message, embeds, options);

Returns: Promise<Eris.Message> - The createPaginationEmbed method will return a Promise which resolves with an Eris.Message object of the paginated Embed. (E.g. to manually tinker with the paginator message).

Parameters:

  • Eris.Message message - An Eris message emitted from the messageCreate event.
  • Object[] embeds - An array containing all Embed objects you want to use with the paginator.
  • Object options - An object containing optional settings to overwrite the default behavior of Eris Paginator.
    • Boolean options.showPageNumbers - Whether to show "Page n of m" over the Embed.
      • Optional: Yes
      • Default: True
    • Boolean options.extendedButtons - Whether to show advanced pagination buttons (Jump to First & Last page)
      • Optional: Yes
      • Default: False
    • Boolean options.cycling - Cycle through all embeds jumping from the first page to the last page on going back and from the last page to the first page going forth.
      • Optional: Yes
      • Default: False
    • Number options.startPage - Which page (element) of the provided array to show first initially.
      • Optional: Yes
      • Default: 1
    • Number options.maxMatches - Maximum amount of reaction button clicks to listen for.
      • Optional: Yes
      • Default: 50
      • Maximum: 100
    • Number options.timeout - Duration for how long the pagination embed should work for.
      • Optional: Yes
      • Default: 300000 (5 minutes)
      • Maximum: 900000 (15 minutes)
    • String options.firstButton - Emoji used as the first page button. Must be Unicode!
      • Optional: Yes
      • Default: โฎ
    • String options.backButton - Emoji used as the back button. Must be Unicode!
      • Optional: Yes
      • Default: โฌ…
    • String options.forthButton - Emoji used as the forth button. Must be Unicode!
      • Optional: Yes
      • Default: โžก
    • String options.lastButton - Emoji used as the last page button. Must be Unicode!
      • Optional: Yes
      • Default: โญ
    • String options.deleteButton - Emoji used as the delete button. Must be Unicode!
      • Optional: Yes
      • Default: ๐Ÿ—‘

Notice: The Delete button does not delete the whole embed. It removes every reaction and resolves with an empty Promise!

Examples

Simple paginator without additional options:

const Eris = require('eris');
const EmbedPaginator = require('eris-pagination');
const bot = new Eris('BOT_TOKEN');

bot.on('ready', () => {
    console.log('Ready!');
});

bot.on('messageCreate', async (message) => {
    if (message.content === '!test') {
        const myEmbeds = [
            { title: 'Test Embed 1', color: 0x2ECC71 },
            { title: 'Test Embed 2', color: 0xE67E22 },
            { title: 'Test Embed 3', color: 0xE74C3C }
        ];

        const paginatedEmbed = await EmbedPaginator.createPaginationEmbed(message, myEmbeds);
        /* paginatedEmbed โ‡จ Eris.Message */
    }
});

bot.connect();


Advanced paginator with overwriting options:

const Eris = require('eris');
const EmbedPaginator = require('eris-pagination');
const bot = new Eris('BOT_TOKEN');

bot.on('ready', () => {
    console.log('Ready!');
});

bot.on('messageCreate', async (message) => {
    if (message.content === '!test') {
        const myEmbeds = [
            { title: 'Test Embed 1', color: 0x2ECC71 },
            { title: 'Test Embed 2', color: 0xE67E22 },
            { title: 'Test Embed 3', color: 0xE74C3C }
        ];

        const paginatedEmbed = await EmbedPaginator.createPaginationEmbed(
            message, 
            myEmbeds, 
            {
                showPageNumbers: false,
                extendedButtons: true,
                maxMatches: 10,
                timeout: 150000,
                backButton: 'โ—€',
                forthButton: 'โ–ถ',
                deleteButton: '๐Ÿ’ฉ',
                startPage: 2
            }
        );
        /* paginatedEmbed โ‡จ Eris.Message */
    }
});

bot.connect();

License

This repository makes use of the MIT License and all of its correlating traits.

While it isn't mandatory, a small credit if this repository was to be reused would be highly appreciated!

eris-pagination's People

Contributors

knht avatar bsian03 avatar nesmon avatar reboxer avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.