Skip to content

Commit

Permalink
fix: export collector
Browse files Browse the repository at this point in the history
  • Loading branch information
imranbarbhuiya committed Mar 17, 2022
1 parent 609710b commit e9758e2
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 50 deletions.
4 changes: 3 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
24 changes: 14 additions & 10 deletions src/Pagination.ts
Original file line number Diff line number Diff line change
@@ -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';

/**
Expand All @@ -30,6 +30,11 @@ export class Pagination extends PaginationEmbed {
*/
public authorizedUsers: Snowflake[];

/**
* The collector of the pagination.
*/
public collector?: InteractionCollector<ButtonInteraction>;

//#end region

/**
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 3 additions & 5 deletions src/PaginationEmbed.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/defaultOptions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Options } from './types';
import type { Options } from './types';

/**
* The default options for the paginator.
Expand Down
22 changes: 0 additions & 22 deletions src/types/ButtonOptions.ts

This file was deleted.

4 changes: 0 additions & 4 deletions src/types/ButtonStyle.ts

This file was deleted.

27 changes: 26 additions & 1 deletion src/types/ButtonsOptions.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/types/EmojiOptions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EmojiIdentifierResolvable } from 'discord.js';
import type { EmojiIdentifierResolvable } from 'discord.js';

/**
* Emojis of the pagination buttons
Expand Down
6 changes: 3 additions & 3 deletions src/types/Options.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 0 additions & 2 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
export * from './ButtonOptions';
export * from './ButtonsOptions';
export * from './ButtonStyle';
export * from './EmojiOptions';
export * from './LabelOptions';
export * from './Options';

0 comments on commit e9758e2

Please sign in to comment.