reciple 6.0.0-dev.19 → 6.0.0-dev.20

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 (46) hide show
  1. package/LICENSE +674 -674
  2. package/README.md +183 -183
  3. package/dist/lib/bin.mjs +65 -65
  4. package/dist/lib/esm.mjs +1 -1
  5. package/dist/lib/index.js +35 -35
  6. package/dist/lib/reciple/classes/RecipleClient.js +296 -296
  7. package/dist/lib/reciple/classes/RecipleConfig.js +106 -106
  8. package/dist/lib/reciple/classes/RecipleModule.js +94 -94
  9. package/dist/lib/reciple/classes/builders/MessageCommandBuilder.js +242 -242
  10. package/dist/lib/reciple/classes/builders/MessageCommandOptionBuilder.js +85 -85
  11. package/dist/lib/reciple/classes/builders/SlashCommandBuilder.js +216 -216
  12. package/dist/lib/reciple/classes/managers/ApplicationCommandManager.js +178 -172
  13. package/dist/lib/reciple/classes/managers/CommandCooldownManager.js +100 -100
  14. package/dist/lib/reciple/classes/managers/{ClientCommandManager.js → CommandManager.js} +59 -62
  15. package/dist/lib/reciple/classes/managers/MessageCommandOptionManager.js +25 -25
  16. package/dist/lib/reciple/classes/managers/{ClientModuleManager.js → ModuleManager.js} +179 -183
  17. package/dist/lib/reciple/flags.js +31 -31
  18. package/dist/lib/reciple/permissions.js +30 -30
  19. package/dist/lib/reciple/types/builders.js +11 -11
  20. package/dist/lib/reciple/types/commands.js +15 -15
  21. package/dist/lib/reciple/types/paramOptions.js +2 -2
  22. package/dist/lib/reciple/util.js +68 -68
  23. package/dist/lib/reciple/version.js +47 -47
  24. package/dist/types/bin.d.mts +2 -2
  25. package/dist/types/esm.d.mts +1 -1
  26. package/dist/types/index.d.ts +19 -19
  27. package/dist/types/reciple/classes/RecipleClient.d.ts +103 -103
  28. package/dist/types/reciple/classes/RecipleConfig.d.ts +100 -100
  29. package/dist/types/reciple/classes/RecipleModule.d.ts +56 -56
  30. package/dist/types/reciple/classes/builders/MessageCommandBuilder.d.ts +150 -150
  31. package/dist/types/reciple/classes/builders/MessageCommandOptionBuilder.d.ts +43 -43
  32. package/dist/types/reciple/classes/builders/SlashCommandBuilder.d.ts +88 -88
  33. package/dist/types/reciple/classes/managers/ApplicationCommandManager.d.ts +53 -51
  34. package/dist/types/reciple/classes/managers/CommandCooldownManager.d.ts +70 -70
  35. package/dist/types/reciple/classes/managers/{ClientCommandManager.d.ts → CommandManager.d.ts} +36 -37
  36. package/dist/types/reciple/classes/managers/MessageCommandOptionManager.d.ts +22 -22
  37. package/dist/types/reciple/classes/managers/{ClientModuleManager.d.ts → ModuleManager.d.ts} +49 -49
  38. package/dist/types/reciple/flags.d.ts +17 -17
  39. package/dist/types/reciple/permissions.d.ts +19 -19
  40. package/dist/types/reciple/types/builders.d.ts +197 -197
  41. package/dist/types/reciple/types/commands.d.ts +81 -81
  42. package/dist/types/reciple/types/paramOptions.d.ts +101 -101
  43. package/dist/types/reciple/util.d.ts +23 -23
  44. package/dist/types/reciple/version.d.ts +25 -25
  45. package/package.json +1 -1
  46. package/resource/reciple.yml +120 -120
@@ -1,242 +1,242 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateMessageCommandOptions = exports.MessageCommandBuilder = void 0;
4
- const builders_1 = require("../../types/builders");
5
- const discord_js_1 = require("discord.js");
6
- const MessageCommandOptionManager_1 = require("../managers/MessageCommandOptionManager");
7
- const MessageCommandOptionBuilder_1 = require("./MessageCommandOptionBuilder");
8
- /**
9
- * Reciple builder for message command
10
- */
11
- class MessageCommandBuilder {
12
- constructor(data) {
13
- this.type = builders_1.CommandType.MessageCommand;
14
- this.name = '';
15
- this.description = '';
16
- this.cooldown = 0;
17
- this.aliases = [];
18
- this.validateOptions = false;
19
- this.options = [];
20
- this.requiredBotPermissions = [];
21
- this.requiredMemberPermissions = [];
22
- this.allowExecuteInDM = true;
23
- this.allowExecuteByBots = false;
24
- this.execute = () => {
25
- /* Execute */
26
- };
27
- if (data?.name !== undefined)
28
- this.setName(data.name);
29
- if (data?.description !== undefined)
30
- this.setDescription(data.description);
31
- if (data?.aliases !== undefined)
32
- this.addAliases(data.aliases);
33
- if (data?.cooldown !== undefined)
34
- this.setCooldown(Number(data?.cooldown));
35
- if (data?.requiredBotPermissions !== undefined)
36
- this.setRequiredBotPermissions(data.requiredBotPermissions);
37
- if (data?.requiredMemberPermissions !== undefined)
38
- this.setRequiredMemberPermissions(data.requiredMemberPermissions);
39
- if (data?.halt !== undefined)
40
- this.setHalt(data.halt);
41
- if (data?.execute !== undefined)
42
- this.setExecute(data.execute);
43
- if (data?.metadata !== undefined)
44
- this.setMetadata(data.metadata);
45
- if (data?.allowExecuteByBots !== undefined)
46
- this.setAllowExecuteByBots(true);
47
- if (data?.allowExecuteInDM !== undefined)
48
- this.setAllowExecuteInDM(true);
49
- if (data?.validateOptions !== undefined)
50
- this.setValidateOptions(true);
51
- if (data?.options !== undefined)
52
- this.options = data.options.map(o => (o instanceof MessageCommandOptionBuilder_1.MessageCommandOptionBuilder ? o : new MessageCommandOptionBuilder_1.MessageCommandOptionBuilder(o)));
53
- }
54
- /**
55
- * Sets the command name
56
- * @param name Command name
57
- */
58
- setName(name) {
59
- if (!name || typeof name !== 'string' || !name.match(/^[\w-]{1,32}$/))
60
- throw new TypeError('name must be a string and match the regex /^[\\w-]{1,32}$/');
61
- this.name = name;
62
- return this;
63
- }
64
- /**
65
- * Sets the command description
66
- * @param description Command description
67
- */
68
- setDescription(description) {
69
- if (!description || typeof description !== 'string')
70
- throw new TypeError('description must be a string.');
71
- this.description = description;
72
- return this;
73
- }
74
- /**
75
- * Add aliases to the command
76
- * @param aliases Command aliases
77
- */
78
- addAliases(...aliases) {
79
- aliases = (0, discord_js_1.normalizeArray)(aliases);
80
- if (!aliases.length)
81
- throw new TypeError('Provide atleast one alias');
82
- if (aliases.some(a => !a || typeof a !== 'string' || a.match(/^\s+$/)))
83
- throw new TypeError('aliases must be strings and should not contain whitespaces');
84
- if (this.name && aliases.some(a => a == this.name))
85
- throw new TypeError('alias cannot have same name to its real command name');
86
- this.aliases = [...new Set(aliases.map(s => s.toLowerCase()))];
87
- return this;
88
- }
89
- /**
90
- * Set if command can be executed in dms
91
- * @param allowExecuteInDM `true` if the command can execute in DMs
92
- */
93
- setAllowExecuteInDM(allowExecuteInDM) {
94
- if (typeof allowExecuteInDM !== 'boolean')
95
- throw new TypeError('allowExecuteInDM must be a boolean.');
96
- this.allowExecuteInDM = allowExecuteInDM;
97
- return this;
98
- }
99
- /**
100
- * Allow command to be executed by bots
101
- * @param allowExecuteByBots `true` if the command can be executed by bots
102
- */
103
- setAllowExecuteByBots(allowExecuteByBots) {
104
- if (typeof allowExecuteByBots !== 'boolean')
105
- throw new TypeError('allowExecuteByBots must be a boolean.');
106
- this.allowExecuteByBots = allowExecuteByBots;
107
- return this;
108
- }
109
- /**
110
- * Add option to the command
111
- * @param option Message option builder
112
- */
113
- addOption(option) {
114
- if (!option)
115
- throw new TypeError('option must be a MessageOption.');
116
- option = typeof option === 'function' ? option(new MessageCommandOptionBuilder_1.MessageCommandOptionBuilder()) : option;
117
- if (this.options.find(o => o.name === option.name))
118
- throw new TypeError('option with name "' + option.name + '" already exists.');
119
- if (this.options.length > 0 && !this.options[this.options.length - 1 < 0 ? 0 : this.options.length - 1].required && option.required)
120
- throw new TypeError('All required options must be before optional options.');
121
- this.options.push(option);
122
- return this;
123
- }
124
- /**
125
- * Validate options before executing
126
- * @param validateOptions `true` if the command options needs to be validated before executing
127
- */
128
- setValidateOptions(validateOptions) {
129
- if (typeof validateOptions !== 'boolean')
130
- throw new TypeError('validateOptions must be a boolean.');
131
- this.validateOptions = validateOptions;
132
- return this;
133
- }
134
- setCooldown(cooldown) {
135
- this.cooldown = cooldown;
136
- return this;
137
- }
138
- setRequiredBotPermissions(...permissions) {
139
- this.requiredBotPermissions = (0, discord_js_1.normalizeArray)(permissions);
140
- return this;
141
- }
142
- setRequiredMemberPermissions(...permissions) {
143
- this.requiredMemberPermissions = (0, discord_js_1.normalizeArray)(permissions);
144
- return this;
145
- }
146
- setHalt(halt) {
147
- this.halt = halt ?? undefined;
148
- return this;
149
- }
150
- setExecute(execute) {
151
- if (!execute || typeof execute !== 'function')
152
- throw new TypeError('execute must be a function.');
153
- this.execute = execute;
154
- return this;
155
- }
156
- setMetadata(metadata) {
157
- this.metadata = metadata;
158
- return this;
159
- }
160
- /**
161
- * Returns JSON object of this builder
162
- */
163
- toJSON() {
164
- return {
165
- type: this.type,
166
- name: this.name,
167
- description: this.description,
168
- aliases: this.aliases,
169
- cooldown: this.cooldown,
170
- requiredBotPermissions: this.requiredBotPermissions,
171
- requiredMemberPermissions: this.requiredMemberPermissions,
172
- halt: this.halt,
173
- execute: this.execute,
174
- metadata: this.metadata,
175
- allowExecuteByBots: this.allowExecuteByBots,
176
- allowExecuteInDM: this.allowExecuteInDM,
177
- validateOptions: this.validateOptions,
178
- options: this.options.map(o => o.toJSON()),
179
- };
180
- }
181
- /**
182
- * Resolve message command data/builder
183
- * @param commandData Command data to resolve
184
- */
185
- static resolveMessageCommand(commandData) {
186
- return this.isMessageCommandBuilder(commandData) ? commandData : new MessageCommandBuilder(commandData);
187
- }
188
- /**
189
- * Is a message command builder
190
- * @param builder data to check
191
- */
192
- static isMessageCommandBuilder(builder) {
193
- return builder instanceof MessageCommandBuilder;
194
- }
195
- /**
196
- * Is a message command execute data
197
- * @param executeData data to check
198
- */
199
- static isMessageCommandExecuteData(executeData) {
200
- return executeData.builder !== undefined && this.isMessageCommandBuilder(executeData.builder);
201
- }
202
- }
203
- exports.MessageCommandBuilder = MessageCommandBuilder;
204
- /**
205
- * Validate message command options
206
- * @param builder Command builder
207
- * @param options Parsed command args
208
- */
209
- async function validateMessageCommandOptions(builder, options) {
210
- const args = options.args || [];
211
- const required = builder.options.filter(o => o.required);
212
- const optional = builder.options.filter(o => !o.required);
213
- const allOptions = [...required, ...optional];
214
- const result = [];
215
- let i = 0;
216
- for (const option of allOptions) {
217
- const arg = args[i];
218
- const value = {
219
- name: option.name,
220
- value: arg ?? undefined,
221
- required: option.required,
222
- invalid: false,
223
- missing: false,
224
- };
225
- if (arg == undefined && option.required) {
226
- value.missing = true;
227
- result.push(value);
228
- continue;
229
- }
230
- if (arg == undefined && !option.required) {
231
- result.push(value);
232
- continue;
233
- }
234
- const validate = option.validator ? await Promise.resolve(option.validator(arg)) : true;
235
- if (!validate)
236
- value.invalid = true;
237
- result.push(value);
238
- i++;
239
- }
240
- return new MessageCommandOptionManager_1.MessageCommandOptionManager(...result);
241
- }
242
- exports.validateMessageCommandOptions = validateMessageCommandOptions;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateMessageCommandOptions = exports.MessageCommandBuilder = void 0;
4
+ const builders_1 = require("../../types/builders");
5
+ const discord_js_1 = require("discord.js");
6
+ const MessageCommandOptionManager_1 = require("../managers/MessageCommandOptionManager");
7
+ const MessageCommandOptionBuilder_1 = require("./MessageCommandOptionBuilder");
8
+ /**
9
+ * Reciple builder for message command
10
+ */
11
+ class MessageCommandBuilder {
12
+ constructor(data) {
13
+ this.type = builders_1.CommandType.MessageCommand;
14
+ this.name = '';
15
+ this.description = '';
16
+ this.cooldown = 0;
17
+ this.aliases = [];
18
+ this.validateOptions = false;
19
+ this.options = [];
20
+ this.requiredBotPermissions = [];
21
+ this.requiredMemberPermissions = [];
22
+ this.allowExecuteInDM = true;
23
+ this.allowExecuteByBots = false;
24
+ this.execute = () => {
25
+ /* Execute */
26
+ };
27
+ if (data?.name !== undefined)
28
+ this.setName(data.name);
29
+ if (data?.description !== undefined)
30
+ this.setDescription(data.description);
31
+ if (data?.aliases !== undefined)
32
+ this.addAliases(data.aliases);
33
+ if (data?.cooldown !== undefined)
34
+ this.setCooldown(Number(data?.cooldown));
35
+ if (data?.requiredBotPermissions !== undefined)
36
+ this.setRequiredBotPermissions(data.requiredBotPermissions);
37
+ if (data?.requiredMemberPermissions !== undefined)
38
+ this.setRequiredMemberPermissions(data.requiredMemberPermissions);
39
+ if (data?.halt !== undefined)
40
+ this.setHalt(data.halt);
41
+ if (data?.execute !== undefined)
42
+ this.setExecute(data.execute);
43
+ if (data?.metadata !== undefined)
44
+ this.setMetadata(data.metadata);
45
+ if (data?.allowExecuteByBots !== undefined)
46
+ this.setAllowExecuteByBots(true);
47
+ if (data?.allowExecuteInDM !== undefined)
48
+ this.setAllowExecuteInDM(true);
49
+ if (data?.validateOptions !== undefined)
50
+ this.setValidateOptions(true);
51
+ if (data?.options !== undefined)
52
+ this.options = data.options.map(o => (o instanceof MessageCommandOptionBuilder_1.MessageCommandOptionBuilder ? o : new MessageCommandOptionBuilder_1.MessageCommandOptionBuilder(o)));
53
+ }
54
+ /**
55
+ * Sets the command name
56
+ * @param name Command name
57
+ */
58
+ setName(name) {
59
+ if (!name || typeof name !== 'string' || !name.match(/^[\w-]{1,32}$/))
60
+ throw new TypeError('name must be a string and match the regex /^[\\w-]{1,32}$/');
61
+ this.name = name;
62
+ return this;
63
+ }
64
+ /**
65
+ * Sets the command description
66
+ * @param description Command description
67
+ */
68
+ setDescription(description) {
69
+ if (!description || typeof description !== 'string')
70
+ throw new TypeError('description must be a string.');
71
+ this.description = description;
72
+ return this;
73
+ }
74
+ /**
75
+ * Add aliases to the command
76
+ * @param aliases Command aliases
77
+ */
78
+ addAliases(...aliases) {
79
+ aliases = (0, discord_js_1.normalizeArray)(aliases);
80
+ if (!aliases.length)
81
+ throw new TypeError('Provide atleast one alias');
82
+ if (aliases.some(a => !a || typeof a !== 'string' || a.match(/^\s+$/)))
83
+ throw new TypeError('aliases must be strings and should not contain whitespaces');
84
+ if (this.name && aliases.some(a => a == this.name))
85
+ throw new TypeError('alias cannot have same name to its real command name');
86
+ this.aliases = [...new Set(aliases.map(s => s.toLowerCase()))];
87
+ return this;
88
+ }
89
+ /**
90
+ * Set if command can be executed in dms
91
+ * @param allowExecuteInDM `true` if the command can execute in DMs
92
+ */
93
+ setAllowExecuteInDM(allowExecuteInDM) {
94
+ if (typeof allowExecuteInDM !== 'boolean')
95
+ throw new TypeError('allowExecuteInDM must be a boolean.');
96
+ this.allowExecuteInDM = allowExecuteInDM;
97
+ return this;
98
+ }
99
+ /**
100
+ * Allow command to be executed by bots
101
+ * @param allowExecuteByBots `true` if the command can be executed by bots
102
+ */
103
+ setAllowExecuteByBots(allowExecuteByBots) {
104
+ if (typeof allowExecuteByBots !== 'boolean')
105
+ throw new TypeError('allowExecuteByBots must be a boolean.');
106
+ this.allowExecuteByBots = allowExecuteByBots;
107
+ return this;
108
+ }
109
+ /**
110
+ * Add option to the command
111
+ * @param option Message option builder
112
+ */
113
+ addOption(option) {
114
+ if (!option)
115
+ throw new TypeError('option must be a MessageOption.');
116
+ option = typeof option === 'function' ? option(new MessageCommandOptionBuilder_1.MessageCommandOptionBuilder()) : option;
117
+ if (this.options.find(o => o.name === option.name))
118
+ throw new TypeError('option with name "' + option.name + '" already exists.');
119
+ if (this.options.length > 0 && !this.options[this.options.length - 1 < 0 ? 0 : this.options.length - 1].required && option.required)
120
+ throw new TypeError('All required options must be before optional options.');
121
+ this.options.push(option);
122
+ return this;
123
+ }
124
+ /**
125
+ * Validate options before executing
126
+ * @param validateOptions `true` if the command options needs to be validated before executing
127
+ */
128
+ setValidateOptions(validateOptions) {
129
+ if (typeof validateOptions !== 'boolean')
130
+ throw new TypeError('validateOptions must be a boolean.');
131
+ this.validateOptions = validateOptions;
132
+ return this;
133
+ }
134
+ setCooldown(cooldown) {
135
+ this.cooldown = cooldown;
136
+ return this;
137
+ }
138
+ setRequiredBotPermissions(...permissions) {
139
+ this.requiredBotPermissions = (0, discord_js_1.normalizeArray)(permissions);
140
+ return this;
141
+ }
142
+ setRequiredMemberPermissions(...permissions) {
143
+ this.requiredMemberPermissions = (0, discord_js_1.normalizeArray)(permissions);
144
+ return this;
145
+ }
146
+ setHalt(halt) {
147
+ this.halt = halt ?? undefined;
148
+ return this;
149
+ }
150
+ setExecute(execute) {
151
+ if (!execute || typeof execute !== 'function')
152
+ throw new TypeError('execute must be a function.');
153
+ this.execute = execute;
154
+ return this;
155
+ }
156
+ setMetadata(metadata) {
157
+ this.metadata = metadata;
158
+ return this;
159
+ }
160
+ /**
161
+ * Returns JSON object of this builder
162
+ */
163
+ toJSON() {
164
+ return {
165
+ type: this.type,
166
+ name: this.name,
167
+ description: this.description,
168
+ aliases: this.aliases,
169
+ cooldown: this.cooldown,
170
+ requiredBotPermissions: this.requiredBotPermissions,
171
+ requiredMemberPermissions: this.requiredMemberPermissions,
172
+ halt: this.halt,
173
+ execute: this.execute,
174
+ metadata: this.metadata,
175
+ allowExecuteByBots: this.allowExecuteByBots,
176
+ allowExecuteInDM: this.allowExecuteInDM,
177
+ validateOptions: this.validateOptions,
178
+ options: this.options.map(o => o.toJSON()),
179
+ };
180
+ }
181
+ /**
182
+ * Resolve message command data/builder
183
+ * @param commandData Command data to resolve
184
+ */
185
+ static resolveMessageCommand(commandData) {
186
+ return this.isMessageCommandBuilder(commandData) ? commandData : new MessageCommandBuilder(commandData);
187
+ }
188
+ /**
189
+ * Is a message command builder
190
+ * @param builder data to check
191
+ */
192
+ static isMessageCommandBuilder(builder) {
193
+ return builder instanceof MessageCommandBuilder;
194
+ }
195
+ /**
196
+ * Is a message command execute data
197
+ * @param executeData data to check
198
+ */
199
+ static isMessageCommandExecuteData(executeData) {
200
+ return executeData.builder !== undefined && this.isMessageCommandBuilder(executeData.builder);
201
+ }
202
+ }
203
+ exports.MessageCommandBuilder = MessageCommandBuilder;
204
+ /**
205
+ * Validate message command options
206
+ * @param builder Command builder
207
+ * @param options Parsed command args
208
+ */
209
+ async function validateMessageCommandOptions(builder, options) {
210
+ const args = options.args || [];
211
+ const required = builder.options.filter(o => o.required);
212
+ const optional = builder.options.filter(o => !o.required);
213
+ const allOptions = [...required, ...optional];
214
+ const result = [];
215
+ let i = 0;
216
+ for (const option of allOptions) {
217
+ const arg = args[i];
218
+ const value = {
219
+ name: option.name,
220
+ value: arg ?? undefined,
221
+ required: option.required,
222
+ invalid: false,
223
+ missing: false,
224
+ };
225
+ if (arg == undefined && option.required) {
226
+ value.missing = true;
227
+ result.push(value);
228
+ continue;
229
+ }
230
+ if (arg == undefined && !option.required) {
231
+ result.push(value);
232
+ continue;
233
+ }
234
+ const validate = option.validator ? await Promise.resolve(option.validator(arg)) : true;
235
+ if (!validate)
236
+ value.invalid = true;
237
+ result.push(value);
238
+ i++;
239
+ }
240
+ return new MessageCommandOptionManager_1.MessageCommandOptionManager(...result);
241
+ }
242
+ exports.validateMessageCommandOptions = validateMessageCommandOptions;
@@ -1,85 +1,85 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MessageCommandOptionBuilder = void 0;
4
- /**
5
- * Option builder for MessageCommandBuilder
6
- */
7
- class MessageCommandOptionBuilder {
8
- constructor(data) {
9
- this.name = '';
10
- this.description = '';
11
- this.required = false;
12
- this.validator = () => true;
13
- if (data?.name !== undefined)
14
- this.setName(data.name);
15
- if (data?.description !== undefined)
16
- this.setDescription(data.description);
17
- if (data?.required !== undefined)
18
- this.setRequired(data.required);
19
- if (data?.validator !== undefined)
20
- this.setValidator(data.validator);
21
- }
22
- /**
23
- * Set command option name
24
- * @param name Option name
25
- */
26
- setName(name) {
27
- if (typeof name !== 'string' || !name.match(/^[\w-]{1,32}$/))
28
- throw new TypeError('name must be a string and match the regex /^[\\w-]{1,32}$/.');
29
- this.name = name;
30
- return this;
31
- }
32
- /**
33
- * Set command option description
34
- * @param description Option description
35
- */
36
- setDescription(description) {
37
- if (!description || typeof description !== 'string')
38
- throw new TypeError('description must be a string.');
39
- this.description = description;
40
- return this;
41
- }
42
- /**
43
- * Set if this option is required
44
- * @param required `true` if this option is required
45
- */
46
- setRequired(required) {
47
- if (typeof required !== 'boolean')
48
- throw new TypeError('required must be a boolean.');
49
- this.required = required;
50
- return this;
51
- }
52
- /**
53
- * Set your custom function to validate given value for this option
54
- * @param validator Custom function to validate value given for this option
55
- */
56
- setValidator(validator) {
57
- if (!validator || typeof validator !== 'function')
58
- throw new TypeError('validator must be a function.');
59
- this.validator = validator;
60
- return this;
61
- }
62
- toJSON() {
63
- return {
64
- name: this.name,
65
- description: this.description,
66
- required: this.required,
67
- validator: this.validator,
68
- };
69
- }
70
- /**
71
- * Resolves message command option data/builder
72
- * @param option Option data to resolve
73
- */
74
- static resolveMessageCommandOption(option) {
75
- return this.isMessageCommandOption(option) ? option : new MessageCommandOptionBuilder(option);
76
- }
77
- /**
78
- * Is a Message command option builder
79
- * @param builder data to check
80
- */
81
- static isMessageCommandOption(builder) {
82
- return builder instanceof MessageCommandOptionBuilder;
83
- }
84
- }
85
- exports.MessageCommandOptionBuilder = MessageCommandOptionBuilder;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MessageCommandOptionBuilder = void 0;
4
+ /**
5
+ * Option builder for MessageCommandBuilder
6
+ */
7
+ class MessageCommandOptionBuilder {
8
+ constructor(data) {
9
+ this.name = '';
10
+ this.description = '';
11
+ this.required = false;
12
+ this.validator = () => true;
13
+ if (data?.name !== undefined)
14
+ this.setName(data.name);
15
+ if (data?.description !== undefined)
16
+ this.setDescription(data.description);
17
+ if (data?.required !== undefined)
18
+ this.setRequired(data.required);
19
+ if (data?.validator !== undefined)
20
+ this.setValidator(data.validator);
21
+ }
22
+ /**
23
+ * Set command option name
24
+ * @param name Option name
25
+ */
26
+ setName(name) {
27
+ if (typeof name !== 'string' || !name.match(/^[\w-]{1,32}$/))
28
+ throw new TypeError('name must be a string and match the regex /^[\\w-]{1,32}$/.');
29
+ this.name = name;
30
+ return this;
31
+ }
32
+ /**
33
+ * Set command option description
34
+ * @param description Option description
35
+ */
36
+ setDescription(description) {
37
+ if (!description || typeof description !== 'string')
38
+ throw new TypeError('description must be a string.');
39
+ this.description = description;
40
+ return this;
41
+ }
42
+ /**
43
+ * Set if this option is required
44
+ * @param required `true` if this option is required
45
+ */
46
+ setRequired(required) {
47
+ if (typeof required !== 'boolean')
48
+ throw new TypeError('required must be a boolean.');
49
+ this.required = required;
50
+ return this;
51
+ }
52
+ /**
53
+ * Set your custom function to validate given value for this option
54
+ * @param validator Custom function to validate value given for this option
55
+ */
56
+ setValidator(validator) {
57
+ if (!validator || typeof validator !== 'function')
58
+ throw new TypeError('validator must be a function.');
59
+ this.validator = validator;
60
+ return this;
61
+ }
62
+ toJSON() {
63
+ return {
64
+ name: this.name,
65
+ description: this.description,
66
+ required: this.required,
67
+ validator: this.validator,
68
+ };
69
+ }
70
+ /**
71
+ * Resolves message command option data/builder
72
+ * @param option Option data to resolve
73
+ */
74
+ static resolveMessageCommandOption(option) {
75
+ return this.isMessageCommandOption(option) ? option : new MessageCommandOptionBuilder(option);
76
+ }
77
+ /**
78
+ * Is a Message command option builder
79
+ * @param builder data to check
80
+ */
81
+ static isMessageCommandOption(builder) {
82
+ return builder instanceof MessageCommandOptionBuilder;
83
+ }
84
+ }
85
+ exports.MessageCommandOptionBuilder = MessageCommandOptionBuilder;