UNPKG

@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.

149 lines (148 loc) 5.69 kB
import { APIEmbed, InteractionReplyOptions, Embed, EmbedBuilder, Message, MessageCreateOptions, MessageReplyOptions, RepliableInteraction, Snowflake, TextBasedChannel } from "discord.js"; import FilterOptions from "./FilterOptions"; import PaginationData from "./PaginationData"; import ButtonWrapper from "./ButtonWrapper"; import AfterSendingAction from "../Types/AfterSendingAction"; import PaginationSent from "./PaginationSent"; import StopAction from "../Types/StopAction"; /** * Class that wraps pagination. */ export default class PaginationWrapper implements PaginationData { private _buttons; private _embeds; private _time; private _filterOptions; private _afterSendingAction; private _beforeStopAction; private _afterStopAction; /** * Class that wraps pagination. * @param {PaginationData} data Data from which to build pagination. */ constructor(data?: Partial<PaginationData>); /** * @returns {Array<ButtonWrapper>} Buttons for pagination. */ get buttons(): Array<ButtonWrapper>; /** * @returns {Array<APIEmbed>} Embeds for pagination. */ get embeds(): Array<APIEmbed>; /** * @returns {FilterOptions} Options for filtering out interactions. */ get filterOptions(): FilterOptions; /** * @returns {number} Time that the pagination will be alive for. */ get time(): number; /** * @returns {AfterSendingAction} Action that is called after sending. */ get afterSendingAction(): AfterSendingAction; /** * @returns {StopAction} Action that is called before the pagination will be stopped. */ get beforeStopAction(): StopAction; /** * @returns {StopAction} Action that is called after the pagination is stopped. */ get afterStopAction(): StopAction; /** * Gets button by it's customId. * @param {string} custom_id Custom id. * @returns {ButtonWrapper | undefined} Button. */ getButtonByCustomId(custom_id: string): ButtonWrapper | undefined; /** * Sets action that will be called after sending. * @param {AfterSendingAction} action Action. * @returns {this} */ setAfterSendingAction(action: AfterSendingAction): this; /** * Sets action that will be called before the pagination is stopped. * @param {StopAction} action Action. * @returns {this} */ setBeforeStopAction(action: StopAction): this; /** * Sets action that will be called after the pagination is stopped. * @param {StopAction} action Action. * @returns {this} */ setAfterStopAction(action: StopAction): this; /** * Sets time that the pagination will be alive for. * @param {number} time Time. * @param {boolean} bypassLimits Should the time bypass limits or not. * @returns {this} */ setTime(time: number, bypassLimits?: boolean): this; /** * Sets embeds for the pagination. * @param {Array<Embed | EmbedBuilder | APIEmbed>} embeds Embeds. * @returns {this} */ setEmbeds(embeds: Array<Embed | EmbedBuilder | APIEmbed>): this; /** * Sets buttons for the pagination. * @param {ButtonWrapper | Array<ButtonWrapper>} buttons Buttons. * @returns {this} */ setButtons(buttons: ButtonWrapper | Array<ButtonWrapper>): this; /** * Sets options for filtering out interactions. * @param {FilterOptions} options Options for filtering out interactions. * @returns {this} */ setFilterOptions(options: FilterOptions): this; /** * Sets allowed users for pagination. * @param {Array<Snowflake>} users User's snowflake. * @returns {this} */ setAllowedUsers(users: Array<Snowflake>): this; /** * Adds user(-s) to allowed list. * @param {Snowflake | Array<Snowflake>} users User(-s). * @returns {this} */ addAllowedUsers(users: Snowflake | Array<Snowflake>): this; /** * Sends pagination to the channel. * @param {TextBasedChannel} channel Channel. * @param {MessageCreateOptions} options Message options. * @param {number} page Page number which will be the starting point. * @returns {Promise<PaginationSent>} Class that represents pagination that is already sent. */ send(channel: TextBasedChannel, options?: MessageCreateOptions, page?: number): Promise<PaginationSent>; /** * Sends pagination as a reply to message. * @param {Message} replyTo Message. * @param {MessageReplyOptions} options Message options. * @param {number} page Page number which will be the starting point. * @returns {Promise<PaginationSent>} Class that represents pagination that is already sent. */ reply(replyTo: Message, options?: MessageReplyOptions, page?: number): Promise<PaginationSent>; /** * Sends pagination as a reply to interaction. * @param {RepliableInteraction} interaction Interaction. * @param {InteractionReplyOptions} options Reply options. * @param {number} page Page number which will be the starting point. * @returns {Promise<PaginationSent>} Class that represents pagination that is already sent. */ interactionReply(interaction: RepliableInteraction, options?: InteractionReplyOptions, page?: number): Promise<PaginationSent>; /** * Transforms class to JSON-like object. * @returns {PaginationData} JSON-like object. */ toJSON(): PaginationData; /** * Overrides pagination data. * @param {Partial<PaginationData>} data Pagination data. * @returns {void} */ overrideData(data: Partial<PaginationData>): void; }