gralonium 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/README.md +62 -0
  2. package/lib/classes/Client.d.ts +44 -0
  3. package/lib/classes/Client.js +162 -0
  4. package/lib/classes/Context.d.ts +25 -0
  5. package/lib/classes/Context.js +139 -0
  6. package/lib/classes/Cooldowns.d.ts +25 -0
  7. package/lib/classes/Cooldowns.js +72 -0
  8. package/lib/classes/Errors.d.ts +135 -0
  9. package/lib/classes/Errors.js +1 -0
  10. package/lib/classes/HelpCommand.d.ts +15 -0
  11. package/lib/classes/HelpCommand.js +1 -0
  12. package/lib/classes/Loader.d.ts +85 -0
  13. package/lib/classes/Loader.js +359 -0
  14. package/lib/classes/Plugins.d.ts +52 -0
  15. package/lib/classes/Plugins.js +107 -0
  16. package/lib/classes/Utils.d.ts +25 -0
  17. package/lib/classes/Utils.js +705 -0
  18. package/lib/classes/builders/CommandBuilder.d.ts +50 -0
  19. package/lib/classes/builders/CommandBuilder.js +107 -0
  20. package/lib/classes/builders/ComponentsV2Builder.d.ts +125 -0
  21. package/lib/classes/builders/ComponentsV2Builder.js +287 -0
  22. package/lib/classes/builders/EventBuilder.d.ts +19 -0
  23. package/lib/classes/builders/EventBuilder.js +1 -0
  24. package/lib/classes/builders/GroupBuilder.d.ts +46 -0
  25. package/lib/classes/builders/GroupBuilder.js +90 -0
  26. package/lib/classes/builders/InteractionBuilder.d.ts +32 -0
  27. package/lib/classes/builders/InteractionBuilder.js +1 -0
  28. package/lib/classes/builders/ParamsBuilder.d.ts +87 -0
  29. package/lib/classes/builders/ParamsBuilder.js +1 -0
  30. package/lib/classes/builders/components/StyleMapper.d.ts +10 -0
  31. package/lib/classes/builders/components/StyleMapper.js +32 -0
  32. package/lib/classes/builders/components/helpers.d.ts +22 -0
  33. package/lib/classes/builders/components/helpers.js +51 -0
  34. package/lib/classes/builders/components/templates.d.ts +13 -0
  35. package/lib/classes/builders/components/templates.js +41 -0
  36. package/lib/classes/experiments/Confirmator.d.ts +58 -0
  37. package/lib/classes/experiments/Confirmator.js +114 -0
  38. package/lib/classes/experiments/Paginator.d.ts +65 -0
  39. package/lib/classes/experiments/Paginator.js +124 -0
  40. package/lib/events/interactionCreate.d.ts +4 -0
  41. package/lib/events/interactionCreate.js +17 -0
  42. package/lib/events/messageCreate.d.ts +4 -0
  43. package/lib/events/messageCreate.js +17 -0
  44. package/lib/events/messageUpdate.d.ts +4 -0
  45. package/lib/events/messageUpdate.js +17 -0
  46. package/lib/experiments.d.ts +2 -0
  47. package/lib/experiments.js +1 -0
  48. package/lib/main.d.ts +18 -0
  49. package/lib/main.js +25 -0
  50. package/package.json +69 -0
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GroupBuilder = void 0;
4
+
5
+ const CommandBuilder_js_1 = require("./CommandBuilder.js");
6
+ const shapeshift_1 = require("@sapphire/shapeshift");
7
+
8
+ const permissionStringPredicate = shapeshift_1.s.string.lengthGreaterThan(0);
9
+ const permissionArrayPredicate = shapeshift_1.s.array(permissionStringPredicate);
10
+
11
+ class GroupBuilder {
12
+ name;
13
+ aliases;
14
+ description;
15
+ commands;
16
+ as_slash;
17
+ as_prefix;
18
+ guildOnly;
19
+ defaultMemberPermissions;
20
+ userPermissions;
21
+ botPermissions;
22
+ guards;
23
+
24
+ constructor(options) {
25
+ this.commands = [];
26
+ this.name = options?.name ?? "";
27
+ this.aliases = options?.aliases ?? [];
28
+ this.description = options?.description ?? "...";
29
+ this.as_prefix = options?.as_prefix ?? true;
30
+ this.as_slash = options?.as_slash ?? true;
31
+ this.guildOnly = options?.guildOnly;
32
+ this.defaultMemberPermissions = options?.defaultMemberPermissions;
33
+ this.userPermissions = permissionArrayPredicate.parse(options?.userPermissions ?? []);
34
+ this.botPermissions = permissionArrayPredicate.parse(options?.botPermissions ?? []);
35
+ this.guards = options?.guards ?? [];
36
+ }
37
+
38
+ setName(name) {
39
+ this.name = name;
40
+ return this;
41
+ }
42
+
43
+ setDescription(description) {
44
+ this.description = description;
45
+ return this;
46
+ }
47
+
48
+ addCommand(command) {
49
+ this.commands.push(command);
50
+ return this;
51
+ }
52
+
53
+ setGuards(...guards) {
54
+ this.guards = guards;
55
+ return this;
56
+ }
57
+
58
+ setUserPermissions(...permissions) {
59
+ this.userPermissions = permissionArrayPredicate.parse(permissions);
60
+ return this;
61
+ }
62
+
63
+ setBotPermissions(...permissions) {
64
+ this.botPermissions = permissionArrayPredicate.parse(permissions);
65
+ return this;
66
+ }
67
+
68
+ allowPrefix(allow) {
69
+ this.as_prefix = allow;
70
+ return this;
71
+ }
72
+
73
+ allowSlash(allow) {
74
+ this.as_slash = allow;
75
+ return this;
76
+ }
77
+
78
+ toJSON() {
79
+ return {
80
+ name: this.name,
81
+ description: this.description,
82
+ options: [],
83
+ default_member_permissions: this.defaultMemberPermissions
84
+ ? (0, CommandBuilder_js_1.validateDefaultMemberPermissions)(this.defaultMemberPermissions)
85
+ : undefined,
86
+ dm_permission: typeof this.guildOnly === "boolean" ? !this.guildOnly : undefined,
87
+ };
88
+ }
89
+ }
90
+ exports.GroupBuilder = GroupBuilder;
@@ -0,0 +1,32 @@
1
+ export declare enum Interactions {
2
+ AnyInteraction = "anyInteraction",
3
+ Autocomplete = "autocomplete",
4
+ Button = "button",
5
+ ChatInput = "chatInput",
6
+ MessageContextMenu = "messageContextMenu",
7
+ Modal = "modalSubmit",
8
+ UserContextMenu = "userContextMenu",
9
+ ChannelSelectMenu = "channelSelectMenu",
10
+ RoleSelectMenu = "roleSelectMenu",
11
+ StringSelectMenu = "stringSelectMenu",
12
+ UserSelectMenu = "userSelectMenu",
13
+ MentionableSelectMenu = "mentionableSelectMenu"
14
+ }
15
+ export interface InteractionDataBuilder {
16
+ name?: string;
17
+ type: Interactions;
18
+ description?: string;
19
+ }
20
+ export declare class InteractionBuilder {
21
+ name?: string;
22
+ type: Interactions;
23
+ description: string;
24
+ constructor(options?: InteractionDataBuilder);
25
+ /**
26
+ * Returns the command data parsed as JSON.
27
+ */
28
+ toJSON(): {
29
+ name: string | undefined;
30
+ description: string;
31
+ };
32
+ }
@@ -0,0 +1 @@
1
+ "use strict";var Interactions;Object.defineProperty(exports,"__esModule",{value:!0}),exports.InteractionBuilder=exports.Interactions=void 0,function(e){e.AnyInteraction="anyInteraction",e.Autocomplete="autocomplete",e.Button="button",e.ChatInput="chatInput",e.MessageContextMenu="messageContextMenu",e.Modal="modalSubmit",e.UserContextMenu="userContextMenu",e.ChannelSelectMenu="channelSelectMenu",e.RoleSelectMenu="roleSelectMenu",e.StringSelectMenu="stringSelectMenu",e.UserSelectMenu="userSelectMenu",e.MentionableSelectMenu="mentionableSelectMenu"}(Interactions||(exports.Interactions=Interactions={}));class InteractionBuilder{name;type;description;constructor(e){this.name=e?.name,this.type=e?.type||Interactions.ChatInput,this.description=e?.description||"..."}toJSON(){return{name:this.name,description:this.description}}}exports.InteractionBuilder=InteractionBuilder;
@@ -0,0 +1,87 @@
1
+ import { ApplicationCommandOptionType, ChannelType } from "discord.js";
2
+ export interface BaseParam {
3
+ /** The name for this parameter. */
4
+ name: string;
5
+ /** The description for this parameter. */
6
+ description: string;
7
+ /** Mark this param as required or not. */
8
+ required: boolean;
9
+ /** Parameter type. (if needed) */
10
+ type?: ApplicationCommandOptionType;
11
+ /** Parameter default value. */
12
+ value?: any;
13
+ /** Mostly to be used for string. Return all arguments after this parameter (including this one) */
14
+ ellipsis?: boolean;
15
+ }
16
+ export interface StringParam extends BaseParam {
17
+ /** String choices. */
18
+ choices?: {
19
+ name: string;
20
+ value: string;
21
+ }[];
22
+ /** Maximum string length. */
23
+ max_length?: number;
24
+ /** Minimum string length. */
25
+ min_length?: number;
26
+ /** Mark this command as automplete */
27
+ autocomplete?: boolean;
28
+ }
29
+ export interface NumberParam extends BaseParam {
30
+ /** Maximum number length. */
31
+ max_value?: number;
32
+ /** Minimum string length. */
33
+ min_value?: number;
34
+ /** Number choices. */
35
+ choices?: {
36
+ name: string;
37
+ value: string;
38
+ }[];
39
+ }
40
+ export interface ChannelParam extends BaseParam {
41
+ /** An array of allowed channel types. */
42
+ channel_types?: ChannelType[];
43
+ }
44
+ export declare class ParamsBuilder {
45
+ params: BaseParam[];
46
+ quoted: boolean;
47
+ /**
48
+ * Enable or disable quoted arguments.
49
+ * @param value Boolean value.
50
+ */
51
+ setQuoted(value: boolean): ParamsBuilder;
52
+ /**
53
+ * Adds a string option.
54
+ * @param param Parameter data.
55
+ */
56
+ addString(param: StringParam): ParamsBuilder;
57
+ /**
58
+ * Adds a number option.
59
+ * @param param Parameter data.
60
+ */
61
+ addNumber(param: NumberParam): ParamsBuilder;
62
+ /**
63
+ * Adds a boolean option.
64
+ * @param param Parameter data.
65
+ */
66
+ addBoolean(param: BaseParam): ParamsBuilder;
67
+ /**
68
+ * Adds a guild member option.
69
+ * @param param Parameter data.
70
+ */
71
+ addMember(param: BaseParam): ParamsBuilder;
72
+ /**
73
+ * Adds a guild channel option.
74
+ * @param param Parameter data.
75
+ */
76
+ addChannel(param: ChannelParam): ParamsBuilder;
77
+ /**
78
+ * Adds a role option.
79
+ * @param param Parameter data.
80
+ */
81
+ addRole(param: BaseParam): ParamsBuilder;
82
+ /**
83
+ * Adds an attachment option.
84
+ * @param param Parameter data.
85
+ */
86
+ addAttachment(param: BaseParam): ParamsBuilder;
87
+ }
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ParamsBuilder=void 0;const discord_js_1=require("discord.js");class ParamsBuilder{params=[];quoted=!0;setQuoted(t){return this.quoted=t,this}addString(t){return t.type=discord_js_1.ApplicationCommandOptionType.String,this.params.push(t),this}addNumber(t){return t.type=discord_js_1.ApplicationCommandOptionType.Number,this.params.push(t),this}addBoolean(t){return t.type=discord_js_1.ApplicationCommandOptionType.Boolean,this.params.push(t),this}addMember(t){return t.type=discord_js_1.ApplicationCommandOptionType.User,this.params.push(t),this}addChannel(t){return t.type=discord_js_1.ApplicationCommandOptionType.Channel,this.params.push(t),this}addRole(t){return t.type=discord_js_1.ApplicationCommandOptionType.Role,this.params.push(t),this}addAttachment(t){return t.type=discord_js_1.ApplicationCommandOptionType.Attachment,this.params.push(t),this}}exports.ParamsBuilder=ParamsBuilder;
@@ -0,0 +1,10 @@
1
+ import { ButtonStyle } from "discord.js";
2
+
3
+ export type ButtonStyleName = "primary" | "secondary" | "success" | "danger" | "link";
4
+ export type ButtonStyleInput = ButtonStyleName | ButtonStyle;
5
+
6
+ /**
7
+ * Maps a button style name (string) or ButtonStyle enum value to a ButtonStyle.
8
+ * Defaults to Primary if the provided value is not recognized.
9
+ */
10
+ export declare function mapButtonStyle(style?: ButtonStyleInput | null): ButtonStyle;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mapButtonStyle = void 0;
4
+
5
+ const discord_js_1 = require("discord.js");
6
+
7
+ const STYLE_MAP = {
8
+ primary: discord_js_1.ButtonStyle.Primary,
9
+ secondary: discord_js_1.ButtonStyle.Secondary,
10
+ success: discord_js_1.ButtonStyle.Success,
11
+ danger: discord_js_1.ButtonStyle.Danger,
12
+ link: discord_js_1.ButtonStyle.Link,
13
+ };
14
+
15
+ /**
16
+ * Maps a button style name (string) or ButtonStyle enum value to a ButtonStyle.
17
+ * Defaults to Primary if the provided value is not recognized.
18
+ */
19
+ function mapButtonStyle(style) {
20
+ if (style === undefined || style === null) {
21
+ return discord_js_1.ButtonStyle.Primary;
22
+ }
23
+ if (typeof style === "number") {
24
+ return style;
25
+ }
26
+ const mapped = STYLE_MAP[style.toLowerCase()];
27
+ if (mapped === undefined) {
28
+ return discord_js_1.ButtonStyle.Primary;
29
+ }
30
+ return mapped;
31
+ }
32
+ exports.mapButtonStyle = mapButtonStyle;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Validates that text content is non-empty.
3
+ * Throws a descriptive error if validation fails.
4
+ */
5
+ export declare function validateTextContent(content: unknown): void;
6
+
7
+ /**
8
+ * Validates that a button row does not exceed 5 buttons.
9
+ * Throws a descriptive error if validation fails.
10
+ */
11
+ export declare function validateButtonCount(count: number): void;
12
+
13
+ /**
14
+ * Validates that a select menu does not exceed 25 options.
15
+ * Throws a descriptive error if validation fails.
16
+ */
17
+ export declare function validateSelectMenuOptions(count: number): void;
18
+
19
+ /**
20
+ * Generates a unique custom ID with an optional prefix.
21
+ */
22
+ export declare function generateCustomId(prefix?: string): string;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateCustomId = exports.validateSelectMenuOptions = exports.validateButtonCount = exports.validateTextContent = void 0;
4
+
5
+ /**
6
+ * Validates that text content is non-empty.
7
+ * Throws a descriptive error if validation fails.
8
+ */
9
+ function validateTextContent(content) {
10
+ if (typeof content !== "string" || content.trim().length === 0) {
11
+ throw new Error("[ComponentsV2Builder] Text content must be a non-empty string.");
12
+ }
13
+ }
14
+ exports.validateTextContent = validateTextContent;
15
+
16
+ /**
17
+ * Validates that a button row does not exceed 5 buttons.
18
+ * Throws a descriptive error if validation fails.
19
+ */
20
+ function validateButtonCount(count) {
21
+ if (count > 5) {
22
+ throw new Error("[ComponentsV2Builder] An ActionRow cannot contain more than 5 buttons.");
23
+ }
24
+ }
25
+ exports.validateButtonCount = validateButtonCount;
26
+
27
+ /**
28
+ * Validates that a select menu does not exceed 25 options.
29
+ * Throws a descriptive error if validation fails.
30
+ */
31
+ function validateSelectMenuOptions(count) {
32
+ if (count > 25) {
33
+ throw new Error("[ComponentsV2Builder] A StringSelectMenu cannot have more than 25 options.");
34
+ }
35
+ }
36
+ exports.validateSelectMenuOptions = validateSelectMenuOptions;
37
+
38
+ /**
39
+ * Generates a unique custom ID with an optional prefix.
40
+ * Uses crypto.randomUUID when available, otherwise falls back to a
41
+ * timestamp + random number combination to avoid collisions in clustered
42
+ * or multi-process environments.
43
+ */
44
+ function generateCustomId(prefix) {
45
+ const base = prefix ? `${prefix}_` : "cv2_";
46
+ if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
47
+ return `${base}${crypto.randomUUID()}`;
48
+ }
49
+ return `${base}${Date.now()}_${Math.random().toString(36).slice(2)}`;
50
+ }
51
+ exports.generateCustomId = generateCustomId;
@@ -0,0 +1,13 @@
1
+ import { ComponentsV2Builder } from "../ComponentsV2Builder.js";
2
+
3
+ /** Create a Confirm / Cancel button container. */
4
+ export declare function createConfirm(confirmId?: string, cancelId?: string): ComponentsV2Builder;
5
+
6
+ /** Create a ticket category select menu container. */
7
+ export declare function createTicketMenu(customId?: string): ComponentsV2Builder;
8
+
9
+ /** Create a plan selector container. */
10
+ export declare function createPlanSelector(customId?: string): ComponentsV2Builder;
11
+
12
+ /** Create a role selector menu container. */
13
+ export declare function createRoleMenu(customId?: string): ComponentsV2Builder;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ /**
3
+ * templates.js — re-exports the static template factories from ComponentsV2Builder
4
+ * as standalone named functions for convenient direct imports.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.createRoleMenu = exports.createPlanSelector = exports.createTicketMenu = exports.createConfirm = void 0;
8
+
9
+ const ComponentsV2Builder_js_1 = require("../ComponentsV2Builder.js");
10
+
11
+ /**
12
+ * Create a Confirm / Cancel button container.
13
+ */
14
+ function createConfirm(confirmId, cancelId) {
15
+ return ComponentsV2Builder_js_1.ComponentsV2Builder.createConfirm(confirmId, cancelId);
16
+ }
17
+ exports.createConfirm = createConfirm;
18
+
19
+ /**
20
+ * Create a ticket category select menu container.
21
+ */
22
+ function createTicketMenu(customId) {
23
+ return ComponentsV2Builder_js_1.ComponentsV2Builder.createTicketMenu(customId);
24
+ }
25
+ exports.createTicketMenu = createTicketMenu;
26
+
27
+ /**
28
+ * Create a plan selector container.
29
+ */
30
+ function createPlanSelector(customId) {
31
+ return ComponentsV2Builder_js_1.ComponentsV2Builder.createPlanSelector(customId);
32
+ }
33
+ exports.createPlanSelector = createPlanSelector;
34
+
35
+ /**
36
+ * Create a role selector menu container.
37
+ */
38
+ function createRoleMenu(customId) {
39
+ return ComponentsV2Builder_js_1.ComponentsV2Builder.createRoleMenu(customId);
40
+ }
41
+ exports.createRoleMenu = createRoleMenu;
@@ -0,0 +1,58 @@
1
+ import { User, Message, CollectedInteraction } from "discord.js";
2
+ import { AsyncFunction } from "../Loader.js";
3
+ import { Erine } from "../Client.js";
4
+ export type ConfirmatorOptions = {
5
+ author: User;
6
+ filter?: ConfirmatorProcess;
7
+ timeout?: number;
8
+ };
9
+ export type ConfirmatorProcess = AsyncFunction<CollectedInteraction, any>;
10
+ export type ConfirmatorButtonsOptions = {
11
+ continue?: {
12
+ label?: string;
13
+ };
14
+ cancel?: {
15
+ label?: string;
16
+ };
17
+ };
18
+ export declare class Confirmator {
19
+ private _author;
20
+ private _continue;
21
+ private _cancel;
22
+ private _filter;
23
+ filter: ConfirmatorProcess;
24
+ timeout: number;
25
+ message?: Message;
26
+ bot: Erine;
27
+ constructor(bot: Erine, options: ConfirmatorOptions);
28
+ /**
29
+ *
30
+ * @param predicate The function to call when someone clicks the continue button
31
+ */
32
+ setContinueProcess(predicate: ConfirmatorProcess): this;
33
+ /**
34
+ * @param predicate The function to call when someone clicks the cancel button.
35
+ */
36
+ setCancelProcess(predicate: ConfirmatorProcess): this;
37
+ /**
38
+ * @param predicate The function to call when the filter process returns false
39
+ */
40
+ setFilterErrorProcess(predicate: ConfirmatorProcess): this;
41
+ /**
42
+ * @param predicate The function to call and check if is true, if not it will throw an error (setted with .setFilterErrorProcess())
43
+ */
44
+ setFilterCheckProcess(predicate: ConfirmatorProcess): this;
45
+ /**
46
+ * You have to use this after you send the message with the buttons, this is required.
47
+ * @param message The message that will be used in the process
48
+ */
49
+ setMessage(message: Message): this;
50
+ /**
51
+ * @param options Optional options to customize your buttons
52
+ */
53
+ static Buttons(options?: ConfirmatorButtonsOptions): import("discord.js").APIActionRowComponent<import("discord.js").APIStringSelectComponent | import("discord.js").APIChannelSelectComponent | import("discord.js").APIMentionableSelectComponent | import("discord.js").APIUserSelectComponent | import("discord.js").APIRoleSelectComponent | import("discord.js").APIButtonComponent | import("discord.js").APITextInputComponent>;
54
+ /**
55
+ * Start the confirmator, we recommend you to start it after using Confirmator.setMessage()
56
+ */
57
+ start(): void;
58
+ }
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Confirmator = void 0;
4
+
5
+ const discord_js_1 = require("discord.js");
6
+
7
+ class Confirmator {
8
+ _author;
9
+ _continue = async () => null;
10
+ _cancel = async (interaction) => interaction.reply({ content: "Cancelled process.", ephemeral: true });
11
+ _filter = async (interaction) => interaction.reply({ content: "This interaction isn't for you!", ephemeral: true });
12
+ filter = async (interaction) => interaction.user.id !== this._author.id;
13
+ timeout;
14
+ message;
15
+ bot;
16
+
17
+ constructor(bot, options) {
18
+ this._author = options.author;
19
+ this.bot = bot;
20
+ this.timeout = options.timeout ?? 60;
21
+ }
22
+
23
+ setContinueProcess(predicate) {
24
+ this._continue = predicate;
25
+ return this;
26
+ }
27
+
28
+ setCancelProcess(predicate) {
29
+ this._cancel = predicate;
30
+ return this;
31
+ }
32
+
33
+ setFilterErrorProcess(predicate) {
34
+ this._filter = predicate;
35
+ return this;
36
+ }
37
+
38
+ setFilterCheckProcess(predicate) {
39
+ this.filter = predicate;
40
+ return this;
41
+ }
42
+
43
+ setMessage(message) {
44
+ this.message = message;
45
+ return this;
46
+ }
47
+
48
+ static Buttons(options) {
49
+ const continueButton = new discord_js_1.ButtonBuilder()
50
+ .setLabel(options?.continue?.label || "Continue")
51
+ .setStyle(discord_js_1.ButtonStyle.Danger)
52
+ .setCustomId("continueButton");
53
+
54
+ const cancelButton = new discord_js_1.ButtonBuilder()
55
+ .setLabel(options?.cancel?.label || "Cancel")
56
+ .setStyle(discord_js_1.ButtonStyle.Success)
57
+ .setCustomId("cancelButton");
58
+
59
+ return new discord_js_1.ActionRowBuilder().addComponents(continueButton, cancelButton).toJSON();
60
+ }
61
+
62
+ async #disableMessageComponents() {
63
+ if (!this.message?.editable || !this.message.components?.length) return;
64
+
65
+ const components = this.message.components.map((row) => {
66
+ const cloned = discord_js_1.ActionRowBuilder.from(row);
67
+ for (const component of cloned.components) {
68
+ component.setDisabled(true);
69
+ }
70
+ return cloned;
71
+ });
72
+
73
+ await this.message.edit({ components }).catch(() => null);
74
+ }
75
+
76
+ start() {
77
+ if (!this.message) {
78
+ throw new Error("Confirmator.start() requires a message via setMessage().");
79
+ }
80
+
81
+ const collector = this.message.createMessageComponentCollector({
82
+ time: this.timeout * 1000,
83
+ componentType: discord_js_1.ComponentType.Button,
84
+ });
85
+
86
+ collector.on("collect", async (interaction) => {
87
+ if (interaction.customId !== "continueButton" && interaction.customId !== "cancelButton") {
88
+ return;
89
+ }
90
+
91
+ if (await this.filter(interaction)) {
92
+ await this._filter(interaction);
93
+ return;
94
+ }
95
+
96
+ if (interaction.customId === "continueButton") {
97
+ await interaction.deferUpdate();
98
+ await collector.stop("confirmed");
99
+ await this._continue(interaction);
100
+ return;
101
+ }
102
+
103
+ await interaction.deferUpdate();
104
+ await collector.stop("cancelled");
105
+ await this._cancel(interaction);
106
+ });
107
+
108
+ collector.on("end", async () => {
109
+ await this.#disableMessageComponents();
110
+ });
111
+ }
112
+ }
113
+
114
+ exports.Confirmator = Confirmator;
@@ -0,0 +1,65 @@
1
+ import { User, Message, ButtonStyle, CollectedInteraction } from "discord.js";
2
+ import { AsyncFunction } from "../Loader.js";
3
+ import { Erine } from "../Client.js";
4
+ export type ButtonSchema = {
5
+ style?: ButtonStyle;
6
+ label?: string;
7
+ };
8
+ export type PaginatorProcess = AsyncFunction<CollectedInteraction, boolean>;
9
+ export type PaginatorOptions<P = any> = {
10
+ pages: P[];
11
+ author: User;
12
+ filter?: PaginatorProcess;
13
+ timeout?: number;
14
+ };
15
+ export type PaginatorButtonsOptions = {
16
+ next?: ButtonSchema;
17
+ previous?: ButtonSchema;
18
+ };
19
+ export declare class Paginator<P = any> {
20
+ pages: P[];
21
+ filter: PaginatorProcess;
22
+ bot: Erine;
23
+ message?: Message;
24
+ timeout: number;
25
+ private _author;
26
+ private _page;
27
+ private _filter;
28
+ private _update;
29
+ constructor(bot: Erine, options: PaginatorOptions);
30
+ /**
31
+ * Get the page content (provided in the constructor).
32
+ */
33
+ get page(): P;
34
+ /**
35
+ * Get the current page number.
36
+ */
37
+ get pageNumber(): number;
38
+ /**
39
+ * Get the page footer.
40
+ * @example "3/10"
41
+ */
42
+ get pagesFooter(): string;
43
+ /**
44
+ * @param predicate The function to call when someone clicks the cancel button.
45
+ */
46
+ setUpdateProcess(predicate: AsyncFunction<P, any>): this;
47
+ /**
48
+ * @param predicate The function to call when the filter process returns false
49
+ */
50
+ setFilterProcess(predicate: PaginatorProcess): this;
51
+ /**
52
+ * @param predicate The function to call and check if is true, if not it will throw an error (setted with .setFilterErrorProcess())
53
+ */
54
+ setFilterCheckProcess(predicate: PaginatorProcess): this;
55
+ /**
56
+ * You have to use this after you send the message with the buttons, this is required.
57
+ * @param message The message that will be used in the process
58
+ */
59
+ setMessage(message: Message): this;
60
+ /**
61
+ * @param options Optional options to customize your buttons
62
+ */
63
+ static Buttons(options?: PaginatorButtonsOptions): import("discord.js").APIActionRowComponent<import("discord.js").APIStringSelectComponent | import("discord.js").APIChannelSelectComponent | import("discord.js").APIMentionableSelectComponent | import("discord.js").APIUserSelectComponent | import("discord.js").APIRoleSelectComponent | import("discord.js").APIButtonComponent | import("discord.js").APITextInputComponent>;
64
+ start(): void;
65
+ }