This commit is contained in:
parent
3fc8ea3e28
commit
d29a81c786
3 changed files with 21 additions and 23 deletions
|
@ -2,14 +2,15 @@ import { ButtonInteraction, CacheType } from "discord.js";
|
||||||
import { ButtonEvent } from "../type/buttonEvent";
|
import { ButtonEvent } from "../type/buttonEvent";
|
||||||
import { CoreClient } from "../client/client";
|
import { CoreClient } from "../client/client";
|
||||||
import { PaginatedCommand } from "../type/paginatedCommand";
|
import { PaginatedCommand } from "../type/paginatedCommand";
|
||||||
|
import EmbedPage from "../type/embedPage";
|
||||||
|
|
||||||
export default class Pagination extends ButtonEvent {
|
export default class Pagination<TPage extends EmbedPage> extends ButtonEvent {
|
||||||
public override async execute(interaction: ButtonInteraction<CacheType>) {
|
public override async execute(interaction: ButtonInteraction<CacheType>) {
|
||||||
const embedId = interaction.customId.split(' ')[1];
|
const embedId = interaction.customId.split(' ')[1];
|
||||||
const action = interaction.customId.split(' ')[2];
|
const action = interaction.customId.split(' ')[2];
|
||||||
|
|
||||||
const commandItem = CoreClient.commandItems.find(x => x.Name == embedId);
|
const commandItem = CoreClient.commandItems.find(x => x.Name == embedId);
|
||||||
const command = commandItem?.Command as PaginatedCommand;
|
const command = commandItem?.Command as PaginatedCommand<TPage>;
|
||||||
|
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case "next":
|
case "next":
|
||||||
|
|
|
@ -3,9 +3,7 @@ import PaginatedEmbed from "../../helpers/PaginatedEmbed";
|
||||||
import TestPage from "../../helpers/Pagination/TestPage";
|
import TestPage from "../../helpers/Pagination/TestPage";
|
||||||
import { PaginatedCommand } from "../../type/paginatedCommand";
|
import { PaginatedCommand } from "../../type/paginatedCommand";
|
||||||
|
|
||||||
export default class Paginationtest extends PaginatedCommand {
|
export default class Paginationtest extends PaginatedCommand<TestPage> {
|
||||||
public paginatedEmbed: PaginatedEmbed<TestPage>;
|
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
|
@ -13,8 +11,6 @@ export default class Paginationtest extends PaginatedCommand {
|
||||||
.setName('paginationtest')
|
.setName('paginationtest')
|
||||||
.setDescription('Test the pagination functionality');
|
.setDescription('Test the pagination functionality');
|
||||||
|
|
||||||
this.paginatedEmbed = new PaginatedEmbed<TestPage>("paginationtest");
|
|
||||||
|
|
||||||
this.InitialisePages();
|
this.InitialisePages();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,18 +20,6 @@ export default class Paginationtest extends PaginatedCommand {
|
||||||
await page!.sendCommandEmbed(interaction);
|
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() {
|
private InitialisePages() {
|
||||||
const page0 = new TestPage("paginationtest", 0, 2);
|
const page0 = new TestPage("paginationtest", 0, 2);
|
||||||
const page1 = new TestPage("paginationtest", 1, 2);
|
const page1 = new TestPage("paginationtest", 1, 2);
|
||||||
|
|
|
@ -1,14 +1,27 @@
|
||||||
import { ButtonInteraction, CommandInteraction } from "discord.js";
|
import { ButtonInteraction, CacheType } from "discord.js";
|
||||||
import { Command } from "./command";
|
import { Command } from "./command";
|
||||||
|
import PaginatedEmbed from "../helpers/PaginatedEmbed";
|
||||||
|
import EmbedPage from "./embedPage";
|
||||||
|
|
||||||
export class PaginatedCommand extends Command {
|
export class PaginatedCommand<TPage extends EmbedPage> extends Command {
|
||||||
public CommandBuilder: any;
|
public CommandBuilder: any;
|
||||||
|
public paginatedEmbed: PaginatedEmbed<TPage>;
|
||||||
|
|
||||||
public async nextPage(interaction: ButtonInteraction) {
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.paginatedEmbed = new PaginatedEmbed<TPage>("paginationtest");
|
||||||
}
|
}
|
||||||
|
|
||||||
public async previousPage(interaction: ButtonInteraction) {
|
public async nextPage(interaction: ButtonInteraction<CacheType>) {
|
||||||
|
const page = this.paginatedEmbed.NextPage();
|
||||||
|
|
||||||
|
await page!.sendButtonEmbed(interaction);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async previousPage(interaction: ButtonInteraction<CacheType>) {
|
||||||
|
const page = this.paginatedEmbed.PreviousPage();
|
||||||
|
|
||||||
|
await page!.sendButtonEmbed(interaction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue