gralonium 0.2.0 → 0.4.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 (47) hide show
  1. package/lib/classes/Client.d.ts +9 -11
  2. package/lib/classes/Client.js +10 -13
  3. package/lib/classes/Context.d.ts +43 -4
  4. package/lib/classes/Context.js +251 -12
  5. package/lib/classes/Cooldowns.d.ts +3 -3
  6. package/lib/classes/Cooldowns.js +3 -8
  7. package/lib/classes/HelpCommand.d.ts +55 -13
  8. package/lib/classes/HelpCommand.js +319 -1
  9. package/lib/classes/Loader.d.ts +17 -11
  10. package/lib/classes/Loader.js +43 -42
  11. package/lib/classes/Utils.d.ts +4 -5
  12. package/lib/classes/Utils.js +32 -21
  13. package/lib/classes/builders/CommandBuilder.d.ts +10 -0
  14. package/lib/classes/builders/CommandBuilder.js +16 -0
  15. package/lib/classes/builders/ComponentsV2Builder.d.ts +285 -113
  16. package/lib/classes/builders/ComponentsV2Builder.js +1069 -182
  17. package/lib/classes/builders/GroupBuilder.d.ts +9 -0
  18. package/lib/classes/builders/GroupBuilder.js +16 -0
  19. package/lib/classes/builders/InteractionBuilder.d.ts +40 -25
  20. package/lib/classes/builders/InteractionBuilder.js +102 -1
  21. package/lib/classes/builders/components/StyleMapper.d.ts +1 -1
  22. package/lib/classes/builders/components/StyleMapper.js +2 -1
  23. package/lib/classes/builders/components/helpers.d.ts +68 -4
  24. package/lib/classes/builders/components/helpers.js +366 -7
  25. package/lib/classes/builders/components/templates.d.ts +151 -9
  26. package/lib/classes/builders/components/templates.js +376 -17
  27. package/lib/classes/builders/components/text.d.ts +24 -0
  28. package/lib/classes/builders/components/text.js +91 -0
  29. package/lib/classes/experiments/Confirmator.d.ts +45 -50
  30. package/lib/classes/experiments/Confirmator.js +37 -21
  31. package/lib/classes/experiments/Paginator.d.ts +49 -56
  32. package/lib/classes/experiments/Paginator.js +48 -19
  33. package/lib/classes/views/V2Paginator.d.ts +91 -0
  34. package/lib/classes/views/V2Paginator.js +268 -0
  35. package/lib/classes/views/V2View.d.ts +113 -0
  36. package/lib/classes/views/V2View.js +438 -0
  37. package/lib/experiments.d.ts +2 -0
  38. package/lib/experiments.js +9 -1
  39. package/lib/main.d.ts +3 -3
  40. package/lib/main.js +5 -5
  41. package/package.json +6 -15
  42. package/lib/events/interactionCreate.d.ts +0 -4
  43. package/lib/events/interactionCreate.js +0 -17
  44. package/lib/events/messageCreate.d.ts +0 -4
  45. package/lib/events/messageCreate.js +0 -17
  46. package/lib/events/messageUpdate.d.ts +0 -4
  47. package/lib/events/messageUpdate.js +0 -17
@@ -29,6 +29,8 @@ class CommandBuilder {
29
29
  botPermissions;
30
30
  guards;
31
31
  cooldown;
32
+ integrationTypes;
33
+ contexts;
32
34
 
33
35
  constructor(options) {
34
36
  this.name = options?.name ?? "";
@@ -43,6 +45,8 @@ class CommandBuilder {
43
45
  this.botPermissions = permissionArrayPredicate.parse(options?.botPermissions ?? []);
44
46
  this.guards = options?.guards ?? [];
45
47
  this.cooldown = options?.cooldown;
48
+ this.integrationTypes = options?.integrationTypes;
49
+ this.contexts = options?.contexts;
46
50
  }
47
51
 
48
52
  setName(name) {
@@ -95,12 +99,24 @@ class CommandBuilder {
95
99
  return this;
96
100
  }
97
101
 
102
+ setIntegrationTypes(...types) {
103
+ this.integrationTypes = types.flat();
104
+ return this;
105
+ }
106
+
107
+ setContexts(...contexts) {
108
+ this.contexts = contexts.flat();
109
+ return this;
110
+ }
111
+
98
112
  toJSON() {
99
113
  return {
100
114
  name: this.name,
101
115
  description: this.description,
102
116
  default_member_permissions: this.defaultMemberPermissions ? validateDefaultMemberPermissions(this.defaultMemberPermissions) : undefined,
103
117
  dm_permission: typeof this.guildOnly === "boolean" ? !this.guildOnly : undefined,
118
+ ...(this.integrationTypes !== undefined ? { integration_types: this.integrationTypes } : {}),
119
+ ...(this.contexts !== undefined ? { contexts: this.contexts } : {}),
104
120
  };
105
121
  }
106
122
  }
@@ -1,125 +1,297 @@
1
1
  import {
2
+ ActionRowBuilder,
3
+ AttachmentBuilder,
4
+ BaseMessageOptions,
2
5
  ButtonBuilder,
3
6
  ButtonStyle,
7
+ ChannelType,
4
8
  ContainerBuilder,
5
- MessageFlags,
9
+ FileBuilder,
10
+ MediaGalleryBuilder,
11
+ MediaGalleryItemBuilder,
12
+ Message,
13
+ MessageMentionOptions,
14
+ SectionBuilder,
15
+ SeparatorBuilder,
16
+ SeparatorSpacingSize,
17
+ StringSelectMenuOptionBuilder,
18
+ TextDisplayBuilder,
19
+ ThumbnailBuilder,
6
20
  } from "discord.js";
7
- import { ButtonStyleInput } from "./components/StyleMapper.js";
21
+ import type { DisableComponentsOptions, EmojiInput, ParsedEmoji } from "./components/helpers";
22
+ import type { V2CardOptions, V2ConfirmOptions, V2ImageViewOptions, V2ListOptions } from "./components/templates";
23
+ import { V2Text, type V2FieldRow } from "./components/text";
24
+
25
+ export type ButtonStyleResolvable =
26
+ | "primary"
27
+ | "secondary"
28
+ | "success"
29
+ | "danger"
30
+ | "link"
31
+ | "premium"
32
+ | ButtonStyle
33
+ | number;
34
+
35
+ export type ColorResolvable = string | number | [number, number, number] | null;
36
+
37
+ export type SeparatorSpacingResolvable = "small" | "large" | SeparatorSpacingSize;
38
+
39
+ export type V2SectionFieldRow = V2FieldRow;
40
+
41
+ export interface ComponentsV2BuilderOptions {
42
+ color?: ColorResolvable;
43
+ accentColor?: ColorResolvable;
44
+ spoiler?: boolean;
45
+ safeMentions?: boolean;
46
+ }
47
+
48
+ export interface V2TextOptions {
49
+ ignoreEmpty?: boolean;
50
+ maxLength?: number;
51
+ joinWith?: string;
52
+ }
53
+
54
+ export interface V2FieldsOptions extends V2TextOptions {
55
+ omitEmpty?: boolean;
56
+ omitIfEmpty?: boolean;
57
+ fallback?: string;
58
+ }
59
+
60
+ export interface V2SectionBlockOptions extends V2FieldsOptions {
61
+ separator?: boolean | "small" | "large";
62
+ }
63
+
64
+ export interface V2QuoteOptions {
65
+ ignoreEmpty?: boolean;
66
+ maxLength?: number;
67
+ fallback?: string;
68
+ }
69
+
70
+ export interface V2SmartTextOptions {
71
+ overflow?: "file" | "clip" | "split";
72
+ maxLength?: number;
73
+ limit?: number;
74
+ filename?: string;
75
+ fileDescription?: string;
76
+ spoiler?: boolean;
77
+ preview?: boolean;
78
+ previewLimit?: number;
79
+ overflowNotice?: string;
80
+ codeBlock?: string;
81
+ chunkSize?: number;
82
+ fallbackToFile?: boolean;
83
+ ignoreEmpty?: boolean;
84
+ }
85
+
86
+ export interface V2ButtonObjectOptions {
87
+ label?: string;
88
+ customId?: string;
89
+ id?: string;
90
+ style?: ButtonStyleResolvable;
91
+ url?: string;
92
+ emoji?: EmojiInput;
93
+ disabled?: boolean;
94
+ skuId?: string;
95
+ }
96
+
97
+ export type V2ButtonTuple = [
98
+ label: string,
99
+ customId?: string | null,
100
+ style?: ButtonStyleResolvable,
101
+ url?: string,
102
+ extra?: Partial<V2ButtonObjectOptions>
103
+ ];
104
+
105
+ export type V2ButtonInput = ButtonBuilder | V2ButtonObjectOptions | V2ButtonTuple;
106
+
107
+ export interface V2SectionOptions extends V2TextOptions {
108
+ thumbnail?: string | ThumbnailBuilder | { url?: string | null; description?: string; spoiler?: boolean } | null;
109
+ thumbnailDescription?: string;
110
+ thumbnailSpoiler?: boolean;
111
+ button?: ButtonBuilder | V2ButtonObjectOptions;
112
+ fallbackToText?: boolean;
113
+ }
114
+
115
+ export interface V2GalleryItemObject {
116
+ url: string;
117
+ description?: string;
118
+ spoiler?: boolean;
119
+ }
120
+
121
+ export type V2GalleryEntry = string | MediaGalleryItemBuilder | V2GalleryItemObject | null | undefined | false;
122
+ export type V2GalleryInput = MediaGalleryBuilder | V2GalleryEntry | V2GalleryEntry[];
123
+
124
+ export interface V2GalleryOptions {
125
+ description?: string;
126
+ spoiler?: boolean;
127
+ ignoreEmpty?: boolean;
128
+ ignoreInvalid?: boolean;
129
+ autoSplit?: boolean;
130
+ }
131
+
132
+ export interface V2AttachmentOptions {
133
+ name?: string;
134
+ description?: string;
135
+ }
136
+
137
+ export interface V2FileOptions extends V2AttachmentOptions {
138
+ spoiler?: boolean;
139
+ attachment?: Buffer | Uint8Array | string | AttachmentBuilder;
140
+ }
141
+
142
+ export interface V2FileInput {
143
+ source: Buffer | Uint8Array | string | AttachmentBuilder;
144
+ name?: string;
145
+ description?: string;
146
+ spoiler?: boolean;
147
+ }
148
+
149
+ export interface V2StringSelectOption {
150
+ label: string;
151
+ value?: string;
152
+ description?: string;
153
+ emoji?: EmojiInput;
154
+ default?: boolean;
155
+ }
156
+
157
+ export type V2SelectOptionTuple = [
158
+ label: string,
159
+ value?: string,
160
+ description?: string,
161
+ emoji?: EmojiInput,
162
+ isDefault?: boolean
163
+ ];
164
+
165
+ export interface V2SelectMenuConfig {
166
+ type?: "string" | "user" | "role" | "channel" | "mentionable";
167
+ customId?: string;
168
+ id?: string;
169
+ placeholder?: string;
170
+ minValues?: number;
171
+ maxValues?: number;
172
+ disabled?: boolean;
173
+ options?: Array<V2StringSelectOption | V2SelectOptionTuple | StringSelectMenuOptionBuilder>;
174
+ channelTypes?: ChannelType[];
175
+ defaultValues?: Array<string | { id: string; type: number }>;
176
+ defaultUsers?: string[];
177
+ defaultRoles?: string[];
178
+ defaultChannels?: string[];
179
+ }
180
+
181
+ export interface V2PayloadOptions {
182
+ ephemeral?: boolean;
183
+ suppressNotifications?: boolean;
184
+ flags?: number;
185
+ safeMentions?: boolean;
186
+ allowedMentions?: MessageMentionOptions;
187
+ files?: BaseMessageOptions["files"];
188
+ }
189
+
190
+ export interface V2BuiltPayload {
191
+ components: TopLevelV2Component[];
192
+ flags: number;
193
+ files?: Array<AttachmentBuilder | NonNullable<BaseMessageOptions["files"]>[number]>;
194
+ allowedMentions?: MessageMentionOptions;
195
+ }
196
+
197
+ export type TopLevelV2Component =
198
+ | ContainerBuilder
199
+ | SectionBuilder
200
+ | TextDisplayBuilder
201
+ | SeparatorBuilder
202
+ | MediaGalleryBuilder
203
+ | FileBuilder
204
+ | ActionRowBuilder<any>;
8
205
 
9
- /**
10
- * Fluent proxy returned by `ComponentsV2Builder#addSelectMenu()`.
11
- * Call `.end()` to return to the parent builder.
12
- */
13
206
  export declare class SelectMenuProxy {
14
- /**
15
- * Add an option to the select menu.
16
- *
17
- * @param label - Display label for the option
18
- * @param value - Value submitted when the option is selected
19
- * @param emoji - Unicode emoji (optional)
20
- * @param description - Short description shown below the label (optional)
21
- */
22
- addOption(label: string, value?: string, emoji?: string, description?: string): this;
23
-
24
- /** Return to the parent `ComponentsV2Builder`. */
207
+ addOption(option: V2StringSelectOption | StringSelectMenuOptionBuilder): this;
208
+ addOption(label: string, value: string, description?: string, emoji?: EmojiInput, isDefault?: boolean): this;
209
+ addOptions(options: Array<V2StringSelectOption | V2SelectOptionTuple | StringSelectMenuOptionBuilder | false | null | undefined>): this;
210
+ setPlaceholder(placeholder: string): this;
211
+ setMinValues(min: number): this;
212
+ setMaxValues(max: number): this;
213
+ setDisabled(disabled?: boolean): this;
25
214
  end(): ComponentsV2Builder;
26
215
  }
27
216
 
28
- /**
29
- * ComponentsV2Builder — a fluent builder that abstracts the complexity of
30
- * Discord.js Components V2 (Containers, Separators, TextDisplays, Buttons,
31
- * and StringSelectMenus).
32
- *
33
- * @example
34
- * ```ts
35
- * const components = new ComponentsV2Builder()
36
- * .addText("## Welcome!")
37
- * .addSeparator("small")
38
- * .addButton("Click Me", "btn_1", "primary")
39
- * .addButton("Cancel", "btn_2", "secondary")
40
- * .build();
41
- *
42
- * interaction.reply({ components, flags: ComponentsV2Builder.flags });
43
- * ```
44
- */
45
217
  export declare class ComponentsV2Builder {
46
- /**
47
- * Add a text display (markdown supported) to the container.
48
- */
49
- addText(content: string): this;
50
-
51
- /**
52
- * Add a separator to the container.
53
- *
54
- * @param spacing - "small" | "large" (defaults to "small")
55
- * @param divider - Whether to render a visual divider line (defaults to true)
56
- */
57
- addSeparator(spacing?: "small" | "large", divider?: boolean): this;
58
-
59
- /**
60
- * Add a single button to the container.
61
- * Buttons are batched and placed into ActionRows automatically (max 5 per row).
62
- *
63
- * @param label - Button label text
64
- * @param customId - Custom ID (or URL for link buttons)
65
- * @param style - "primary" | "secondary" | "success" | "danger" | "link"
66
- * @param url - URL (only used when style is "link")
67
- */
68
- addButton(label: string, customId?: string, style?: ButtonStyleInput, url?: string): this;
69
-
70
- /**
71
- * Add multiple pre-built `ButtonBuilder` instances at once.
72
- * They are batched into ActionRows automatically (max 5 per row).
73
- */
74
- addButtons(...buttons: ButtonBuilder[]): this;
75
-
76
- /**
77
- * Add a `StringSelectMenu` to the container.
78
- * Returns a `SelectMenuProxy` for adding options fluently.
79
- * Call `.end()` on the proxy to return to this builder.
80
- *
81
- * @param customId - Custom ID for the select menu
82
- * @param placeholder - Placeholder text (optional)
83
- */
84
- addSelectMenu(customId?: string, placeholder?: string): SelectMenuProxy;
85
-
86
- /**
87
- * Mark the container as a spoiler (blurred until clicked).
88
- */
89
- setSpoiler(spoiler: boolean): this;
90
-
91
- /**
92
- * Build and return the components array ready for
93
- * `interaction.reply({ components: builder.build(), flags: ComponentsV2Builder.flags })`.
94
- */
95
- build(): ContainerBuilder[];
96
-
97
- /**
98
- * The `MessageFlags` bitmask required for Components V2 messages.
99
- *
100
- * ```ts
101
- * interaction.reply({ components: builder.build(), flags: ComponentsV2Builder.flags });
102
- * ```
103
- */
104
- static readonly flags: MessageFlags;
105
-
106
- /**
107
- * Create a Confirm / Cancel button container.
108
- */
109
- static createConfirm(confirmId?: string, cancelId?: string): ComponentsV2Builder;
110
-
111
- /**
112
- * Create a ticket category select menu container.
113
- */
114
- static createTicketMenu(customId?: string): ComponentsV2Builder;
115
-
116
- /**
117
- * Create a plan selector container (bot / game / web hosting example).
118
- */
119
- static createPlanSelector(customId?: string): ComponentsV2Builder;
120
-
121
- /**
122
- * Create a role selector menu container.
123
- */
124
- static createRoleMenu(customId?: string): ComponentsV2Builder;
218
+ static readonly flags: number;
219
+ static readonly MAX_TEXT_LENGTH: number;
220
+ static readonly SAFE_TEXT_LENGTH: number;
221
+ static readonly MAX_COMPONENTS: number;
222
+ static readonly MAX_TOP_LEVEL_COMPONENTS: number;
223
+ static readonly text: typeof V2Text;
224
+ static clipText(text: string, maxLen?: number, fallback?: string): string;
225
+ static resolveColor(color?: ColorResolvable, fallback?: ColorResolvable): number | null;
226
+ static parseEmoji(emoji?: EmojiInput): ParsedEmoji | null;
227
+ static isValidMediaUrl(url?: string | null): boolean;
228
+ static isValidLinkUrl(url?: string | null): boolean;
229
+ static disableComponents(components: any[], options?: DisableComponentsOptions): any[];
230
+ static disableMessageComponents(message: Message, options?: DisableComponentsOptions): Promise<Message | null>;
231
+ static countTextLength(components: any[]): number;
232
+ static countComponents(components: any[]): number;
233
+ static isBuilder(value: unknown): value is ComponentsV2Builder;
234
+
235
+ constructor(options?: ComponentsV2BuilderOptions);
236
+
237
+ setColor(color: ColorResolvable): this;
238
+ setAccentColor(color: ColorResolvable): this;
239
+ setSpoiler(spoiler?: boolean): this;
240
+ addContainer(options?: ComponentsV2BuilderOptions): this;
241
+ outside(): this;
242
+ inside(options?: ComponentsV2BuilderOptions & { new?: boolean; newContainer?: boolean }): this;
243
+
244
+ addText(content: string | TextDisplayBuilder | Array<string | TextDisplayBuilder | false | null | undefined>, options?: V2TextOptions): this;
245
+ addFields(rows: Array<V2FieldRow | false | null | undefined>, options?: V2FieldsOptions): this;
246
+ addSectionBlock(heading: string, rows: Array<V2FieldRow | false | null | undefined>, options?: V2SectionBlockOptions): this;
247
+ addQuote(text: string, options?: V2QuoteOptions): this;
248
+ addSmartText(text: string, options?: V2SmartTextOptions): this;
249
+
250
+ addSection(
251
+ texts: string | TextDisplayBuilder | Array<string | TextDisplayBuilder | false | null | undefined>,
252
+ accessoryOrOptions?: ThumbnailBuilder | ButtonBuilder | V2SectionOptions
253
+ ): this;
254
+
255
+ addGallery(itemsOrUrl: V2GalleryInput, options?: V2GalleryOptions): this;
256
+ addAttachment(source: Buffer | Uint8Array | string | AttachmentBuilder, options?: V2AttachmentOptions): this;
257
+ addFile(source: Buffer | Uint8Array | string | AttachmentBuilder | FileBuilder, options?: V2FileOptions): this;
258
+
259
+ addSeparator(spacing?: SeparatorSpacingResolvable | { spacing?: SeparatorSpacingResolvable; divider?: boolean }, divider?: boolean): this;
260
+ addSpacer(spacing?: SeparatorSpacingResolvable): this;
261
+
262
+ addButton(options: V2ButtonObjectOptions | ButtonBuilder): this;
263
+ addButton(label: string, customId?: string | null, style?: ButtonStyleResolvable, url?: string, extraOptions?: Partial<V2ButtonObjectOptions>): this;
264
+ addButtons(buttons: Array<V2ButtonInput | false | null | undefined>, options?: { autoWrap?: boolean }): this;
265
+ addButtonsRow(buttons: Array<V2ButtonInput | false | null | undefined>, options?: { autoWrap?: boolean }): this;
266
+
267
+ addSelectMenu(config: V2SelectMenuConfig): this;
268
+ addSelectMenu(customId: string, placeholder?: string): SelectMenuProxy;
269
+ addSelectRow(config: V2SelectMenuConfig): this;
270
+ addUserSelectMenu(configOrCustomId: string | Omit<V2SelectMenuConfig, "type">, options?: Omit<V2SelectMenuConfig, "type" | "customId">): this;
271
+ addRoleSelectMenu(configOrCustomId: string | Omit<V2SelectMenuConfig, "type">, options?: Omit<V2SelectMenuConfig, "type" | "customId">): this;
272
+ addChannelSelectMenu(configOrCustomId: string | Omit<V2SelectMenuConfig, "type">, options?: Omit<V2SelectMenuConfig, "type" | "customId">): this;
273
+ addMentionableSelectMenu(configOrCustomId: string | Omit<V2SelectMenuConfig, "type">, options?: Omit<V2SelectMenuConfig, "type" | "customId">): this;
274
+
275
+ addComponent(component: TopLevelV2Component): this;
276
+
277
+ readonly textLength: number;
278
+ readonly remainingChars: number;
279
+ readonly componentCount: number;
280
+ readonly remainingComponents: number;
281
+ readonly files: AttachmentBuilder[];
282
+
283
+ build(): TopLevelV2Component[];
284
+ toJSON(): Record<string, unknown>[];
285
+ toPayload(options?: V2PayloadOptions): V2BuiltPayload;
286
+
287
+ static card(options?: V2CardOptions): ComponentsV2Builder;
288
+ static imageView(options?: V2ImageViewOptions): ComponentsV2Builder;
289
+ static list<T = unknown>(options?: V2ListOptions<T>): ComponentsV2Builder;
290
+ static confirm(options: V2ConfirmOptions): ComponentsV2Builder;
291
+ static confirm(confirmId: string, cancelId: string, title?: string, message?: string): ComponentsV2Builder;
292
+ static createConfirm(options: V2ConfirmOptions): ComponentsV2Builder;
293
+ static createConfirm(confirmId: string, cancelId: string, title?: string, message?: string): ComponentsV2Builder;
294
+ static createTicketMenu(customId: string, title?: string, description?: string): { builder: ComponentsV2Builder; select: SelectMenuProxy };
295
+ static createPlanSelector(customId: string, title?: string, description?: string): { builder: ComponentsV2Builder; select: SelectMenuProxy };
296
+ static createRoleMenu(customId: string, title?: string, description?: string): { builder: ComponentsV2Builder; select: SelectMenuProxy };
125
297
  }