gralonium 0.4.0 → 0.5.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 (40) hide show
  1. package/lib/classes/Client.d.ts +13 -3
  2. package/lib/classes/Client.js +23 -1
  3. package/lib/classes/Context.d.ts +2 -0
  4. package/lib/classes/Context.js +94 -21
  5. package/lib/classes/Cooldowns.d.ts +2 -0
  6. package/lib/classes/Cooldowns.js +28 -0
  7. package/lib/classes/Loader.d.ts +12 -3
  8. package/lib/classes/Loader.js +141 -19
  9. package/lib/classes/Plugins.js +3 -2
  10. package/lib/classes/Utils.d.ts +1 -1
  11. package/lib/classes/Utils.js +110 -20
  12. package/lib/classes/builders/CommandBuilder.d.ts +14 -0
  13. package/lib/classes/builders/CommandBuilder.js +50 -2
  14. package/lib/classes/builders/ComponentsV2Builder.d.ts +51 -3
  15. package/lib/classes/builders/ComponentsV2Builder.js +394 -72
  16. package/lib/classes/builders/GroupBuilder.d.ts +11 -0
  17. package/lib/classes/builders/GroupBuilder.js +21 -1
  18. package/lib/classes/builders/InteractionBuilder.d.ts +47 -0
  19. package/lib/classes/builders/InteractionBuilder.js +113 -2
  20. package/lib/classes/builders/ParamsBuilder.d.ts +118 -76
  21. package/lib/classes/builders/ParamsBuilder.js +167 -1
  22. package/lib/classes/builders/components/StyleMapper.d.ts +13 -1
  23. package/lib/classes/builders/components/StyleMapper.js +33 -8
  24. package/lib/classes/builders/components/helpers.d.ts +3 -0
  25. package/lib/classes/builders/components/helpers.js +56 -3
  26. package/lib/classes/builders/components/linter.d.ts +61 -0
  27. package/lib/classes/builders/components/linter.js +252 -0
  28. package/lib/classes/builders/components/overflow.d.ts +151 -0
  29. package/lib/classes/builders/components/overflow.js +534 -0
  30. package/lib/classes/views/V2Adaptive.d.ts +103 -0
  31. package/lib/classes/views/V2Adaptive.js +502 -0
  32. package/lib/classes/views/V2PersistentRouter.d.ts +124 -0
  33. package/lib/classes/views/V2PersistentRouter.js +511 -0
  34. package/lib/classes/views/V2View.d.ts +1 -0
  35. package/lib/classes/views/V2View.js +53 -15
  36. package/lib/experiments.d.ts +2 -0
  37. package/lib/experiments.js +2 -0
  38. package/lib/main.d.ts +4 -0
  39. package/lib/main.js +4 -0
  40. package/package.json +1 -1
@@ -22,6 +22,8 @@ class GroupBuilder {
22
22
  guards;
23
23
  integrationTypes;
24
24
  contexts;
25
+ nameLocalizations;
26
+ descriptionLocalizations;
25
27
 
26
28
  constructor(options) {
27
29
  this.commands = [];
@@ -37,6 +39,12 @@ class GroupBuilder {
37
39
  this.guards = options?.guards ?? [];
38
40
  this.integrationTypes = options?.integrationTypes;
39
41
  this.contexts = options?.contexts;
42
+ this.nameLocalizations = (0, CommandBuilder_js_1.normalizeNameLocalizations)(
43
+ options?.nameLocalizations ?? options?.name_localizations
44
+ );
45
+ this.descriptionLocalizations = (0, CommandBuilder_js_1.normalizeDescriptionLocalizations)(
46
+ options?.descriptionLocalizations ?? options?.description_localizations
47
+ );
40
48
  }
41
49
 
42
50
  setName(name) {
@@ -89,15 +97,27 @@ class GroupBuilder {
89
97
  return this;
90
98
  }
91
99
 
100
+ setNameLocalizations(locales) {
101
+ this.nameLocalizations = (0, CommandBuilder_js_1.normalizeNameLocalizations)(locales);
102
+ return this;
103
+ }
104
+
105
+ setDescriptionLocalizations(locales) {
106
+ this.descriptionLocalizations = (0, CommandBuilder_js_1.normalizeDescriptionLocalizations)(locales);
107
+ return this;
108
+ }
109
+
92
110
  toJSON() {
93
111
  return {
94
112
  name: this.name,
95
- description: this.description,
113
+ description: String(this.description ?? "...").slice(0, 100),
96
114
  options: [],
97
115
  default_member_permissions: this.defaultMemberPermissions
98
116
  ? (0, CommandBuilder_js_1.validateDefaultMemberPermissions)(this.defaultMemberPermissions)
99
117
  : undefined,
100
118
  dm_permission: typeof this.guildOnly === "boolean" ? !this.guildOnly : undefined,
119
+ ...(this.nameLocalizations ? { name_localizations: this.nameLocalizations } : {}),
120
+ ...(this.descriptionLocalizations ? { description_localizations: this.descriptionLocalizations } : {}),
101
121
  ...(this.integrationTypes !== undefined ? { integration_types: this.integrationTypes } : {}),
102
122
  ...(this.contexts !== undefined ? { contexts: this.contexts } : {}),
103
123
  };
@@ -1,3 +1,6 @@
1
+ import type { ApplicationCommandType, ApplicationIntegrationType, InteractionContextType } from "discord.js";
2
+ import type { LocalizationMap } from "./CommandBuilder.js";
3
+
1
4
  export declare enum Interactions {
2
5
  AnyInteraction = "anyInteraction",
3
6
  Autocomplete = "autocomplete",
@@ -5,6 +8,7 @@ export declare enum Interactions {
5
8
  ChatInput = "chatInput",
6
9
  MessageContextMenu = "messageContextMenu",
7
10
  Modal = "modalSubmit",
11
+ OverflowMenu = "overflowMenu",
8
12
  UserContextMenu = "userContextMenu",
9
13
  ChannelSelectMenu = "channelSelectMenu",
10
14
  RoleSelectMenu = "roleSelectMenu",
@@ -21,6 +25,15 @@ export interface InteractionDataBuilder {
21
25
  description?: string;
22
26
  prefix?: string;
23
27
  match?: InteractionMatcher;
28
+ as_command?: boolean;
29
+ guildOnly?: boolean;
30
+ defaultMemberPermissions?: string | bigint;
31
+ integrationTypes?: Array<ApplicationIntegrationType | number>;
32
+ contexts?: Array<InteractionContextType | number>;
33
+ nameLocalizations?: LocalizationMap;
34
+ name_localizations?: LocalizationMap;
35
+ descriptionLocalizations?: LocalizationMap;
36
+ description_localizations?: LocalizationMap;
24
37
  }
25
38
 
26
39
  export declare class InteractionBuilder {
@@ -29,11 +42,25 @@ export declare class InteractionBuilder {
29
42
  description: string;
30
43
  prefix?: string;
31
44
  match?: InteractionMatcher;
45
+ as_command: boolean;
46
+ guildOnly: boolean | undefined;
47
+ defaultMemberPermissions?: string | bigint | undefined;
48
+ integrationTypes?: Array<ApplicationIntegrationType | number>;
49
+ contexts?: Array<InteractionContextType | number>;
50
+ nameLocalizations?: LocalizationMap;
51
+ descriptionLocalizations?: LocalizationMap;
32
52
  constructor(options?: InteractionDataBuilder);
33
53
  setName(name: string): this;
34
54
  setDescription(description: string): this;
35
55
  setPrefix(prefix: string): this;
36
56
  setMatcher(matcher: InteractionMatcher): this;
57
+ setNameLocalizations(locales?: LocalizationMap | null): this;
58
+ setDescriptionLocalizations(locales?: LocalizationMap | null): this;
59
+ setIntegrationTypes(...types: Array<ApplicationIntegrationType | number | Array<ApplicationIntegrationType | number>>): this;
60
+ setContexts(...contexts: Array<InteractionContextType | number | Array<InteractionContextType | number>>): this;
61
+ setDefaultMemberPermissions(permissions: string | bigint | undefined): this;
62
+ setGuildOnly(guildOnly?: boolean): this;
63
+ allowCommand(allow?: boolean): this;
37
64
  hasPattern(): boolean;
38
65
  matches(key: string, interaction?: any): boolean;
39
66
  /**
@@ -42,6 +69,26 @@ export declare class InteractionBuilder {
42
69
  toJSON(): {
43
70
  name: string | undefined;
44
71
  description: string;
72
+ default_member_permissions?: string | null;
73
+ dm_permission?: boolean;
45
74
  prefix?: string;
75
+ name_localizations?: LocalizationMap;
76
+ description_localizations?: LocalizationMap;
77
+ integration_types?: Array<ApplicationIntegrationType | number>;
78
+ contexts?: Array<InteractionContextType | number>;
46
79
  };
80
+ /**
81
+ * Returns the application command payload for context menu commands (`type: 2` / `type: 3`).
82
+ */
83
+ toCommandJSON(): {
84
+ name: string | undefined;
85
+ type: ApplicationCommandType;
86
+ description?: string;
87
+ default_member_permissions?: string | null;
88
+ dm_permission?: boolean;
89
+ name_localizations?: LocalizationMap;
90
+ description_localizations?: LocalizationMap;
91
+ integration_types?: Array<ApplicationIntegrationType | number>;
92
+ contexts?: Array<InteractionContextType | number>;
93
+ } | null;
47
94
  }
@@ -2,6 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.InteractionBuilder = exports.Interactions = void 0;
4
4
 
5
+ const discord_js_1 = require("discord.js");
6
+ const CommandBuilder_js_1 = require("./CommandBuilder.js");
7
+
5
8
  var Interactions;
6
9
  (function (Interactions) {
7
10
  Interactions.AnyInteraction = "anyInteraction";
@@ -10,6 +13,7 @@ var Interactions;
10
13
  Interactions.ChatInput = "chatInput";
11
14
  Interactions.MessageContextMenu = "messageContextMenu";
12
15
  Interactions.Modal = "modalSubmit";
16
+ Interactions.OverflowMenu = "overflowMenu";
13
17
  Interactions.UserContextMenu = "userContextMenu";
14
18
  Interactions.ChannelSelectMenu = "channelSelectMenu";
15
19
  Interactions.RoleSelectMenu = "roleSelectMenu";
@@ -20,7 +24,8 @@ var Interactions;
20
24
 
21
25
  /**
22
26
  * Builder describing an interaction handler loaded by Gralonium.
23
- * Supports exact `name`/`customId` matching as well as `prefix` and `match` (RegExp or predicate).
27
+ * Supports exact `name`/`customId` matching, `prefix` / `match` routing,
28
+ * localizations, and context-menu application command metadata.
24
29
  */
25
30
  class InteractionBuilder {
26
31
  name;
@@ -28,6 +33,13 @@ class InteractionBuilder {
28
33
  description;
29
34
  prefix;
30
35
  match;
36
+ as_command;
37
+ guildOnly;
38
+ defaultMemberPermissions;
39
+ integrationTypes;
40
+ contexts;
41
+ nameLocalizations;
42
+ descriptionLocalizations;
31
43
 
32
44
  constructor(options) {
33
45
  this.name = options?.name;
@@ -35,6 +47,17 @@ class InteractionBuilder {
35
47
  this.description = options?.description || "...";
36
48
  this.prefix = options?.prefix;
37
49
  this.match = options?.match;
50
+ this.as_command = options?.as_command ?? true;
51
+ this.guildOnly = options?.guildOnly;
52
+ this.defaultMemberPermissions = options?.defaultMemberPermissions;
53
+ this.integrationTypes = options?.integrationTypes;
54
+ this.contexts = options?.contexts;
55
+ this.nameLocalizations = (0, CommandBuilder_js_1.normalizeNameLocalizations)(
56
+ options?.nameLocalizations ?? options?.name_localizations
57
+ );
58
+ this.descriptionLocalizations = (0, CommandBuilder_js_1.normalizeDescriptionLocalizations)(
59
+ options?.descriptionLocalizations ?? options?.description_localizations
60
+ );
38
61
  }
39
62
 
40
63
  setName(name) {
@@ -63,6 +86,41 @@ class InteractionBuilder {
63
86
  return this;
64
87
  }
65
88
 
89
+ setNameLocalizations(locales) {
90
+ this.nameLocalizations = (0, CommandBuilder_js_1.normalizeNameLocalizations)(locales);
91
+ return this;
92
+ }
93
+
94
+ setDescriptionLocalizations(locales) {
95
+ this.descriptionLocalizations = (0, CommandBuilder_js_1.normalizeDescriptionLocalizations)(locales);
96
+ return this;
97
+ }
98
+
99
+ setIntegrationTypes(...types) {
100
+ this.integrationTypes = types.flat();
101
+ return this;
102
+ }
103
+
104
+ setContexts(...contexts) {
105
+ this.contexts = contexts.flat();
106
+ return this;
107
+ }
108
+
109
+ setDefaultMemberPermissions(permissions) {
110
+ this.defaultMemberPermissions = permissions;
111
+ return this;
112
+ }
113
+
114
+ setGuildOnly(guildOnly = true) {
115
+ this.guildOnly = Boolean(guildOnly);
116
+ return this;
117
+ }
118
+
119
+ allowCommand(allow = true) {
120
+ this.as_command = Boolean(allow);
121
+ return this;
122
+ }
123
+
66
124
  /**
67
125
  * Returns true if this builder uses a dynamic prefix, RegExp, or predicate matcher.
68
126
  */
@@ -93,10 +151,63 @@ class InteractionBuilder {
93
151
  toJSON() {
94
152
  return {
95
153
  name: this.name,
96
- description: this.description,
154
+ description: String(this.description ?? "...").slice(0, 100),
155
+ ...(this.defaultMemberPermissions !== undefined
156
+ ? {
157
+ default_member_permissions: (0, CommandBuilder_js_1.validateDefaultMemberPermissions)(
158
+ this.defaultMemberPermissions
159
+ ),
160
+ }
161
+ : {}),
162
+ ...(typeof this.guildOnly === "boolean" ? { dm_permission: !this.guildOnly } : {}),
97
163
  ...(this.prefix !== undefined ? { prefix: this.prefix } : {}),
164
+ ...(this.nameLocalizations ? { name_localizations: this.nameLocalizations } : {}),
165
+ ...(this.descriptionLocalizations ? { description_localizations: this.descriptionLocalizations } : {}),
166
+ ...(this.integrationTypes !== undefined ? { integration_types: this.integrationTypes } : {}),
167
+ ...(this.contexts !== undefined ? { contexts: this.contexts } : {}),
98
168
  };
99
169
  }
170
+
171
+ /**
172
+ * Builds the Discord application command payload for context menu commands (`type: 2` / `type: 3`).
173
+ */
174
+ toCommandJSON() {
175
+ if (this.as_command === false) {
176
+ return null;
177
+ }
178
+
179
+ const commandType =
180
+ this.type === Interactions.UserContextMenu
181
+ ? discord_js_1.ApplicationCommandType.User
182
+ : this.type === Interactions.MessageContextMenu
183
+ ? discord_js_1.ApplicationCommandType.Message
184
+ : discord_js_1.ApplicationCommandType.ChatInput;
185
+
186
+ const payload = {
187
+ name: this.name,
188
+ type: commandType,
189
+ ...(this.defaultMemberPermissions !== undefined
190
+ ? {
191
+ default_member_permissions: (0, CommandBuilder_js_1.validateDefaultMemberPermissions)(
192
+ this.defaultMemberPermissions
193
+ ),
194
+ }
195
+ : {}),
196
+ ...(typeof this.guildOnly === "boolean" ? { dm_permission: !this.guildOnly } : {}),
197
+ ...(this.nameLocalizations ? { name_localizations: this.nameLocalizations } : {}),
198
+ ...(this.integrationTypes !== undefined ? { integration_types: this.integrationTypes } : {}),
199
+ ...(this.contexts !== undefined ? { contexts: this.contexts } : {}),
200
+ };
201
+
202
+ if (commandType === discord_js_1.ApplicationCommandType.ChatInput) {
203
+ payload.description = String(this.description ?? "...").slice(0, 100);
204
+ if (this.descriptionLocalizations) {
205
+ payload.description_localizations = this.descriptionLocalizations;
206
+ }
207
+ }
208
+
209
+ return payload;
210
+ }
100
211
  }
101
212
 
102
213
  exports.InteractionBuilder = InteractionBuilder;
@@ -1,87 +1,129 @@
1
1
  import { ApplicationCommandOptionType, ChannelType } from "discord.js";
2
+ import type { LocalizationMap } from "./CommandBuilder.js";
3
+
4
+ export interface ParamChoice<V = string | number> {
5
+ name: string;
6
+ value: V;
7
+ name_localizations?: LocalizationMap;
8
+ nameLocalizations?: LocalizationMap;
9
+ }
10
+
2
11
  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;
12
+ /** The name for this parameter. */
13
+ name: string;
14
+ /** The description for this parameter. */
15
+ description: string;
16
+ /** Mark this param as required or not. */
17
+ required?: boolean;
18
+ /** Localized option names. */
19
+ name_localizations?: LocalizationMap;
20
+ nameLocalizations?: LocalizationMap;
21
+ /** Localized option descriptions. */
22
+ description_localizations?: LocalizationMap;
23
+ descriptionLocalizations?: LocalizationMap;
24
+ /** Parameter type. (if needed) */
25
+ type?: ApplicationCommandOptionType;
26
+ /** Parameter default value. */
27
+ value?: any;
28
+ /** Mostly to be used for string. Return all arguments after this parameter (including this one) */
29
+ ellipsis?: boolean;
15
30
  }
31
+
16
32
  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;
33
+ /** String choices. */
34
+ choices?: ParamChoice<string>[];
35
+ /** Maximum string length. */
36
+ max_length?: number;
37
+ maxLength?: number;
38
+ /** Minimum string length. */
39
+ min_length?: number;
40
+ minLength?: number;
41
+ /** Mark this command as autocomplete. */
42
+ autocomplete?: boolean;
28
43
  }
44
+
29
45
  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
- }[];
46
+ /** Maximum number value. */
47
+ max_value?: number;
48
+ maxValue?: number;
49
+ /** Minimum number value. */
50
+ min_value?: number;
51
+ minValue?: number;
52
+ /** Number choices. */
53
+ choices?: ParamChoice<number | string>[];
54
+ autocomplete?: boolean;
55
+ }
56
+
57
+ export interface IntegerParam extends BaseParam {
58
+ /** Maximum integer value. */
59
+ max_value?: number;
60
+ maxValue?: number;
61
+ /** Minimum integer value. */
62
+ min_value?: number;
63
+ minValue?: number;
64
+ /** Integer choices. */
65
+ choices?: ParamChoice<number | string>[];
66
+ autocomplete?: boolean;
39
67
  }
68
+
40
69
  export interface ChannelParam extends BaseParam {
41
- /** An array of allowed channel types. */
42
- channel_types?: ChannelType[];
70
+ /** An array of allowed channel types. */
71
+ channel_types?: ChannelType[];
72
+ channelTypes?: ChannelType[];
43
73
  }
74
+
75
+ export type MentionableParam = BaseParam;
76
+
44
77
  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;
78
+ params: BaseParam[];
79
+ quoted: boolean;
80
+ /**
81
+ * Enable or disable quoted arguments.
82
+ * @param value Boolean value.
83
+ */
84
+ setQuoted(value: boolean): ParamsBuilder;
85
+ /**
86
+ * Adds a string option.
87
+ */
88
+ addString(param: StringParam): ParamsBuilder;
89
+ /**
90
+ * Adds a number option.
91
+ */
92
+ addNumber(param: NumberParam): ParamsBuilder;
93
+ /**
94
+ * Adds an integer option.
95
+ */
96
+ addInteger(param: IntegerParam): ParamsBuilder;
97
+ /**
98
+ * Adds a boolean option.
99
+ */
100
+ addBoolean(param: BaseParam): ParamsBuilder;
101
+ /**
102
+ * Adds a guild member / user option.
103
+ */
104
+ addMember(param: BaseParam): ParamsBuilder;
105
+ /**
106
+ * Alias of `addMember`.
107
+ */
108
+ addUser(param: BaseParam): ParamsBuilder;
109
+ /**
110
+ * Adds a guild channel option.
111
+ */
112
+ addChannel(param: ChannelParam): ParamsBuilder;
113
+ /**
114
+ * Adds a role option.
115
+ */
116
+ addRole(param: BaseParam): ParamsBuilder;
117
+ /**
118
+ * Adds an attachment option.
119
+ */
120
+ addAttachment(param: BaseParam): ParamsBuilder;
121
+ /**
122
+ * Adds a mentionable (user or role) option.
123
+ */
124
+ addMentionable(param: MentionableParam): ParamsBuilder;
125
+ /**
126
+ * Serializes options cleanly for Discord ApplicationCommand registration.
127
+ */
128
+ toJSON(): Record<string, any>[];
87
129
  }
@@ -1 +1,167 @@
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;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ParamsBuilder = void 0;
4
+
5
+ const discord_js_1 = require("discord.js");
6
+ const CommandBuilder_js_1 = require("./CommandBuilder.js");
7
+
8
+ const INTERNAL_RUNTIME_KEYS = new Set([
9
+ "ellipsis",
10
+ "value",
11
+ "minLength",
12
+ "maxLength",
13
+ "minValue",
14
+ "maxValue",
15
+ "channelTypes",
16
+ "nameLocalizations",
17
+ "descriptionLocalizations",
18
+ ]);
19
+
20
+ function normalizeChoices(choices) {
21
+ if (!Array.isArray(choices)) return undefined;
22
+ return choices.map((choice) => {
23
+ const out = {
24
+ name: String(choice.name),
25
+ value: choice.value,
26
+ };
27
+ const nameLocs = (0, CommandBuilder_js_1.normalizeNameLocalizations)(
28
+ choice.name_localizations ?? choice.nameLocalizations
29
+ );
30
+ if (nameLocs) {
31
+ out.name_localizations = nameLocs;
32
+ }
33
+ return out;
34
+ });
35
+ }
36
+
37
+ class ParamsBuilder {
38
+ params = [];
39
+ quoted = true;
40
+
41
+ setQuoted(value) {
42
+ this.quoted = value;
43
+ return this;
44
+ }
45
+
46
+ #normalizeParam(param, type) {
47
+ const normalized = { ...param, type };
48
+
49
+ if (normalized.description !== undefined) {
50
+ normalized.description = String(normalized.description ?? "...").slice(0, 100);
51
+ }
52
+
53
+ if (normalized.min_length === undefined && normalized.minLength !== undefined) {
54
+ normalized.min_length = normalized.minLength;
55
+ }
56
+ if (normalized.max_length === undefined && normalized.maxLength !== undefined) {
57
+ normalized.max_length = normalized.maxLength;
58
+ }
59
+ if (normalized.min_value === undefined && normalized.minValue !== undefined) {
60
+ normalized.min_value = normalized.minValue;
61
+ }
62
+ if (normalized.max_value === undefined && normalized.maxValue !== undefined) {
63
+ normalized.max_value = normalized.maxValue;
64
+ }
65
+ if (normalized.channel_types === undefined && normalized.channelTypes !== undefined) {
66
+ normalized.channel_types = normalized.channelTypes;
67
+ }
68
+
69
+ const nameLocs = (0, CommandBuilder_js_1.normalizeNameLocalizations)(
70
+ normalized.name_localizations ?? normalized.nameLocalizations
71
+ );
72
+ if (nameLocs) {
73
+ normalized.name_localizations = nameLocs;
74
+ } else {
75
+ delete normalized.name_localizations;
76
+ }
77
+
78
+ const descLocs = (0, CommandBuilder_js_1.normalizeDescriptionLocalizations)(
79
+ normalized.description_localizations ?? normalized.descriptionLocalizations
80
+ );
81
+ if (descLocs) {
82
+ normalized.description_localizations = descLocs;
83
+ } else {
84
+ delete normalized.description_localizations;
85
+ }
86
+
87
+ delete normalized.minLength;
88
+ delete normalized.maxLength;
89
+ delete normalized.minValue;
90
+ delete normalized.maxValue;
91
+ delete normalized.channelTypes;
92
+ delete normalized.nameLocalizations;
93
+ delete normalized.descriptionLocalizations;
94
+
95
+ if (normalized.choices !== undefined) {
96
+ normalized.choices = normalizeChoices(normalized.choices);
97
+ }
98
+
99
+ return normalized;
100
+ }
101
+
102
+ addString(param) {
103
+ this.params.push(this.#normalizeParam(param, discord_js_1.ApplicationCommandOptionType.String));
104
+ return this;
105
+ }
106
+
107
+ addNumber(param) {
108
+ this.params.push(this.#normalizeParam(param, discord_js_1.ApplicationCommandOptionType.Number));
109
+ return this;
110
+ }
111
+
112
+ addInteger(param) {
113
+ this.params.push(this.#normalizeParam(param, discord_js_1.ApplicationCommandOptionType.Integer));
114
+ return this;
115
+ }
116
+
117
+ addBoolean(param) {
118
+ this.params.push(this.#normalizeParam(param, discord_js_1.ApplicationCommandOptionType.Boolean));
119
+ return this;
120
+ }
121
+
122
+ addMember(param) {
123
+ this.params.push(this.#normalizeParam(param, discord_js_1.ApplicationCommandOptionType.User));
124
+ return this;
125
+ }
126
+
127
+ addUser(param) {
128
+ return this.addMember(param);
129
+ }
130
+
131
+ addChannel(param) {
132
+ this.params.push(this.#normalizeParam(param, discord_js_1.ApplicationCommandOptionType.Channel));
133
+ return this;
134
+ }
135
+
136
+ addRole(param) {
137
+ this.params.push(this.#normalizeParam(param, discord_js_1.ApplicationCommandOptionType.Role));
138
+ return this;
139
+ }
140
+
141
+ addAttachment(param) {
142
+ this.params.push(this.#normalizeParam(param, discord_js_1.ApplicationCommandOptionType.Attachment));
143
+ return this;
144
+ }
145
+
146
+ addMentionable(param) {
147
+ this.params.push(this.#normalizeParam(param, discord_js_1.ApplicationCommandOptionType.Mentionable));
148
+ return this;
149
+ }
150
+
151
+ /**
152
+ * Serializes options cleanly for Discord ApplicationCommand registration,
153
+ * omitting prefix-only runtime fields such as `ellipsis` and `value`.
154
+ */
155
+ toJSON() {
156
+ return this.params.map((param) => {
157
+ const json = {};
158
+ for (const [key, val] of Object.entries(param)) {
159
+ if (INTERNAL_RUNTIME_KEYS.has(key) || val === undefined) continue;
160
+ json[key] = val;
161
+ }
162
+ return json;
163
+ });
164
+ }
165
+ }
166
+
167
+ exports.ParamsBuilder = ParamsBuilder;