@notoiro/djs-button-pages
Version:
A simple yet powerful module for implementing customizable embed pages with buttons in Discord chat. Works only with Discord.js.
116 lines (115 loc) • 3.97 kB
TypeScript
import { Message, RepliableInteraction } from "discord.js";
import PaginationData from "./PaginationData";
import ButtonWrapper from "./ButtonWrapper";
import StopAction from "../Types/StopAction";
import PaginationState from "../Enums/PaginationState";
/**
* Class that represents pagination that is already sent.
*/
export default class PaginationSent {
private readonly _data;
private readonly _message;
private _page;
private readonly _beforeStopAction;
private readonly _onStopAction;
private _state;
private _collector;
/**
* Class that represents pagination that is already sent.
* @param {PaginationData} _data Embeds, buttons and so on.
* @param {Message | RepliableInteraction} _message Message or interaction that pagination should be assigned to.
* @param {number} _page Page which pagination should start from.
* @param {StopAction | undefined} _beforeStopAction Action that is completed before the pagination is stopped.
* @param {StopAction | undefined} _onStopAction Action that is completed after the pagination is stopped.
*/
constructor(_data: PaginationData, _message: Message | RepliableInteraction, _page?: number, _beforeStopAction?: StopAction | undefined, _onStopAction?: StopAction | undefined);
/**
* @returns {number} Current page.
*/
get page(): number;
/**
* @returns {PaginationData} Embeds, buttons and so on.
*/
get data(): PaginationData;
/**
* @returns {boolean} Is pagination active or not.
*/
get isActive(): boolean;
/**
* @returns {PaginationState} Pagination's state.
*/
get state(): PaginationState;
/**
* @returns {Message | RepliableInteraction} Message or interaction that pagination should be assigned to.
*/
get attachedTo(): Message | RepliableInteraction;
/**
* Gets button wrapper by custom id.
* @param {string} custom_id Custom id.
* @returns {ButtonWrapper | undefined} Button wrapper.
*/
getButtonByCustomId(custom_id: string): ButtonWrapper | undefined;
/**
* Initializes pagination. Can be called only once.
* Default pagination wrapper calls it so you shouldn't.
* @returns {Promise<this>}
*/
init(): Promise<this>;
/**
* Deletes pagination and stops it.
* If pagination is an ephemeral interaction stops it instead.
* @returns {Promise<void>}
*/
delete(): Promise<void>;
/**
* Switches pagination to the next page.
* It does not update the pagination, so you should call {@link update} by yourself!
* @param {number} page Page number.
* @returns {this}
*/
setPage(page: number): this;
/**
* Updates pagination state.
* @returns {Promise<void>}
*/
update(): Promise<void>;
/**
* Stops pagination.
* @returns {void}
*/
stop(): void;
/**
* Called than the collector collects interaction.
* @param {ButtonInteraction} interaction Interaction that is fired.
* @returns {Promise<void>}
*/
private _collected;
/**
* Called than the pagination stopped.
* @param {string} reason Reason why the pagination is stopped.
* @returns {Promise<void>}
*/
private _stopped;
/**
* Builds action rows with enabled or disabled buttons.
* @param {boolean} disabled Should be buttons disabled or not.
* @returns {Array<ActionRowBuilder<ButtonBuilder>>}
*/
private _buildActionRows;
/**
* Builds action rows for specific page.
* @returns {Promise<Array<ActionRowBuilder<ButtonBuilder>>>}
*/
private _buildPagedActionRows;
/**
* Forms collector for pages.
* @returns {Promise<void>}
*/
private _formCollector;
/**
* Forms filtering function for collector.
* @param {string} messageId Reply id.
* @returns {Promise<boolean>}
*/
private _formFilter;
}