diff --git a/.eslintrc.json b/.eslintrc.json index 1b2de78..d3bd6ea 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -27,6 +27,8 @@ "no-unused-vars": "off", "node/no-missing-require": "off", "no-console": "warn", - "@typescript-eslint/explicit-member-accessibility": ["error"] + "@typescript-eslint/explicit-member-accessibility": ["error"], + "@typescript-eslint/consistent-type-imports": "error", + "@typescript-eslint/no-shadow": "warn" } } diff --git a/src/Pagination.ts b/src/Pagination.ts index 0dc43df..b6a2ca1 100644 --- a/src/Pagination.ts +++ b/src/Pagination.ts @@ -1,12 +1,12 @@ -import { +import { Interaction, Message, MessageComponentInteraction } from 'discord.js'; +import type { CommandInteraction, - ContextMenuInteraction, - Interaction, - Message, - MessageComponentInteraction, Snowflake, + InteractionCollector, + ButtonInteraction, + ContextMenuInteraction, } from 'discord.js'; -import { Options } from './types'; +import type { Options } from './types'; import { PaginationEmbed } from './PaginationEmbed'; /** @@ -30,6 +30,11 @@ export class Pagination extends PaginationEmbed { */ public authorizedUsers: Snowflake[]; + /** + * The collector of the pagination. + */ + public collector?: InteractionCollector; + //#end region /** @@ -146,18 +151,17 @@ export class Pagination extends PaginationEmbed { * */ public paginate(message: Message): this { - const collector = message.createMessageComponentCollector({ + this.collector = message.createMessageComponentCollector({ filter: ({ customId, user }) => Object.values(this.buttons).some((b) => b.customId === customId) && (this.authorizedUsers.length ? this.authorizedUsers.includes(user.id) : true), idle: this.idle, + componentType: 'BUTTON', }); - collector.on('collect', async (i) => { - if (!i.isButton()) return; - + this.collector.on('collect', async (i) => { if (i.customId === this.buttons.first?.customId) { this.goFirst(i); return; diff --git a/src/PaginationEmbed.ts b/src/PaginationEmbed.ts index c7f9e7a..218ebf6 100644 --- a/src/PaginationEmbed.ts +++ b/src/PaginationEmbed.ts @@ -1,14 +1,12 @@ -import { +import type { ButtonInteraction, EmbedField, InteractionReplyOptions, - MessageActionRow, MessageAttachment, - MessageButton, - MessageEmbed, MessageEmbedOptions, } from 'discord.js'; -import { +import { MessageActionRow, MessageButton, MessageEmbed } from 'discord.js'; +import type { ButtonsOptions, ButtonStyle, EmojiOptions, diff --git a/src/defaultOptions.ts b/src/defaultOptions.ts index c976cdd..9fcd7c4 100644 --- a/src/defaultOptions.ts +++ b/src/defaultOptions.ts @@ -1,4 +1,4 @@ -import { Options } from './types'; +import type { Options } from './types'; /** * The default options for the paginator. diff --git a/src/types/ButtonOptions.ts b/src/types/ButtonOptions.ts deleted file mode 100644 index b1d4916..0000000 --- a/src/types/ButtonOptions.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { EmojiIdentifierResolvable } from 'discord.js'; -import { ButtonStyle } from './ButtonStyle'; - -/** - * Pagination Button Options - */ -export interface ButtonOptions { - /** - * The emoji to use for the button. - */ - emoji: EmojiIdentifierResolvable; - /** - * The text to show on the button. - * @default "" - */ - label: string; - /** - * The style of the button. - * @default "SECONDARY" - */ - style: ButtonStyle; -} diff --git a/src/types/ButtonStyle.ts b/src/types/ButtonStyle.ts deleted file mode 100644 index 984d866..0000000 --- a/src/types/ButtonStyle.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * The style of the paginator buttons. - */ -export type ButtonStyle = 'PRIMARY' | 'SECONDARY' | 'DANGER' | 'SUCCESS'; diff --git a/src/types/ButtonsOptions.ts b/src/types/ButtonsOptions.ts index 5eb8c10..2f05b64 100644 --- a/src/types/ButtonsOptions.ts +++ b/src/types/ButtonsOptions.ts @@ -1,4 +1,29 @@ -import { ButtonOptions } from './ButtonOptions'; +import type { EmojiIdentifierResolvable } from 'discord.js'; + +/** + * The style of the paginator buttons. + */ +export type ButtonStyle = 'PRIMARY' | 'SECONDARY' | 'DANGER' | 'SUCCESS'; + +/** + * Pagination Button Options + */ +export interface ButtonOptions { + /** + * The emoji to use for the button. + */ + emoji: EmojiIdentifierResolvable; + /** + * The text to show on the button. + * @default "" + */ + label: string; + /** + * The style of the button. + * @default "SECONDARY" + */ + style: ButtonStyle; +} /** * Pagination Buttons Options diff --git a/src/types/EmojiOptions.ts b/src/types/EmojiOptions.ts index 92330a0..0959852 100644 --- a/src/types/EmojiOptions.ts +++ b/src/types/EmojiOptions.ts @@ -1,4 +1,4 @@ -import { EmojiIdentifierResolvable } from 'discord.js'; +import type { EmojiIdentifierResolvable } from 'discord.js'; /** * Emojis of the pagination buttons diff --git a/src/types/Options.ts b/src/types/Options.ts index ed4736f..3f38413 100644 --- a/src/types/Options.ts +++ b/src/types/Options.ts @@ -1,6 +1,6 @@ -import { MessageAttachment } from 'discord.js'; -import { ButtonStyle } from './ButtonStyle'; -import { EmojiOptions } from './EmojiOptions'; +import type { MessageAttachment } from 'discord.js'; +import type { ButtonStyle } from './ButtonsOptions'; +import type { EmojiOptions } from './EmojiOptions'; /** * The options to customize the pagination. diff --git a/src/types/index.ts b/src/types/index.ts index 7965886..4a8d19c 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -1,6 +1,4 @@ -export * from './ButtonOptions'; export * from './ButtonsOptions'; -export * from './ButtonStyle'; export * from './EmojiOptions'; export * from './LabelOptions'; export * from './Options';