Compare commits

..

No commits in common. "d29a81c786a777f791d2e67f17d326de45d8fb18" and "a213e727c1920d7c810abb225064c126a96b47fe" have entirely different histories.

5 changed files with 28 additions and 27 deletions

View file

@ -2,15 +2,14 @@ import { ButtonInteraction, CacheType } from "discord.js";
import { ButtonEvent } from "../type/buttonEvent";
import { CoreClient } from "../client/client";
import { PaginatedCommand } from "../type/paginatedCommand";
import EmbedPage from "../type/embedPage";
export default class Pagination<TPage extends EmbedPage> extends ButtonEvent {
export default class Pagination extends ButtonEvent {
public override async execute(interaction: ButtonInteraction<CacheType>) {
const embedId = interaction.customId.split(' ')[1];
const action = interaction.customId.split(' ')[2];
const commandItem = CoreClient.commandItems.find(x => x.Name == embedId);
const command = commandItem?.Command as PaginatedCommand<TPage>;
const command = commandItem?.Command as PaginatedCommand;
switch (action) {
case "next":

View file

@ -3,7 +3,9 @@ import PaginatedEmbed from "../../helpers/PaginatedEmbed";
import TestPage from "../../helpers/Pagination/TestPage";
import { PaginatedCommand } from "../../type/paginatedCommand";
export default class Paginationtest extends PaginatedCommand<TestPage> {
export default class Paginationtest extends PaginatedCommand {
public paginatedEmbed: PaginatedEmbed<TestPage>;
constructor() {
super();
@ -11,6 +13,8 @@ export default class Paginationtest extends PaginatedCommand<TestPage> {
.setName('paginationtest')
.setDescription('Test the pagination functionality');
this.paginatedEmbed = new PaginatedEmbed<TestPage>("paginationtest");
this.InitialisePages();
}
@ -20,6 +24,18 @@ export default class Paginationtest extends PaginatedCommand<TestPage> {
await page!.sendCommandEmbed(interaction);
}
public override async nextPage(interaction: ButtonInteraction<CacheType>) {
const page = this.paginatedEmbed.NextPage();
await page!.sendButtonEmbed(interaction);
}
public override async previousPage(interaction: ButtonInteraction<CacheType>) {
const page = this.paginatedEmbed.PreviousPage();
await page!.sendButtonEmbed(interaction);
}
private InitialisePages() {
const page0 = new TestPage("paginationtest", 0, 2);
const page1 = new TestPage("paginationtest", 1, 2);

View file

@ -5,6 +5,6 @@ export default class TestPage extends EmbedPage {
super(embedId, page, total);
this.setTitle("Test Embed");
this.setDescription(`You are viewing page ${page + 1}`);
this.setDescription(`You are viewing page ${page}`);
}
}

View file

@ -6,19 +6,19 @@ export default class EmbedPage extends EmbedBuilder {
constructor(embedId: string, page: number, total: number) {
super();
this.setFooter({ text: `Page ${page + 1} of ${total + 1}`});
this.setFooter({ text: `Page ${page} of ${total}`});
this.row = new ActionRowBuilder<ButtonBuilder>();
this.row.addComponents(
new ButtonBuilder()
.setCustomId(`pagination ${embedId} previous`)
.setLabel("◀️")
.setLabel("<")
.setStyle(ButtonStyle.Primary)
.setDisabled(page == 0),
new ButtonBuilder()
.setCustomId(`pagination ${embedId} next`)
.setLabel("▶️")
.setLabel(">")
.setStyle(ButtonStyle.Primary)
.setDisabled(page == total));
}
@ -31,10 +31,9 @@ export default class EmbedPage extends EmbedBuilder {
}
public async sendButtonEmbed(interaction: ButtonInteraction) {
await interaction.update({
await interaction.reply({
embeds: [ this ],
components: [ this.row ],
});
return;
}
}

View file

@ -1,27 +1,14 @@
import { ButtonInteraction, CacheType } from "discord.js";
import { ButtonInteraction, CommandInteraction } from "discord.js";
import { Command } from "./command";
import PaginatedEmbed from "../helpers/PaginatedEmbed";
import EmbedPage from "./embedPage";
export class PaginatedCommand<TPage extends EmbedPage> extends Command {
export class PaginatedCommand extends Command {
public CommandBuilder: any;
public paginatedEmbed: PaginatedEmbed<TPage>;
constructor() {
super();
public async nextPage(interaction: ButtonInteraction) {
this.paginatedEmbed = new PaginatedEmbed<TPage>("paginationtest");
}
public async nextPage(interaction: ButtonInteraction<CacheType>) {
const page = this.paginatedEmbed.NextPage();
public async previousPage(interaction: ButtonInteraction) {
await page!.sendButtonEmbed(interaction);
}
public async previousPage(interaction: ButtonInteraction<CacheType>) {
const page = this.paginatedEmbed.PreviousPage();
await page!.sendButtonEmbed(interaction);
}
}