commandkit 0.1.3 → 0.1.4-dev.20231003142112
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/README.md +17 -10
- package/dist/index.d.mts +87 -28
- package/dist/index.d.ts +87 -28
- package/dist/index.js +531 -295
- package/dist/index.mjs +537 -294
- package/package.json +47 -47
package/dist/index.js
CHANGED
|
@@ -31,7 +31,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var src_exports = {};
|
|
32
32
|
__export(src_exports, {
|
|
33
33
|
CommandKit: () => CommandKit,
|
|
34
|
-
CommandType: () => CommandType
|
|
34
|
+
CommandType: () => CommandType,
|
|
35
|
+
ReloadType: () => ReloadType
|
|
35
36
|
});
|
|
36
37
|
module.exports = __toCommonJS(src_exports);
|
|
37
38
|
|
|
@@ -75,7 +76,288 @@ function getFolderPaths(directory, nesting) {
|
|
|
75
76
|
var import_path2 = __toESM(require("path"));
|
|
76
77
|
function toFileURL(filePath) {
|
|
77
78
|
const resolvedPath = import_path2.default.resolve(filePath);
|
|
78
|
-
return "file://" + resolvedPath.replace(
|
|
79
|
+
return "file://" + resolvedPath.replace(/\\\\|\\/g, "/");
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// src/utils/colors.ts
|
|
83
|
+
var resetColor = "\x1B[0m";
|
|
84
|
+
var colors_default = {
|
|
85
|
+
reset: (text) => `${text}${resetColor}`,
|
|
86
|
+
bright: (text) => `\x1B[1m${text}${resetColor}`,
|
|
87
|
+
dim: (text) => `\x1B[2m${text}${resetColor}`,
|
|
88
|
+
underscore: (text) => `\x1B[4m${text}${resetColor}`,
|
|
89
|
+
blink: (text) => `\x1B[5m${text}${resetColor}`,
|
|
90
|
+
reverse: (text) => `\x1B[7m${text}${resetColor}`,
|
|
91
|
+
hidden: (text) => `\x1B[8m${text}${resetColor}`,
|
|
92
|
+
black: (text) => `\x1B[30m${text}${resetColor}`,
|
|
93
|
+
red: (text) => `\x1B[31m${text}${resetColor}`,
|
|
94
|
+
green: (text) => `\x1B[32m${text}${resetColor}`,
|
|
95
|
+
yellow: (text) => `\x1B[33m${text}${resetColor}`,
|
|
96
|
+
blue: (text) => `\x1B[34m${text}${resetColor}`,
|
|
97
|
+
magenta: (text) => `\x1B[35m${text}${resetColor}`,
|
|
98
|
+
cyan: (text) => `\x1B[36m${text}${resetColor}`,
|
|
99
|
+
white: (text) => `\x1B[37m${text}${resetColor}`,
|
|
100
|
+
bgBlack: (text) => `\x1B[40m${text}${resetColor}`,
|
|
101
|
+
bgRed: (text) => `\x1B[41m${text}${resetColor}`,
|
|
102
|
+
bgGreen: (text) => `\x1B[42m${text}${resetColor}`,
|
|
103
|
+
bgYellow: (text) => `\x1B[43m${text}${resetColor}`,
|
|
104
|
+
bgBlue: (text) => `\x1B[44m${text}${resetColor}`,
|
|
105
|
+
bgMagenta: (text) => `\x1B[45m${text}${resetColor}`,
|
|
106
|
+
bgCyan: (text) => `\x1B[46m${text}${resetColor}`,
|
|
107
|
+
bgWhite: (text) => `\x1B[47m${text}${resetColor}`
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
// src/handlers/command-handler/functions/loadCommandsWithRest.ts
|
|
111
|
+
async function loadCommandsWithRest(props) {
|
|
112
|
+
if (props.reloading) {
|
|
113
|
+
if (props.client.isReady()) {
|
|
114
|
+
await handleLoading(
|
|
115
|
+
props.client,
|
|
116
|
+
props.commands,
|
|
117
|
+
props.devGuildIds,
|
|
118
|
+
props.reloading,
|
|
119
|
+
props.type
|
|
120
|
+
);
|
|
121
|
+
} else {
|
|
122
|
+
throw new Error(colors_default.red(`\u274C Cannot reload commands when client is not ready.`));
|
|
123
|
+
}
|
|
124
|
+
} else {
|
|
125
|
+
props.client.once("ready", async (c) => {
|
|
126
|
+
await handleLoading(c, props.commands, props.devGuildIds, props.reloading, props.type);
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
async function handleLoading(client, commands, devGuildIds, reloading, type) {
|
|
131
|
+
const devOnlyCommands = commands.filter((cmd) => cmd.options?.devOnly);
|
|
132
|
+
const globalCommands = commands.filter((cmd) => !cmd.options?.devOnly);
|
|
133
|
+
if (type === "dev") {
|
|
134
|
+
await loadDevCommands(client, devOnlyCommands, devGuildIds, reloading);
|
|
135
|
+
} else if (type === "global") {
|
|
136
|
+
await loadGlobalCommands(client, globalCommands, reloading);
|
|
137
|
+
} else {
|
|
138
|
+
await loadDevCommands(client, devOnlyCommands, devGuildIds, reloading);
|
|
139
|
+
await loadGlobalCommands(client, globalCommands, reloading);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
async function loadGlobalCommands(client, commands, reloading) {
|
|
143
|
+
const requestBody = commands.map((cmd) => cmd.data);
|
|
144
|
+
await client.application.commands.set(requestBody).catch((error) => {
|
|
145
|
+
console.log(
|
|
146
|
+
colors_default.red(
|
|
147
|
+
`\u274C Error ${reloading ? "reloading" : "loading"} global application commands.
|
|
148
|
+
`
|
|
149
|
+
)
|
|
150
|
+
);
|
|
151
|
+
throw new Error(error);
|
|
152
|
+
});
|
|
153
|
+
console.log(
|
|
154
|
+
colors_default.green(
|
|
155
|
+
`\u2705 ${reloading ? "Reloaded" : "Loaded"} ${requestBody.length} global commands.`
|
|
156
|
+
)
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
async function loadDevCommands(client, commands, guildIds, reloading) {
|
|
160
|
+
const requestBody = commands.map((cmd) => cmd.data);
|
|
161
|
+
for (const guildId of guildIds) {
|
|
162
|
+
const targetGuild = client.guilds.cache.get(guildId) || await client.guilds.fetch(guildId);
|
|
163
|
+
if (!targetGuild) {
|
|
164
|
+
console.log(
|
|
165
|
+
`Couldn't ${reloading ? "reloading" : "loading"} commands in guild "${targetGuild}" - guild doesn't exist or client isn't part of the guild.`
|
|
166
|
+
);
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
await targetGuild.commands.set(requestBody).catch((error) => {
|
|
170
|
+
console.log(
|
|
171
|
+
colors_default.red(
|
|
172
|
+
`\u274C Error ${reloading ? "reloading" : "loading"} developer application commands in guild "${targetGuild?.name || guildId}".
|
|
173
|
+
`
|
|
174
|
+
)
|
|
175
|
+
);
|
|
176
|
+
throw new Error(error);
|
|
177
|
+
});
|
|
178
|
+
console.log(
|
|
179
|
+
colors_default.green(
|
|
180
|
+
`\u2705 ${reloading ? "Reloaded" : "Loaded"} ${requestBody.length} developer commands in guild "${targetGuild.name}".`
|
|
181
|
+
)
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// src/handlers/command-handler/utils/areSlashCommandsDifferent.ts
|
|
187
|
+
function areSlashCommandsDifferent(appCommand, localCommand) {
|
|
188
|
+
if (!appCommand.options)
|
|
189
|
+
appCommand.options = [];
|
|
190
|
+
if (!localCommand.options)
|
|
191
|
+
localCommand.options = [];
|
|
192
|
+
if (!appCommand.description)
|
|
193
|
+
appCommand.description = "";
|
|
194
|
+
if (!localCommand.description)
|
|
195
|
+
localCommand.description = "";
|
|
196
|
+
if (localCommand.description !== appCommand.description || localCommand.options.length !== appCommand.options.length) {
|
|
197
|
+
return true;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// src/handlers/command-handler/functions/registerCommands.ts
|
|
202
|
+
async function registerCommands(props) {
|
|
203
|
+
if (props.reloading) {
|
|
204
|
+
if (props.client.isReady()) {
|
|
205
|
+
await handleRegistration(props.client, props.commands, props.devGuildIds, props.type);
|
|
206
|
+
} else {
|
|
207
|
+
throw new Error(colors_default.red(`\u274C Cannot reload commands when client is not ready.`));
|
|
208
|
+
}
|
|
209
|
+
} else {
|
|
210
|
+
props.client.once("ready", async (c) => {
|
|
211
|
+
await handleRegistration(c, props.commands, props.devGuildIds, props.type);
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
async function handleRegistration(client, commands, devGuildIds, type) {
|
|
216
|
+
const devOnlyCommands = commands.filter((cmd) => cmd.options?.devOnly);
|
|
217
|
+
const globalCommands = commands.filter((cmd) => !cmd.options?.devOnly);
|
|
218
|
+
if (type === "dev") {
|
|
219
|
+
await registerDevCommands(client, devOnlyCommands, devGuildIds);
|
|
220
|
+
} else if (type === "global") {
|
|
221
|
+
await registerGlobalCommands(client, globalCommands);
|
|
222
|
+
} else {
|
|
223
|
+
await registerDevCommands(client, devOnlyCommands, devGuildIds);
|
|
224
|
+
await registerGlobalCommands(client, globalCommands);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
async function registerGlobalCommands(client, commands) {
|
|
228
|
+
const appCommandsManager = client.application.commands;
|
|
229
|
+
await appCommandsManager.fetch();
|
|
230
|
+
for (const command of commands) {
|
|
231
|
+
const targetCommand = appCommandsManager.cache.find(
|
|
232
|
+
(cmd) => cmd.name === command.data.name
|
|
233
|
+
);
|
|
234
|
+
if (command.options?.deleted) {
|
|
235
|
+
if (!targetCommand) {
|
|
236
|
+
console.log(
|
|
237
|
+
colors_default.yellow(
|
|
238
|
+
`\u23E9 Ignoring: Command "${command.data.name}" is globally marked as deleted.`
|
|
239
|
+
)
|
|
240
|
+
);
|
|
241
|
+
} else {
|
|
242
|
+
await targetCommand.delete().catch((error) => {
|
|
243
|
+
console.log(
|
|
244
|
+
colors_default.red(`\u274C Failed to delete command "${command.data.name}" globally.`)
|
|
245
|
+
);
|
|
246
|
+
console.error(error);
|
|
247
|
+
});
|
|
248
|
+
console.log(colors_default.green(`\u{1F6AE} Deleted command "${command.data.name}" globally.`));
|
|
249
|
+
}
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
if (targetCommand) {
|
|
253
|
+
const commandsAreDifferent = areSlashCommandsDifferent(targetCommand, command.data);
|
|
254
|
+
if (commandsAreDifferent) {
|
|
255
|
+
await targetCommand.edit(command.data).catch((error) => {
|
|
256
|
+
console.log(
|
|
257
|
+
colors_default.red(
|
|
258
|
+
`\u274C Failed to edit command "${command.data.name}" globally.`
|
|
259
|
+
)
|
|
260
|
+
);
|
|
261
|
+
console.error(error);
|
|
262
|
+
});
|
|
263
|
+
console.log(colors_default.green(`\u2705 Edited command "${command.data.name}" globally.`));
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
if (targetCommand)
|
|
268
|
+
continue;
|
|
269
|
+
await appCommandsManager.create(command.data).catch((error) => {
|
|
270
|
+
console.log(
|
|
271
|
+
colors_default.red(`\u274C Failed to register command "${command.data.name}" globally.`)
|
|
272
|
+
);
|
|
273
|
+
console.error(error);
|
|
274
|
+
});
|
|
275
|
+
console.log(colors_default.green(`\u2705 Registered command "${command.data.name}" globally.`));
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
async function registerDevCommands(client, commands, guildIds) {
|
|
279
|
+
const devGuilds = [];
|
|
280
|
+
for (const guildId of guildIds) {
|
|
281
|
+
const guild = client.guilds.cache.get(guildId) || await client.guilds.fetch(guildId);
|
|
282
|
+
if (!guild) {
|
|
283
|
+
console.log(
|
|
284
|
+
colors_default.yellow(
|
|
285
|
+
`\u23E9 Ignoring: Guild ${guildId} does not exist or client isn't in this guild.`
|
|
286
|
+
)
|
|
287
|
+
);
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
devGuilds.push(guild);
|
|
291
|
+
}
|
|
292
|
+
const guildCommandsManagers = [];
|
|
293
|
+
for (const guild of devGuilds) {
|
|
294
|
+
const guildCommandsManager = guild.commands;
|
|
295
|
+
await guildCommandsManager.fetch();
|
|
296
|
+
guildCommandsManagers.push(guildCommandsManager);
|
|
297
|
+
}
|
|
298
|
+
for (const command of commands) {
|
|
299
|
+
for (const guildCommands of guildCommandsManagers) {
|
|
300
|
+
const targetCommand = guildCommands.cache.find((cmd) => cmd.name === command.data.name);
|
|
301
|
+
if (command.options?.deleted) {
|
|
302
|
+
if (!targetCommand) {
|
|
303
|
+
console.log(
|
|
304
|
+
colors_default.yellow(
|
|
305
|
+
`\u23E9 Ignoring: Command "${command.data.name}" is marked as deleted for ${guildCommands.guild.name}.`
|
|
306
|
+
)
|
|
307
|
+
);
|
|
308
|
+
} else {
|
|
309
|
+
await targetCommand.delete().catch((error) => {
|
|
310
|
+
console.log(
|
|
311
|
+
colors_default.red(
|
|
312
|
+
`\u274C Failed to delete command "${command.data.name}" in ${guildCommands.guild.name}.`
|
|
313
|
+
)
|
|
314
|
+
);
|
|
315
|
+
console.error(error);
|
|
316
|
+
});
|
|
317
|
+
console.log(
|
|
318
|
+
colors_default.green(
|
|
319
|
+
`\u{1F6AE} Deleted command "${command.data.name}" in ${guildCommands.guild.name}.`
|
|
320
|
+
)
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
continue;
|
|
324
|
+
}
|
|
325
|
+
if (targetCommand) {
|
|
326
|
+
const commandsAreDifferent = areSlashCommandsDifferent(targetCommand, command.data);
|
|
327
|
+
if (commandsAreDifferent) {
|
|
328
|
+
await targetCommand.edit(command.data).catch((error) => {
|
|
329
|
+
console.log(
|
|
330
|
+
colors_default.red(
|
|
331
|
+
`\u274C Failed to edit command "${command.data.name}" in ${guildCommands.guild.name}.`
|
|
332
|
+
)
|
|
333
|
+
);
|
|
334
|
+
console.error(error);
|
|
335
|
+
});
|
|
336
|
+
console.log(
|
|
337
|
+
colors_default.green(
|
|
338
|
+
`\u2705 Edited command "${command.data.name}" in ${guildCommands.guild.name}.`
|
|
339
|
+
)
|
|
340
|
+
);
|
|
341
|
+
continue;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
if (targetCommand)
|
|
345
|
+
continue;
|
|
346
|
+
await guildCommands.create(command.data).catch((error) => {
|
|
347
|
+
console.log(
|
|
348
|
+
colors_default.red(
|
|
349
|
+
`\u274C Failed to register command "${command.data.name}" in ${guildCommands.guild.name}.`
|
|
350
|
+
)
|
|
351
|
+
);
|
|
352
|
+
console.error(error);
|
|
353
|
+
});
|
|
354
|
+
console.log(
|
|
355
|
+
colors_default.green(
|
|
356
|
+
`\u2705 Registered command "${command.data.name}" in ${guildCommands.guild.name}.`
|
|
357
|
+
)
|
|
358
|
+
);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
79
361
|
}
|
|
80
362
|
|
|
81
363
|
// src/handlers/command-handler/validations/botPermissions.ts
|
|
@@ -119,7 +401,7 @@ function devOnly_default({ interaction, targetCommand, handlerData }) {
|
|
|
119
401
|
const memberRoles = guildMember?.roles.cache;
|
|
120
402
|
let hasDevRole = false;
|
|
121
403
|
memberRoles?.forEach((role) => {
|
|
122
|
-
if (handlerData.devRoleIds
|
|
404
|
+
if (handlerData.devRoleIds.includes(role.id)) {
|
|
123
405
|
hasDevRole = true;
|
|
124
406
|
}
|
|
125
407
|
});
|
|
@@ -175,254 +457,13 @@ function userPermissions_default({ interaction, targetCommand }) {
|
|
|
175
457
|
// src/handlers/command-handler/validations/index.ts
|
|
176
458
|
var validations_default = [botPermissions_default, devOnly_default, guildOnly_default, userPermissions_default];
|
|
177
459
|
|
|
178
|
-
// src/handlers/command-handler/utils/areSlashCommandsDifferent.ts
|
|
179
|
-
function areSlashCommandsDifferent(appCommand, localCommand) {
|
|
180
|
-
if (!appCommand.options)
|
|
181
|
-
appCommand.options = [];
|
|
182
|
-
if (!localCommand.options)
|
|
183
|
-
localCommand.options = [];
|
|
184
|
-
if (!appCommand.description)
|
|
185
|
-
appCommand.description = "";
|
|
186
|
-
if (!localCommand.description)
|
|
187
|
-
localCommand.description = "";
|
|
188
|
-
if (localCommand.description !== appCommand.description || localCommand.options.length !== appCommand.options.length) {
|
|
189
|
-
return true;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
// src/handlers/command-handler/functions/registerCommands.ts
|
|
194
|
-
var import_safe = __toESM(require("colors/safe"));
|
|
195
|
-
async function registerCommands(commandHandler) {
|
|
196
|
-
const client = commandHandler._data.client;
|
|
197
|
-
const devGuildIds = commandHandler._data.devGuildIds;
|
|
198
|
-
const commands = commandHandler._data.commands;
|
|
199
|
-
client.once("ready", async () => {
|
|
200
|
-
const devGuilds = [];
|
|
201
|
-
for (const devGuildId of devGuildIds) {
|
|
202
|
-
const guild = client.guilds.cache.get(devGuildId);
|
|
203
|
-
if (!guild) {
|
|
204
|
-
console.log(
|
|
205
|
-
import_safe.default.yellow(
|
|
206
|
-
`\u23E9 Ignoring: Guild ${devGuildId} does not exist or client isn't in this guild.`
|
|
207
|
-
)
|
|
208
|
-
);
|
|
209
|
-
continue;
|
|
210
|
-
}
|
|
211
|
-
devGuilds.push(guild);
|
|
212
|
-
}
|
|
213
|
-
const appCommands = client.application?.commands;
|
|
214
|
-
await appCommands?.fetch();
|
|
215
|
-
const devGuildCommands = [];
|
|
216
|
-
for (const guild of devGuilds) {
|
|
217
|
-
const guildCommands = guild.commands;
|
|
218
|
-
await guildCommands?.fetch();
|
|
219
|
-
devGuildCommands.push(guildCommands);
|
|
220
|
-
}
|
|
221
|
-
for (const command of commands) {
|
|
222
|
-
let commandData = command.data;
|
|
223
|
-
if (command.options?.deleted) {
|
|
224
|
-
const targetCommand = appCommands?.cache.find(
|
|
225
|
-
(cmd) => cmd.name === commandData.name
|
|
226
|
-
);
|
|
227
|
-
if (!targetCommand) {
|
|
228
|
-
console.log(
|
|
229
|
-
import_safe.default.yellow(
|
|
230
|
-
`\u23E9 Ignoring: Command "${commandData.name}" is globally marked as deleted.`
|
|
231
|
-
)
|
|
232
|
-
);
|
|
233
|
-
} else {
|
|
234
|
-
targetCommand.delete().then(() => {
|
|
235
|
-
console.log(
|
|
236
|
-
import_safe.default.green(`\u{1F6AE} Deleted command "${commandData.name}" globally.`)
|
|
237
|
-
);
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
for (const guildCommands of devGuildCommands) {
|
|
241
|
-
const targetCommand2 = guildCommands.cache.find(
|
|
242
|
-
(cmd) => cmd.name === commandData.name
|
|
243
|
-
);
|
|
244
|
-
if (!targetCommand2) {
|
|
245
|
-
console.log(
|
|
246
|
-
import_safe.default.yellow(
|
|
247
|
-
`\u23E9 Ignoring: Command "${commandData.name}" is marked as deleted for ${guildCommands.guild.name}.`
|
|
248
|
-
)
|
|
249
|
-
);
|
|
250
|
-
} else {
|
|
251
|
-
targetCommand2.delete().then(() => {
|
|
252
|
-
console.log(
|
|
253
|
-
import_safe.default.green(
|
|
254
|
-
`\u{1F6AE} Deleted command "${commandData.name}" in ${guildCommands.guild.name}.`
|
|
255
|
-
)
|
|
256
|
-
);
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
continue;
|
|
261
|
-
}
|
|
262
|
-
let editedCommand = false;
|
|
263
|
-
const appGlobalCommand = appCommands?.cache.find(
|
|
264
|
-
(cmd) => cmd.name === commandData.name
|
|
265
|
-
);
|
|
266
|
-
if (appGlobalCommand) {
|
|
267
|
-
const commandsAreDifferent = areSlashCommandsDifferent(
|
|
268
|
-
appGlobalCommand,
|
|
269
|
-
commandData
|
|
270
|
-
);
|
|
271
|
-
if (commandsAreDifferent) {
|
|
272
|
-
appGlobalCommand.edit(commandData).then(() => {
|
|
273
|
-
console.log(
|
|
274
|
-
import_safe.default.green(`\u2705 Edited command "${commandData.name}" globally.`)
|
|
275
|
-
);
|
|
276
|
-
}).catch((error) => {
|
|
277
|
-
console.log(
|
|
278
|
-
import_safe.default.red(
|
|
279
|
-
`\u274C Failed to edit command "${commandData.name}" globally.`
|
|
280
|
-
)
|
|
281
|
-
);
|
|
282
|
-
console.error(error);
|
|
283
|
-
});
|
|
284
|
-
editedCommand = true;
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
for (const guildCommands of devGuildCommands) {
|
|
288
|
-
const appGuildCommand = guildCommands.cache.find(
|
|
289
|
-
(cmd) => cmd.name === commandData.name
|
|
290
|
-
);
|
|
291
|
-
if (appGuildCommand) {
|
|
292
|
-
const commandsAreDifferent = areSlashCommandsDifferent(
|
|
293
|
-
appGuildCommand,
|
|
294
|
-
commandData
|
|
295
|
-
);
|
|
296
|
-
if (commandsAreDifferent) {
|
|
297
|
-
appGuildCommand.edit(commandData).then(() => {
|
|
298
|
-
console.log(
|
|
299
|
-
import_safe.default.green(
|
|
300
|
-
`\u2705 Edited command "${commandData.name}" in ${guildCommands.guild.name}.`
|
|
301
|
-
)
|
|
302
|
-
);
|
|
303
|
-
}).catch((error) => {
|
|
304
|
-
console.log(
|
|
305
|
-
import_safe.default.red(
|
|
306
|
-
`\u274C Failed to edit command "${commandData.name}" in ${guildCommands.guild.name}.`
|
|
307
|
-
)
|
|
308
|
-
);
|
|
309
|
-
console.error(error);
|
|
310
|
-
});
|
|
311
|
-
editedCommand = true;
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
if (editedCommand)
|
|
316
|
-
continue;
|
|
317
|
-
if (command.options?.devOnly) {
|
|
318
|
-
if (!devGuilds.length) {
|
|
319
|
-
console.log(
|
|
320
|
-
import_safe.default.yellow(
|
|
321
|
-
`\u23E9 Ignoring: Cannot register command "${commandData.name}" as no valid "devGuildIds" were provided.`
|
|
322
|
-
)
|
|
323
|
-
);
|
|
324
|
-
continue;
|
|
325
|
-
}
|
|
326
|
-
for (const guild of devGuilds) {
|
|
327
|
-
const cmdExists = guild.commands.cache.some(
|
|
328
|
-
(cmd) => cmd.name === commandData.name
|
|
329
|
-
);
|
|
330
|
-
if (cmdExists)
|
|
331
|
-
continue;
|
|
332
|
-
guild?.commands.create(commandData).then(() => {
|
|
333
|
-
console.log(
|
|
334
|
-
import_safe.default.green(
|
|
335
|
-
`\u2705 Registered command "${commandData.name}" in ${guild.name}.`
|
|
336
|
-
)
|
|
337
|
-
);
|
|
338
|
-
}).catch((error) => {
|
|
339
|
-
console.log(
|
|
340
|
-
import_safe.default.red(
|
|
341
|
-
`\u274C Failed to register command "${commandData.name}" in ${guild.name}.`
|
|
342
|
-
)
|
|
343
|
-
);
|
|
344
|
-
console.error(error);
|
|
345
|
-
});
|
|
346
|
-
}
|
|
347
|
-
} else {
|
|
348
|
-
const cmdExists = appCommands?.cache.some((cmd) => cmd.name === commandData.name);
|
|
349
|
-
if (cmdExists)
|
|
350
|
-
continue;
|
|
351
|
-
appCommands?.create(commandData).then(() => {
|
|
352
|
-
console.log(
|
|
353
|
-
import_safe.default.green(`\u2705 Registered command "${commandData.name}" globally.`)
|
|
354
|
-
);
|
|
355
|
-
}).catch((error) => {
|
|
356
|
-
console.log(
|
|
357
|
-
import_safe.default.red(
|
|
358
|
-
`\u274C Failed to register command "${commandData.name}" globally.`
|
|
359
|
-
)
|
|
360
|
-
);
|
|
361
|
-
console.error(error);
|
|
362
|
-
});
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
});
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
// src/handlers/command-handler/functions/handleCommands.ts
|
|
369
|
-
function handleCommands(commandHandler) {
|
|
370
|
-
const client = commandHandler._data.client;
|
|
371
|
-
const handler = commandHandler._data.commandKitInstance;
|
|
372
|
-
client.on("interactionCreate", async (interaction) => {
|
|
373
|
-
if (!interaction.isChatInputCommand() && !interaction.isContextMenuCommand())
|
|
374
|
-
return;
|
|
375
|
-
const targetCommand = commandHandler._data.commands.find(
|
|
376
|
-
(cmd) => cmd.data.name === interaction.commandName
|
|
377
|
-
);
|
|
378
|
-
if (!targetCommand)
|
|
379
|
-
return;
|
|
380
|
-
const { data, options, run, ...rest } = targetCommand;
|
|
381
|
-
const commandObj = {
|
|
382
|
-
data: targetCommand.data,
|
|
383
|
-
options: targetCommand.options,
|
|
384
|
-
...rest
|
|
385
|
-
};
|
|
386
|
-
let canRun = true;
|
|
387
|
-
for (const validationFunction of commandHandler._data.customValidations) {
|
|
388
|
-
const stopValidationLoop = await validationFunction({
|
|
389
|
-
interaction,
|
|
390
|
-
client,
|
|
391
|
-
commandObj,
|
|
392
|
-
handler
|
|
393
|
-
});
|
|
394
|
-
if (stopValidationLoop) {
|
|
395
|
-
canRun = false;
|
|
396
|
-
break;
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
if (!canRun)
|
|
400
|
-
return;
|
|
401
|
-
if (!commandHandler._data.skipBuiltInValidations) {
|
|
402
|
-
for (const validation of commandHandler._data.builtInValidations) {
|
|
403
|
-
const stopValidationLoop = validation({
|
|
404
|
-
targetCommand,
|
|
405
|
-
interaction,
|
|
406
|
-
handlerData: commandHandler._data
|
|
407
|
-
});
|
|
408
|
-
if (stopValidationLoop) {
|
|
409
|
-
canRun = false;
|
|
410
|
-
break;
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
if (!canRun)
|
|
415
|
-
return;
|
|
416
|
-
targetCommand.run({ interaction, client, handler });
|
|
417
|
-
});
|
|
418
|
-
}
|
|
419
|
-
|
|
420
460
|
// src/handlers/command-handler/CommandHandler.ts
|
|
421
|
-
var
|
|
461
|
+
var import_rfdc = __toESM(require("rfdc"));
|
|
462
|
+
var clone = (0, import_rfdc.default)();
|
|
422
463
|
var CommandHandler = class {
|
|
423
|
-
|
|
464
|
+
#data;
|
|
424
465
|
constructor({ ...options }) {
|
|
425
|
-
this
|
|
466
|
+
this.#data = {
|
|
426
467
|
...options,
|
|
427
468
|
builtInValidations: [],
|
|
428
469
|
commands: []
|
|
@@ -431,54 +472,184 @@ var CommandHandler = class {
|
|
|
431
472
|
async init() {
|
|
432
473
|
await this.#buildCommands();
|
|
433
474
|
this.#buildValidations();
|
|
434
|
-
|
|
435
|
-
this.#
|
|
475
|
+
const devOnlyCommands = this.#data.commands.filter((cmd) => cmd.options?.devOnly);
|
|
476
|
+
if (devOnlyCommands.length && !this.#data.devGuildIds.length) {
|
|
477
|
+
console.log(
|
|
478
|
+
colors_default.yellow(
|
|
479
|
+
'\u2139\uFE0F Warning: You have commands marked as "devOnly" but "devGuildIds" has not been set.'
|
|
480
|
+
)
|
|
481
|
+
);
|
|
482
|
+
}
|
|
483
|
+
if (devOnlyCommands.length && !this.#data.devUserIds.length && !this.#data.devRoleIds.length) {
|
|
484
|
+
console.log(
|
|
485
|
+
colors_default.yellow(
|
|
486
|
+
'\u2139\uFE0F Warning: You have commands marked as "devOnly" but not "devUserIds" or "devRoleIds" were set.'
|
|
487
|
+
)
|
|
488
|
+
);
|
|
489
|
+
}
|
|
490
|
+
if (this.#data.bulkRegister) {
|
|
491
|
+
await loadCommandsWithRest({
|
|
492
|
+
client: this.#data.client,
|
|
493
|
+
devGuildIds: this.#data.devGuildIds,
|
|
494
|
+
commands: this.#data.commands
|
|
495
|
+
});
|
|
496
|
+
} else {
|
|
497
|
+
await registerCommands({
|
|
498
|
+
client: this.#data.client,
|
|
499
|
+
devGuildIds: this.#data.devGuildIds,
|
|
500
|
+
commands: this.#data.commands
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
this.handleCommands();
|
|
436
504
|
}
|
|
437
505
|
async #buildCommands() {
|
|
438
|
-
const
|
|
439
|
-
|
|
506
|
+
const allowedExtensions = /\.(js|mjs|cjs|ts)$/i;
|
|
507
|
+
const commandFilePaths = getFilePaths(this.#data.commandsPath, true).filter(
|
|
508
|
+
(path3) => allowedExtensions.test(path3)
|
|
440
509
|
);
|
|
441
510
|
for (const commandFilePath of commandFilePaths) {
|
|
442
511
|
const modulePath = toFileURL(commandFilePath);
|
|
443
|
-
let
|
|
512
|
+
let importedObj = await import(`${modulePath}?t=${Date.now()}`);
|
|
513
|
+
let commandObj = clone(importedObj);
|
|
514
|
+
if (typeof module !== "undefined" && typeof require !== "undefined") {
|
|
515
|
+
delete require.cache[require.resolve(commandFilePath)];
|
|
516
|
+
}
|
|
444
517
|
const compactFilePath = commandFilePath.split(process.cwd())[1] || commandFilePath;
|
|
445
518
|
if (commandObj.default)
|
|
446
519
|
commandObj = commandObj.default;
|
|
447
520
|
if (!commandObj.data) {
|
|
448
521
|
console.log(
|
|
449
|
-
|
|
522
|
+
colors_default.yellow(
|
|
450
523
|
`\u23E9 Ignoring: Command ${compactFilePath} does not export "data".`
|
|
451
524
|
)
|
|
452
525
|
);
|
|
453
526
|
continue;
|
|
454
527
|
}
|
|
528
|
+
if (!commandObj.data.name) {
|
|
529
|
+
console.log(
|
|
530
|
+
colors_default.yellow(
|
|
531
|
+
`\u23E9 Ignoring: Command ${compactFilePath} does not export "data.name".`
|
|
532
|
+
)
|
|
533
|
+
);
|
|
534
|
+
continue;
|
|
535
|
+
}
|
|
455
536
|
if (!commandObj.run) {
|
|
456
537
|
console.log(
|
|
457
|
-
|
|
538
|
+
colors_default.yellow(
|
|
539
|
+
`\u23E9 Ignoring: Command ${commandObj.data.name} does not export "run".`
|
|
540
|
+
)
|
|
458
541
|
);
|
|
459
542
|
continue;
|
|
460
543
|
}
|
|
461
|
-
|
|
544
|
+
if (typeof commandObj.run !== "function") {
|
|
545
|
+
console.log(
|
|
546
|
+
colors_default.yellow(
|
|
547
|
+
`\u23E9 Ignoring: Command ${commandObj.data.name} does not export "run" as a function.`
|
|
548
|
+
)
|
|
549
|
+
);
|
|
550
|
+
continue;
|
|
551
|
+
}
|
|
552
|
+
commandObj.filePath = commandFilePath;
|
|
553
|
+
let commandCategory = commandFilePath.split(this.#data.commandsPath)[1]?.replace(/\\\\|\\/g, "/").split("/")[1] || null;
|
|
554
|
+
if (commandCategory && allowedExtensions.test(commandCategory)) {
|
|
555
|
+
commandObj.category = null;
|
|
556
|
+
} else {
|
|
557
|
+
commandObj.category = commandCategory;
|
|
558
|
+
}
|
|
559
|
+
this.#data.commands.push(commandObj);
|
|
462
560
|
}
|
|
463
561
|
}
|
|
464
562
|
#buildValidations() {
|
|
465
563
|
for (const validationFunction of validations_default) {
|
|
466
|
-
this.
|
|
564
|
+
this.#data.builtInValidations.push(validationFunction);
|
|
467
565
|
}
|
|
468
566
|
}
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
567
|
+
handleCommands() {
|
|
568
|
+
this.#data.client.on("interactionCreate", async (interaction) => {
|
|
569
|
+
if (!interaction.isChatInputCommand() && !interaction.isContextMenuCommand())
|
|
570
|
+
return;
|
|
571
|
+
const targetCommand = this.#data.commands.find(
|
|
572
|
+
(cmd) => cmd.data.name === interaction.commandName
|
|
573
|
+
);
|
|
574
|
+
if (!targetCommand)
|
|
575
|
+
return;
|
|
576
|
+
const { data, options, run, ...rest } = targetCommand;
|
|
577
|
+
const commandObj = {
|
|
578
|
+
data: targetCommand.data,
|
|
579
|
+
options: targetCommand.options,
|
|
580
|
+
...rest
|
|
581
|
+
};
|
|
582
|
+
if (this.#data.validationHandler) {
|
|
583
|
+
let canRun2 = true;
|
|
584
|
+
for (const validationFunction of this.#data.validationHandler.validations) {
|
|
585
|
+
const stopValidationLoop = await validationFunction({
|
|
586
|
+
interaction,
|
|
587
|
+
commandObj,
|
|
588
|
+
client: this.#data.client,
|
|
589
|
+
handler: this.#data.commandkitInstance
|
|
590
|
+
});
|
|
591
|
+
if (stopValidationLoop) {
|
|
592
|
+
canRun2 = false;
|
|
593
|
+
break;
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
if (!canRun2)
|
|
597
|
+
return;
|
|
598
|
+
}
|
|
599
|
+
let canRun = true;
|
|
600
|
+
if (!this.#data.skipBuiltInValidations) {
|
|
601
|
+
for (const validation of this.#data.builtInValidations) {
|
|
602
|
+
const stopValidationLoop = validation({
|
|
603
|
+
targetCommand,
|
|
604
|
+
interaction,
|
|
605
|
+
handlerData: this.#data
|
|
606
|
+
});
|
|
607
|
+
if (stopValidationLoop) {
|
|
608
|
+
canRun = false;
|
|
609
|
+
break;
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
if (!canRun)
|
|
614
|
+
return;
|
|
615
|
+
targetCommand.run({
|
|
616
|
+
interaction,
|
|
617
|
+
client: this.#data.client,
|
|
618
|
+
handler: this.#data.commandkitInstance
|
|
619
|
+
});
|
|
620
|
+
});
|
|
474
621
|
}
|
|
475
622
|
get commands() {
|
|
476
|
-
return this.
|
|
623
|
+
return this.#data.commands;
|
|
624
|
+
}
|
|
625
|
+
async reloadCommands(type) {
|
|
626
|
+
this.#data.commands = [];
|
|
627
|
+
await this.#buildCommands();
|
|
628
|
+
if (this.#data.bulkRegister) {
|
|
629
|
+
await loadCommandsWithRest({
|
|
630
|
+
client: this.#data.client,
|
|
631
|
+
devGuildIds: this.#data.devGuildIds,
|
|
632
|
+
commands: this.#data.commands,
|
|
633
|
+
reloading: true,
|
|
634
|
+
type
|
|
635
|
+
});
|
|
636
|
+
} else {
|
|
637
|
+
await registerCommands({
|
|
638
|
+
client: this.#data.client,
|
|
639
|
+
devGuildIds: this.#data.devGuildIds,
|
|
640
|
+
commands: this.#data.commands,
|
|
641
|
+
reloading: true,
|
|
642
|
+
type
|
|
643
|
+
});
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
async useUpdatedValidations() {
|
|
477
647
|
}
|
|
478
648
|
};
|
|
479
649
|
|
|
480
650
|
// src/handlers/event-handler/EventHandler.ts
|
|
481
|
-
var
|
|
651
|
+
var import_rfdc2 = __toESM(require("rfdc"));
|
|
652
|
+
var clone2 = (0, import_rfdc2.default)();
|
|
482
653
|
var EventHandler = class {
|
|
483
654
|
#data;
|
|
484
655
|
constructor({ ...options }) {
|
|
@@ -494,9 +665,10 @@ var EventHandler = class {
|
|
|
494
665
|
async #buildEvents() {
|
|
495
666
|
const eventFolderPaths = getFolderPaths(this.#data.eventsPath);
|
|
496
667
|
for (const eventFolderPath of eventFolderPaths) {
|
|
497
|
-
const eventName = eventFolderPath.replace(
|
|
668
|
+
const eventName = eventFolderPath.replace(/\\\\|\\/g, "/").split("/").pop();
|
|
669
|
+
const allowedExtensions = /\.(js|mjs|cjs|ts)$/i;
|
|
498
670
|
const eventFilePaths = getFilePaths(eventFolderPath, true).filter(
|
|
499
|
-
(path3) =>
|
|
671
|
+
(path3) => allowedExtensions.test(path3)
|
|
500
672
|
);
|
|
501
673
|
const eventObj = {
|
|
502
674
|
name: eventName,
|
|
@@ -505,14 +677,18 @@ var EventHandler = class {
|
|
|
505
677
|
this.#data.events.push(eventObj);
|
|
506
678
|
for (const eventFilePath of eventFilePaths) {
|
|
507
679
|
const modulePath = toFileURL(eventFilePath);
|
|
508
|
-
let
|
|
680
|
+
let importedFunction = (await import(`${modulePath}?t=${Date.now()}`)).default;
|
|
681
|
+
let eventFunction = clone2(importedFunction);
|
|
682
|
+
if (typeof module !== "undefined" && typeof require !== "undefined") {
|
|
683
|
+
delete require.cache[require.resolve(eventFilePath)];
|
|
684
|
+
}
|
|
509
685
|
if (eventFunction?.default) {
|
|
510
686
|
eventFunction = eventFunction.default;
|
|
511
687
|
}
|
|
512
688
|
const compactFilePath = eventFilePath.split(process.cwd())[1] || eventFilePath;
|
|
513
689
|
if (typeof eventFunction !== "function") {
|
|
514
690
|
console.log(
|
|
515
|
-
|
|
691
|
+
colors_default.yellow(
|
|
516
692
|
`\u23E9 Ignoring: Event ${compactFilePath} does not export a function.`
|
|
517
693
|
)
|
|
518
694
|
);
|
|
@@ -539,10 +715,18 @@ var EventHandler = class {
|
|
|
539
715
|
get events() {
|
|
540
716
|
return this.#data.events;
|
|
541
717
|
}
|
|
718
|
+
async reloadEvents(commandHandler) {
|
|
719
|
+
this.#data.events = [];
|
|
720
|
+
await this.#buildEvents();
|
|
721
|
+
this.#data.client.removeAllListeners();
|
|
722
|
+
this.#registerEvents();
|
|
723
|
+
commandHandler?.handleCommands();
|
|
724
|
+
}
|
|
542
725
|
};
|
|
543
726
|
|
|
544
727
|
// src/handlers/validation-handler/ValidationHandler.ts
|
|
545
|
-
var
|
|
728
|
+
var import_rfdc3 = __toESM(require("rfdc"));
|
|
729
|
+
var clone3 = (0, import_rfdc3.default)();
|
|
546
730
|
var ValidationHandler = class {
|
|
547
731
|
#data;
|
|
548
732
|
constructor({ ...options }) {
|
|
@@ -555,19 +739,24 @@ var ValidationHandler = class {
|
|
|
555
739
|
await this.#buildValidations();
|
|
556
740
|
}
|
|
557
741
|
async #buildValidations() {
|
|
742
|
+
const allowedExtensions = /\.(js|mjs|cjs|ts)$/i;
|
|
558
743
|
const validationFilePaths = getFilePaths(this.#data.validationsPath, true).filter(
|
|
559
|
-
(path3) =>
|
|
744
|
+
(path3) => allowedExtensions.test(path3)
|
|
560
745
|
);
|
|
561
746
|
for (const validationFilePath of validationFilePaths) {
|
|
562
747
|
const modulePath = toFileURL(validationFilePath);
|
|
563
|
-
let
|
|
748
|
+
let importedFunction = (await import(`${modulePath}?t=${Date.now()}`)).default;
|
|
749
|
+
let validationFunction = clone3(importedFunction);
|
|
750
|
+
if (typeof module !== "undefined" && typeof require !== "undefined") {
|
|
751
|
+
delete require.cache[require.resolve(validationFilePath)];
|
|
752
|
+
}
|
|
564
753
|
if (validationFunction?.default) {
|
|
565
754
|
validationFunction = validationFunction.default;
|
|
566
755
|
}
|
|
567
756
|
const compactFilePath = validationFilePath.split(process.cwd())[1] || validationFilePath;
|
|
568
757
|
if (typeof validationFunction !== "function") {
|
|
569
758
|
console.log(
|
|
570
|
-
|
|
759
|
+
colors_default.yellow(
|
|
571
760
|
`\u23E9 Ignoring: Validation ${compactFilePath} does not export a function.`
|
|
572
761
|
)
|
|
573
762
|
);
|
|
@@ -579,25 +768,25 @@ var ValidationHandler = class {
|
|
|
579
768
|
get validations() {
|
|
580
769
|
return this.#data.validations;
|
|
581
770
|
}
|
|
771
|
+
async reloadValidations() {
|
|
772
|
+
this.#data.validations = [];
|
|
773
|
+
await this.#buildValidations();
|
|
774
|
+
}
|
|
582
775
|
};
|
|
583
776
|
|
|
584
777
|
// src/CommandKit.ts
|
|
585
|
-
var import_safe5 = __toESM(require("colors/safe"));
|
|
586
778
|
var CommandKit = class {
|
|
587
779
|
#data;
|
|
588
|
-
constructor(
|
|
780
|
+
constructor(options) {
|
|
589
781
|
if (!options.client) {
|
|
590
|
-
throw new Error(
|
|
782
|
+
throw new Error(colors_default.red('"client" is required when instantiating CommandKit.'));
|
|
591
783
|
}
|
|
592
784
|
if (options.validationsPath && !options.commandsPath) {
|
|
593
785
|
throw new Error(
|
|
594
|
-
|
|
786
|
+
colors_default.red('"commandsPath" is required when "validationsPath" is set.')
|
|
595
787
|
);
|
|
596
788
|
}
|
|
597
|
-
this.#data =
|
|
598
|
-
...options,
|
|
599
|
-
commands: []
|
|
600
|
-
};
|
|
789
|
+
this.#data = options;
|
|
601
790
|
this.#init();
|
|
602
791
|
}
|
|
603
792
|
async #init() {
|
|
@@ -608,14 +797,13 @@ var CommandKit = class {
|
|
|
608
797
|
commandKitInstance: this
|
|
609
798
|
});
|
|
610
799
|
await eventHandler.init();
|
|
800
|
+
this.#data.eventHandler = eventHandler;
|
|
611
801
|
}
|
|
612
|
-
let validationFunctions = [];
|
|
613
802
|
if (this.#data.validationsPath) {
|
|
614
803
|
const validationHandler = new ValidationHandler({
|
|
615
804
|
validationsPath: this.#data.validationsPath
|
|
616
805
|
});
|
|
617
|
-
|
|
618
|
-
validationHandler.validations.forEach((v) => validationFunctions.push(v));
|
|
806
|
+
this.#data.validationHandler = validationHandler;
|
|
619
807
|
}
|
|
620
808
|
if (this.#data.commandsPath) {
|
|
621
809
|
const commandHandler = new CommandHandler({
|
|
@@ -624,43 +812,85 @@ var CommandKit = class {
|
|
|
624
812
|
devGuildIds: this.#data.devGuildIds || [],
|
|
625
813
|
devUserIds: this.#data.devUserIds || [],
|
|
626
814
|
devRoleIds: this.#data.devRoleIds || [],
|
|
627
|
-
|
|
815
|
+
validationHandler: this.#data.validationHandler,
|
|
628
816
|
skipBuiltInValidations: this.#data.skipBuiltInValidations || false,
|
|
629
|
-
|
|
817
|
+
commandkitInstance: this,
|
|
818
|
+
bulkRegister: this.#data.bulkRegister || false
|
|
630
819
|
});
|
|
631
820
|
await commandHandler.init();
|
|
632
|
-
this.#data.
|
|
821
|
+
this.#data.commandHandler = commandHandler;
|
|
633
822
|
}
|
|
634
823
|
}
|
|
635
|
-
/**
|
|
824
|
+
/**
|
|
825
|
+
* Updates application commands with the latest from "commandsPath".
|
|
826
|
+
*/
|
|
827
|
+
async reloadCommands(type) {
|
|
828
|
+
if (!this.#data.commandHandler)
|
|
829
|
+
return;
|
|
830
|
+
await this.#data.commandHandler.reloadCommands(type);
|
|
831
|
+
}
|
|
832
|
+
/**
|
|
833
|
+
* Updates application events with the latest from "eventsPath".
|
|
834
|
+
*/
|
|
835
|
+
async reloadEvents() {
|
|
836
|
+
if (!this.#data.eventHandler)
|
|
837
|
+
return;
|
|
838
|
+
await this.#data.eventHandler.reloadEvents(this.#data.commandHandler);
|
|
839
|
+
}
|
|
840
|
+
/**
|
|
841
|
+
* Updates application command validations with the latest from "validationsPath".
|
|
842
|
+
*/
|
|
843
|
+
async reloadValidations() {
|
|
844
|
+
if (!this.#data.validationHandler)
|
|
845
|
+
return;
|
|
846
|
+
await this.#data.validationHandler.reloadValidations();
|
|
847
|
+
}
|
|
848
|
+
/**
|
|
849
|
+
* @returns An array of objects of all the commands that CommandKit is handling.
|
|
850
|
+
*/
|
|
636
851
|
get commands() {
|
|
637
|
-
|
|
852
|
+
if (!this.#data.commandHandler) {
|
|
853
|
+
return [];
|
|
854
|
+
}
|
|
855
|
+
const commands = this.#data.commandHandler.commands.map((cmd) => {
|
|
638
856
|
const { run, ...command } = cmd;
|
|
639
857
|
return command;
|
|
640
858
|
});
|
|
641
859
|
return commands;
|
|
642
860
|
}
|
|
643
|
-
/**
|
|
861
|
+
/**
|
|
862
|
+
* @returns The path to the commands folder which was set when instantiating CommandKit.
|
|
863
|
+
*/
|
|
644
864
|
get commandsPath() {
|
|
645
865
|
return this.#data.commandsPath;
|
|
646
866
|
}
|
|
647
|
-
/**
|
|
867
|
+
/**
|
|
868
|
+
* @returns The path to the events folder which was set when instantiating CommandKit.
|
|
869
|
+
*/
|
|
648
870
|
get eventsPath() {
|
|
649
871
|
return this.#data.eventsPath;
|
|
650
872
|
}
|
|
651
|
-
/**
|
|
873
|
+
/**
|
|
874
|
+
* @returns The path to the validations folder which was set when instantiating CommandKit.
|
|
875
|
+
*/
|
|
652
876
|
get validationsPath() {
|
|
653
877
|
return this.#data.validationsPath;
|
|
654
878
|
}
|
|
655
|
-
/**
|
|
879
|
+
/**
|
|
880
|
+
* @returns An array of all the developer user IDs which was set when instantiating CommandKit.
|
|
881
|
+
*/
|
|
656
882
|
get devUserIds() {
|
|
657
883
|
return this.#data.devUserIds || [];
|
|
658
884
|
}
|
|
659
|
-
/**
|
|
885
|
+
/**
|
|
886
|
+
* @returns An array of all the developer guild IDs which was set when instantiating CommandKit.
|
|
887
|
+
*/
|
|
660
888
|
get devGuildIds() {
|
|
661
889
|
return this.#data.devGuildIds || [];
|
|
662
890
|
}
|
|
663
|
-
/**
|
|
891
|
+
/**
|
|
892
|
+
* @returns An array of all the developer role IDs which was set when instantiating CommandKit.
|
|
893
|
+
*/
|
|
664
894
|
get devRoleIds() {
|
|
665
895
|
return this.#data.devRoleIds || [];
|
|
666
896
|
}
|
|
@@ -673,8 +903,14 @@ var CommandType = /* @__PURE__ */ ((CommandType2) => {
|
|
|
673
903
|
CommandType2[CommandType2["User"] = 2] = "User";
|
|
674
904
|
return CommandType2;
|
|
675
905
|
})(CommandType || {});
|
|
906
|
+
var ReloadType = /* @__PURE__ */ ((ReloadType2) => {
|
|
907
|
+
ReloadType2["Developer"] = "dev";
|
|
908
|
+
ReloadType2["Global"] = "global";
|
|
909
|
+
return ReloadType2;
|
|
910
|
+
})(ReloadType || {});
|
|
676
911
|
// Annotate the CommonJS export names for ESM import in node:
|
|
677
912
|
0 && (module.exports = {
|
|
678
913
|
CommandKit,
|
|
679
|
-
CommandType
|
|
914
|
+
CommandType,
|
|
915
|
+
ReloadType
|
|
680
916
|
});
|