spacecommands 3.4.1 → 3.4.5
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 +34 -9
- package/dist/SlashCommands.js +3 -3
- package/package.json +1 -1
package/dist/CommandHandler.js
CHANGED
|
@@ -44,7 +44,14 @@ class CommandHandler {
|
|
|
44
44
|
_commandChecks = new Map();
|
|
45
45
|
constructor(instance, client, dir, disabledDefaultCommands, typeScript = false) {
|
|
46
46
|
this._client = client;
|
|
47
|
-
|
|
47
|
+
if (client.isReady()) {
|
|
48
|
+
this.setUp(instance, client, dir, disabledDefaultCommands, typeScript);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
client.once('ready', () => {
|
|
52
|
+
this.setUp(instance, client, dir, disabledDefaultCommands, typeScript);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
48
55
|
}
|
|
49
56
|
async setUp(instance, client, dir, disabledDefaultCommands, typeScript = false) {
|
|
50
57
|
// Do not pass in TS here because this should always compiled to JS
|
|
@@ -160,6 +167,24 @@ class CommandHandler {
|
|
|
160
167
|
}
|
|
161
168
|
const { name = fileName, category, commands, aliases, init, callback, run, execute, error, description, requiredPermissions, permissions, slash, expectedArgs, expectedArgsTypes, minArgs, options = [], autocomplete, } = configuration;
|
|
162
169
|
const { testOnly } = configuration;
|
|
170
|
+
// Extract options from SlashCommandBuilder if using data property
|
|
171
|
+
// This allows commands to use SlashCommandBuilder pattern while still working with SpaceCommands
|
|
172
|
+
let finalOptions = options;
|
|
173
|
+
if (configuration.data && typeof configuration.data.toJSON === 'function') {
|
|
174
|
+
const jsonData = configuration.data.toJSON();
|
|
175
|
+
if (jsonData.options) {
|
|
176
|
+
finalOptions = jsonData.options;
|
|
177
|
+
}
|
|
178
|
+
if (instance.debug && finalOptions && finalOptions.length) {
|
|
179
|
+
console.log(`SpaceCommands > Command "${name || fileName}" using SlashCommandBuilder with ${finalOptions.length} options`);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
else if (configuration.data && configuration.data.options) {
|
|
183
|
+
finalOptions = configuration.data.options;
|
|
184
|
+
if (instance.debug) {
|
|
185
|
+
console.log(`SpaceCommands > Command "${name || fileName}" using SlashCommandBuilder with ${finalOptions.length} options`);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
163
188
|
if (run || execute) {
|
|
164
189
|
throw new Error(`Command located at "${file}" has either a "run" or "execute" function. Please rename that function to "callback".`);
|
|
165
190
|
}
|
|
@@ -201,7 +226,7 @@ class CommandHandler {
|
|
|
201
226
|
if (slash !== undefined && typeof slash !== 'boolean' && slash !== 'both') {
|
|
202
227
|
throw new Error(`SpaceCommands > Command "${names[0]}" has a "slash" property that is not boolean "true" or string "both".`);
|
|
203
228
|
}
|
|
204
|
-
if (!slash &&
|
|
229
|
+
if (!slash && finalOptions.length) {
|
|
205
230
|
throw new Error(`SpaceCommands > Command "${names[0]}" has an "options" property but is not a slash command.`);
|
|
206
231
|
}
|
|
207
232
|
if (slash && !(builtIn && !instance.isDBConnected())) {
|
|
@@ -211,9 +236,9 @@ class CommandHandler {
|
|
|
211
236
|
if (minArgs !== undefined && !expectedArgs) {
|
|
212
237
|
throw new Error(`SpaceCommands > Command "${names[0]}" has "minArgs" property defined without "expectedArgs" property as a slash command.`);
|
|
213
238
|
}
|
|
214
|
-
if (
|
|
215
|
-
for (const key in
|
|
216
|
-
const name =
|
|
239
|
+
if (finalOptions.length) {
|
|
240
|
+
for (const key in finalOptions) {
|
|
241
|
+
const name = finalOptions[key].name;
|
|
217
242
|
let lowerCase = name.toLowerCase();
|
|
218
243
|
if (name !== lowerCase && instance.showWarns) {
|
|
219
244
|
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 +247,7 @@ class CommandHandler {
|
|
|
222
247
|
lowerCase = lowerCase.replace(/\s/g, '_');
|
|
223
248
|
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
249
|
}
|
|
225
|
-
|
|
250
|
+
finalOptions[key].name = lowerCase;
|
|
226
251
|
}
|
|
227
252
|
}
|
|
228
253
|
else if (expectedArgs) {
|
|
@@ -231,7 +256,7 @@ class CommandHandler {
|
|
|
231
256
|
.split(/[>\]] [<\[]/);
|
|
232
257
|
for (let a = 0; a < split.length; ++a) {
|
|
233
258
|
const item = split[a];
|
|
234
|
-
|
|
259
|
+
finalOptions.push({
|
|
235
260
|
name: item.replace(/ /g, '-').toLowerCase(),
|
|
236
261
|
description: item,
|
|
237
262
|
type: expectedArgsTypes && expectedArgsTypes.length >= a
|
|
@@ -244,11 +269,11 @@ class CommandHandler {
|
|
|
244
269
|
const slashCommands = instance.slashCommands;
|
|
245
270
|
if (testOnly) {
|
|
246
271
|
for (const id of instance.testServers) {
|
|
247
|
-
await slashCommands.create(names[0], description,
|
|
272
|
+
await slashCommands.create(names[0], description, finalOptions, id);
|
|
248
273
|
}
|
|
249
274
|
}
|
|
250
275
|
else {
|
|
251
|
-
await slashCommands.create(names[0], description,
|
|
276
|
+
await slashCommands.create(names[0], description, finalOptions);
|
|
252
277
|
}
|
|
253
278
|
if (autocomplete) {
|
|
254
279
|
const slashCommands = instance.slashCommands;
|
package/dist/SlashCommands.js
CHANGED
|
@@ -109,9 +109,9 @@ class SlashCommands {
|
|
|
109
109
|
}
|
|
110
110
|
didOptionsChange(command, options) {
|
|
111
111
|
return (command.options?.filter((opt, index) => {
|
|
112
|
-
return (opt?.required !== options[index]?.required
|
|
113
|
-
opt?.name !== options[index]?.name
|
|
114
|
-
opt?.options
|
|
112
|
+
return (opt?.required !== options[index]?.required ||
|
|
113
|
+
opt?.name !== options[index]?.name ||
|
|
114
|
+
(opt?.options && opt.options.length !== options[index]?.options?.length));
|
|
115
115
|
}).length !== 0);
|
|
116
116
|
}
|
|
117
117
|
async create(name, description, options, guildId) {
|