spacecommands 3.4.1 → 3.4.2
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.
- package/dist/CommandHandler.js +17 -8
- package/package.json +1 -1
package/dist/CommandHandler.js
CHANGED
|
@@ -160,6 +160,15 @@ class CommandHandler {
|
|
|
160
160
|
}
|
|
161
161
|
const { name = fileName, category, commands, aliases, init, callback, run, execute, error, description, requiredPermissions, permissions, slash, expectedArgs, expectedArgsTypes, minArgs, options = [], autocomplete, } = configuration;
|
|
162
162
|
const { testOnly } = configuration;
|
|
163
|
+
// Extract options from SlashCommandBuilder if using data property
|
|
164
|
+
// This allows commands to use SlashCommandBuilder pattern while still working with SpaceCommands
|
|
165
|
+
let finalOptions = options;
|
|
166
|
+
if (configuration.data && configuration.data.options) {
|
|
167
|
+
finalOptions = configuration.data.options;
|
|
168
|
+
if (instance.debug) {
|
|
169
|
+
console.log(`SpaceCommands > Command "${name || fileName}" using SlashCommandBuilder with ${finalOptions.length} options`);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
163
172
|
if (run || execute) {
|
|
164
173
|
throw new Error(`Command located at "${file}" has either a "run" or "execute" function. Please rename that function to "callback".`);
|
|
165
174
|
}
|
|
@@ -201,7 +210,7 @@ class CommandHandler {
|
|
|
201
210
|
if (slash !== undefined && typeof slash !== 'boolean' && slash !== 'both') {
|
|
202
211
|
throw new Error(`SpaceCommands > Command "${names[0]}" has a "slash" property that is not boolean "true" or string "both".`);
|
|
203
212
|
}
|
|
204
|
-
if (!slash &&
|
|
213
|
+
if (!slash && finalOptions.length) {
|
|
205
214
|
throw new Error(`SpaceCommands > Command "${names[0]}" has an "options" property but is not a slash command.`);
|
|
206
215
|
}
|
|
207
216
|
if (slash && !(builtIn && !instance.isDBConnected())) {
|
|
@@ -211,9 +220,9 @@ class CommandHandler {
|
|
|
211
220
|
if (minArgs !== undefined && !expectedArgs) {
|
|
212
221
|
throw new Error(`SpaceCommands > Command "${names[0]}" has "minArgs" property defined without "expectedArgs" property as a slash command.`);
|
|
213
222
|
}
|
|
214
|
-
if (
|
|
215
|
-
for (const key in
|
|
216
|
-
const name =
|
|
223
|
+
if (finalOptions.length) {
|
|
224
|
+
for (const key in finalOptions) {
|
|
225
|
+
const name = finalOptions[key].name;
|
|
217
226
|
let lowerCase = name.toLowerCase();
|
|
218
227
|
if (name !== lowerCase && instance.showWarns) {
|
|
219
228
|
console.log(`SpaceCommands > Command "${names[0]}" has an option of "${name}". All option names must be lower case for slash commands. SpaceCommands will modify this for you.`);
|
|
@@ -222,7 +231,7 @@ class CommandHandler {
|
|
|
222
231
|
lowerCase = lowerCase.replace(/\s/g, '_');
|
|
223
232
|
console.log(`SpaceCommands > Command "${names[0]}" has an option of "${name}" with a white space in it. It is a best practice for option names to only be one word. SpaceCommands will modify this for you.`);
|
|
224
233
|
}
|
|
225
|
-
|
|
234
|
+
finalOptions[key].name = lowerCase;
|
|
226
235
|
}
|
|
227
236
|
}
|
|
228
237
|
else if (expectedArgs) {
|
|
@@ -231,7 +240,7 @@ class CommandHandler {
|
|
|
231
240
|
.split(/[>\]] [<\[]/);
|
|
232
241
|
for (let a = 0; a < split.length; ++a) {
|
|
233
242
|
const item = split[a];
|
|
234
|
-
|
|
243
|
+
finalOptions.push({
|
|
235
244
|
name: item.replace(/ /g, '-').toLowerCase(),
|
|
236
245
|
description: item,
|
|
237
246
|
type: expectedArgsTypes && expectedArgsTypes.length >= a
|
|
@@ -244,11 +253,11 @@ class CommandHandler {
|
|
|
244
253
|
const slashCommands = instance.slashCommands;
|
|
245
254
|
if (testOnly) {
|
|
246
255
|
for (const id of instance.testServers) {
|
|
247
|
-
await slashCommands.create(names[0], description,
|
|
256
|
+
await slashCommands.create(names[0], description, finalOptions, id);
|
|
248
257
|
}
|
|
249
258
|
}
|
|
250
259
|
else {
|
|
251
|
-
await slashCommands.create(names[0], description,
|
|
260
|
+
await slashCommands.create(names[0], description, finalOptions);
|
|
252
261
|
}
|
|
253
262
|
if (autocomplete) {
|
|
254
263
|
const slashCommands = instance.slashCommands;
|