account for possibility of no desc in pagination

master
Kit Kasune 3 years ago
parent 60bf68464f
commit 4e35a7fdb6
  1. 18
      util/livepagination.d.ts
  2. 47
      util/livepagination.js
  3. 2
      util/pagination.js
  4. 2
      util/ts/pagination.ts

@ -0,0 +1,18 @@
import { TextChannel, Message, MessageEmbed, Client } from 'discord.js';
import { Pagination } from './pagination';
export declare class LivePagination extends Pagination {
knownMax: number;
private _onScrollAttempt;
constructor(channel: TextChannel, pages: MessageEmbed[], originalMessage: Message, client: Client, loopPages?: boolean, message?: Message);
setOnScrollAttemptHandler(func: (pagination: LivePagination, pos: number, exists: boolean, inBounds: boolean) => void): this;
start(options?: {
endTime?: number;
time?: number;
startPage?: number;
user?: 'any' | string;
}): Promise<LivePagination>;
setControllers(endTime: number, user: 'any' | string): Promise<LivePagination>;
setPage(page: number): Promise<LivePagination>;
private static throwNoScrollAttempt;
set onScrollAttempt(func: (pagination: LivePagination, pos: number, exists: boolean, inBounds: boolean) => void);
}

@ -0,0 +1,47 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LivePagination = void 0;
const pagination_1 = require("./pagination");
class LivePagination extends pagination_1.Pagination {
constructor(channel, pages, originalMessage, client, loopPages, message) {
super(channel, pages, originalMessage, client, loopPages, message);
}
;
setOnScrollAttemptHandler(func) {
this._onScrollAttempt = func;
return this;
}
;
async start(options) {
if (!this._onScrollAttempt) {
LivePagination.throwNoScrollAttempt();
}
await super.start(options);
return this;
}
async setControllers(endTime, user) {
if (!this._onScrollAttempt) {
LivePagination.throwNoScrollAttempt();
}
await super.setControllers(endTime, user);
return this;
}
;
async setPage(page) {
if (!this._onScrollAttempt) {
LivePagination.throwNoScrollAttempt();
}
this._onScrollAttempt(this, page, typeof this.pages[page] !== 'undefined' && this.pages[page] !== null, typeof this.knownMax === 'number' ? page < this.knownMax : true);
await super.setPage(page);
return this;
}
;
static throwNoScrollAttempt() {
throw new Error("Fatal Pagination Error: You tried to start the LivePagination without setting a scrollAttemptEvent. This is necessary to allow the pagination to be built as the user scrolls. If you don't know what you're doing here, just make a Pagination instead.");
}
set onScrollAttempt(func) {
this._onScrollAttempt = func;
}
;
}
exports.LivePagination = LivePagination;

@ -117,7 +117,7 @@ class Pagination {
} }
this.controllers.collector.stop(); this.controllers.collector.stop();
let fe = this.getCurrentPage(); let fe = this.getCurrentPage();
fe.setDescription(`${fe.description}\n\n*This menu has ended, start a new one to interact with it!*`); fe.setDescription(`${fe.description && fe.description.length ? `${fe.description}\n\n` : ''}*This menu has ended, start a new one to interact with it!*`);
fe.setFooter({ text: `Menu Ended${fe.footer && fe.footer.text && fe.footer.text.length ? ` | ${fe.footer.text}` : ''}`, iconURL: this.client.user.displayAvatarURL() }); fe.setFooter({ text: `Menu Ended${fe.footer && fe.footer.text && fe.footer.text.length ? ` | ${fe.footer.text}` : ''}`, iconURL: this.client.user.displayAvatarURL() });
await this.message.edit({ embeds: [fe] }); await this.message.edit({ embeds: [fe] });
clearInterval(this.timeoutInterval); clearInterval(this.timeoutInterval);

@ -125,7 +125,7 @@ export class Pagination {
this.controllers.collector.stop(); this.controllers.collector.stop();
let fe = this.getCurrentPage(); let fe = this.getCurrentPage();
fe.setDescription(`${fe.description}\n\n*This menu has ended, start a new one to interact with it!*`); fe.setDescription(`${fe.description && fe.description.length ? `${fe.description}\n\n` : ''}*This menu has ended, start a new one to interact with it!*`);
fe.setFooter({text: `Menu Ended${fe.footer && fe.footer.text && fe.footer.text.length ? ` | ${fe.footer.text}` : ''}`, iconURL: this.client.user.displayAvatarURL()}); fe.setFooter({text: `Menu Ended${fe.footer && fe.footer.text && fe.footer.text.length ? ` | ${fe.footer.text}` : ''}`, iconURL: this.client.user.displayAvatarURL()});
await this.message.edit({embeds: [fe]}); await this.message.edit({embeds: [fe]});

Loading…
Cancel
Save