UNPKG

@ayanaware/bentocord

Version:

Bentocord is a Bento plugin designed to rapidly build fully functional Discord Bots.

60 lines 2.58 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CodeblockPaginator = void 0; const LocalizedCodeblockBuilder_1 = require("../../builders/LocalizedCodeblockBuilder"); const Paginator_1 = require("./Paginator"); class CodeblockPaginator extends Paginator_1.Paginator { constructor(ctx, items, options = {}) { super(ctx, items, options); } async build() { const items = await this.getItems(); const cbb = new LocalizedCodeblockBuilder_1.LocalizedCodeblockBuilder(this.ctx, this.options.language); if (this.pageCount === 0) return cbb; // show page header if more then 1 page if (this.pageCount > 1) { await cbb.setTranslatedHeader('BENTOCORD_PAGINATION_PAGE', { page: this.page + 1, total: this.pageCount }, '[Page {page}/{total}]'); } for (const { item, index } of items) { const flare = this.options.flare ?? {}; const focused = index === this.options.focused; // handle above flare let above = flare.above; if (focused && above) { if (typeof above === 'object') above = await this.ctx.formatTranslation(above); if (flare.padStart > 0) above = above.padStart(flare.padStart); cbb.addLine(above); } // translate label if needed if (typeof item.label === 'object') item.label = await this.ctx.formatTranslation(item.label); // translate description if needed if (typeof item.description === 'object') item.description = await this.ctx.formatTranslation(item.description); // build display let display = item.label; if (item.description) display = `${display} - ${item.description}`; // add item cbb.addLine((index + 1).toString(), display); // handle below flare let below = flare.below; if (focused && below) { if (typeof below === 'object') below = await this.ctx.formatTranslation(below); if (flare.padStart > 0) below = below.padStart(flare.padStart); cbb.addLine(below); } } return cbb; } async render() { return { content: (await this.build()).render() }; } } exports.CodeblockPaginator = CodeblockPaginator; //# sourceMappingURL=CodeblockPaginator.js.map