commandkit 0.1.6-dev.20231112142450 → 0.1.6-dev.20231112181436
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/bin/build.mjs +14 -11
- package/bin/common.mjs +3 -3
- package/bin/dev-server.mjs +21 -19
- package/bin/index.mjs +7 -5
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +56 -52
- package/dist/index.mjs +52 -48
- package/package.json +1 -1
package/bin/build.mjs
CHANGED
|
@@ -5,12 +5,7 @@ import ora from 'ora';
|
|
|
5
5
|
import { Colors, erase, findCommandKitJSON, panic, write } from './common.mjs';
|
|
6
6
|
|
|
7
7
|
export async function bootstrapProductionBuild(config) {
|
|
8
|
-
const {
|
|
9
|
-
minify = false,
|
|
10
|
-
outDir = 'dist',
|
|
11
|
-
main,
|
|
12
|
-
src,
|
|
13
|
-
} = findCommandKitJSON(config);
|
|
8
|
+
const { minify = false, outDir = 'dist', main, src } = findCommandKitJSON(config);
|
|
14
9
|
|
|
15
10
|
const status = ora('Creating optimized production build...\n').start();
|
|
16
11
|
const start = performance.now();
|
|
@@ -26,7 +21,7 @@ export async function bootstrapProductionBuild(config) {
|
|
|
26
21
|
minify,
|
|
27
22
|
shims: true,
|
|
28
23
|
banner: {
|
|
29
|
-
js: '/* Optimized production build of your project, generated by CommandKit */'
|
|
24
|
+
js: '/* Optimized production build of your project, generated by CommandKit */',
|
|
30
25
|
},
|
|
31
26
|
sourcemap: false,
|
|
32
27
|
keepNames: true,
|
|
@@ -35,10 +30,18 @@ export async function bootstrapProductionBuild(config) {
|
|
|
35
30
|
entry: [src, '!dist', '!.commandkit'],
|
|
36
31
|
});
|
|
37
32
|
|
|
38
|
-
status.succeed(
|
|
39
|
-
|
|
33
|
+
status.succeed(
|
|
34
|
+
Colors.green(`Build completed in ${(performance.now() - start).toFixed(2)}ms!`),
|
|
35
|
+
);
|
|
36
|
+
write(
|
|
37
|
+
Colors.green(
|
|
38
|
+
`\nRun ${Colors.magenta(`node ${outDir}/${main}`)} ${Colors.green(
|
|
39
|
+
'to start your bot.',
|
|
40
|
+
)}`,
|
|
41
|
+
),
|
|
42
|
+
);
|
|
40
43
|
} catch (e) {
|
|
41
|
-
status.fail(`Build failed after ${(performance.now() - start).toFixed(2)}ms!`)
|
|
44
|
+
status.fail(`Build failed after ${(performance.now() - start).toFixed(2)}ms!`);
|
|
42
45
|
panic(e);
|
|
43
46
|
}
|
|
44
|
-
}
|
|
47
|
+
}
|
package/bin/common.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
|
-
import { join } from 'node:path'
|
|
3
|
+
import { join } from 'node:path';
|
|
4
4
|
import fs from 'node:fs';
|
|
5
|
-
import { rimrafSync } from 'rimraf'
|
|
5
|
+
import { rimrafSync } from 'rimraf';
|
|
6
6
|
|
|
7
7
|
const resetColor = '\x1b[0m';
|
|
8
8
|
|
|
@@ -71,4 +71,4 @@ export function findCommandKitJSON(src) {
|
|
|
71
71
|
|
|
72
72
|
export function erase(dir) {
|
|
73
73
|
rimrafSync(dir);
|
|
74
|
-
}
|
|
74
|
+
}
|
package/bin/dev-server.mjs
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
// @ts-check
|
|
2
|
-
import { config as dotenv } from 'dotenv'
|
|
2
|
+
import { config as dotenv } from 'dotenv';
|
|
3
3
|
import { build } from 'tsup';
|
|
4
|
-
import child_process from 'node:child_process'
|
|
4
|
+
import child_process from 'node:child_process';
|
|
5
5
|
import ora from 'ora';
|
|
6
6
|
import { join } from 'node:path';
|
|
7
7
|
import { Colors, erase, findCommandKitJSON, panic, write } from './common.mjs';
|
|
8
8
|
|
|
9
9
|
export async function bootstrapDevelopmentServer(config) {
|
|
10
|
-
const {
|
|
11
|
-
src,
|
|
12
|
-
main = 'index.mjs',
|
|
13
|
-
nodeOptions = ['--watch']
|
|
14
|
-
} = findCommandKitJSON(config);
|
|
10
|
+
const { src, main = 'index.mjs', nodeOptions = ['--watch'] } = findCommandKitJSON(config);
|
|
15
11
|
|
|
16
12
|
if (!src) {
|
|
17
13
|
panic('Could not find src in commandkit.json');
|
|
@@ -38,14 +34,16 @@ export async function bootstrapDevelopmentServer(config) {
|
|
|
38
34
|
watch: nodeOptions.includes('--watch'),
|
|
39
35
|
});
|
|
40
36
|
|
|
41
|
-
status.succeed(
|
|
37
|
+
status.succeed(
|
|
38
|
+
Colors.green(`Server started in ${(performance.now() - start).toFixed(2)}ms!\n`),
|
|
39
|
+
);
|
|
42
40
|
|
|
43
41
|
const processEnv = {};
|
|
44
42
|
|
|
45
43
|
const env = dotenv({
|
|
46
44
|
path: join(process.cwd(), '.env'),
|
|
47
45
|
// @ts-expect-error
|
|
48
|
-
processEnv
|
|
46
|
+
processEnv,
|
|
49
47
|
});
|
|
50
48
|
|
|
51
49
|
if (env.error) {
|
|
@@ -56,15 +54,19 @@ export async function bootstrapDevelopmentServer(config) {
|
|
|
56
54
|
write(Colors.blue('[DOTENV] Loaded .env file!'));
|
|
57
55
|
}
|
|
58
56
|
|
|
59
|
-
const ps = child_process.spawn(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
57
|
+
const ps = child_process.spawn(
|
|
58
|
+
'node',
|
|
59
|
+
[...nodeOptions, join(process.cwd(), '.commandkit', main)],
|
|
60
|
+
{
|
|
61
|
+
env: {
|
|
62
|
+
...process.env,
|
|
63
|
+
...processEnv,
|
|
64
|
+
NODE_ENV: 'development',
|
|
65
|
+
COMMANDKIT_DEV: 'true',
|
|
66
|
+
},
|
|
67
|
+
cwd: process.cwd(),
|
|
65
68
|
},
|
|
66
|
-
|
|
67
|
-
});
|
|
69
|
+
);
|
|
68
70
|
|
|
69
71
|
ps.stdout.on('data', (data) => {
|
|
70
72
|
write(data.toString());
|
|
@@ -83,7 +85,7 @@ export async function bootstrapDevelopmentServer(config) {
|
|
|
83
85
|
panic(err);
|
|
84
86
|
});
|
|
85
87
|
} catch (e) {
|
|
86
|
-
status.fail(`Error occurred after ${(performance.now() - start).toFixed(2)}ms!\n`)
|
|
88
|
+
status.fail(`Error occurred after ${(performance.now() - start).toFixed(2)}ms!\n`);
|
|
87
89
|
panic(e);
|
|
88
90
|
}
|
|
89
|
-
}
|
|
91
|
+
}
|
package/bin/index.mjs
CHANGED
|
@@ -8,20 +8,22 @@ import { bootstrapProductionBuild } from './build.mjs';
|
|
|
8
8
|
|
|
9
9
|
const program = new Command('commandkit');
|
|
10
10
|
|
|
11
|
-
program
|
|
11
|
+
program
|
|
12
|
+
.command('dev')
|
|
12
13
|
.description('Start your bot in development mode.')
|
|
13
14
|
.option('-c, --config <path>', 'Path to your commandkit.json file.', './commandkit.json')
|
|
14
15
|
.action(() => {
|
|
15
16
|
const options = program.opts();
|
|
16
|
-
bootstrapDevelopmentServer(options.config)
|
|
17
|
+
bootstrapDevelopmentServer(options.config);
|
|
17
18
|
});
|
|
18
19
|
|
|
19
|
-
program
|
|
20
|
+
program
|
|
21
|
+
.command('build')
|
|
20
22
|
.description('Build your project for production usage.')
|
|
21
23
|
.option('-c, --config <path>', 'Path to your commandkit.json file.', './commandkit.json')
|
|
22
24
|
.action(() => {
|
|
23
25
|
const options = program.opts();
|
|
24
|
-
bootstrapProductionBuild(options.config)
|
|
26
|
+
bootstrapProductionBuild(options.config);
|
|
25
27
|
});
|
|
26
28
|
|
|
27
|
-
program.parse();
|
|
29
|
+
program.parse();
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CommandInteraction, Client, ChatInputCommandInteraction, ContextMenuCommandInteraction,
|
|
1
|
+
import { CommandInteraction, Client, ChatInputCommandInteraction, ContextMenuCommandInteraction, PermissionsString, APIApplicationCommandOption, ButtonInteraction, Awaitable, Message, InteractionCollectorOptions, ButtonBuilder } from 'discord.js';
|
|
2
2
|
|
|
3
3
|
interface CommandProps {
|
|
4
4
|
interaction: CommandInteraction;
|
|
@@ -25,8 +25,8 @@ interface CommandOptions {
|
|
|
25
25
|
guildOnly?: boolean;
|
|
26
26
|
devOnly?: boolean;
|
|
27
27
|
deleted?: boolean;
|
|
28
|
-
userPermissions?:
|
|
29
|
-
botPermissions?:
|
|
28
|
+
userPermissions?: PermissionsString[];
|
|
29
|
+
botPermissions?: PermissionsString[];
|
|
30
30
|
[key: string]: any;
|
|
31
31
|
}
|
|
32
32
|
declare enum CommandType {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CommandInteraction, Client, ChatInputCommandInteraction, ContextMenuCommandInteraction,
|
|
1
|
+
import { CommandInteraction, Client, ChatInputCommandInteraction, ContextMenuCommandInteraction, PermissionsString, APIApplicationCommandOption, ButtonInteraction, Awaitable, Message, InteractionCollectorOptions, ButtonBuilder } from 'discord.js';
|
|
2
2
|
|
|
3
3
|
interface CommandProps {
|
|
4
4
|
interaction: CommandInteraction;
|
|
@@ -25,8 +25,8 @@ interface CommandOptions {
|
|
|
25
25
|
guildOnly?: boolean;
|
|
26
26
|
devOnly?: boolean;
|
|
27
27
|
deleted?: boolean;
|
|
28
|
-
userPermissions?:
|
|
29
|
-
botPermissions?:
|
|
28
|
+
userPermissions?: PermissionsString[];
|
|
29
|
+
botPermissions?: PermissionsString[];
|
|
30
30
|
[key: string]: any;
|
|
31
31
|
}
|
|
32
32
|
declare enum CommandType {
|
package/dist/index.js
CHANGED
|
@@ -364,33 +364,6 @@ async function registerDevCommands(client, commands, guildIds) {
|
|
|
364
364
|
}
|
|
365
365
|
}
|
|
366
366
|
|
|
367
|
-
// src/handlers/command-handler/validations/botPermissions.ts
|
|
368
|
-
function botPermissions_default({ interaction, targetCommand }) {
|
|
369
|
-
const botMember = interaction.guild?.members.me;
|
|
370
|
-
let commandPermissions = targetCommand.options?.botPermissions;
|
|
371
|
-
if (!botMember || !commandPermissions)
|
|
372
|
-
return;
|
|
373
|
-
if (!Array.isArray(commandPermissions)) {
|
|
374
|
-
commandPermissions = [commandPermissions];
|
|
375
|
-
}
|
|
376
|
-
const missingPermissions = [];
|
|
377
|
-
for (const permission of commandPermissions) {
|
|
378
|
-
const hasPermission = botMember.permissions.has(permission);
|
|
379
|
-
if (!hasPermission) {
|
|
380
|
-
missingPermissions.push(`\`${permission.toString()}\``);
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
if (missingPermissions.length) {
|
|
384
|
-
interaction.reply({
|
|
385
|
-
content: `\u274C I do not have enough permissions to execute this command. Missing: ${missingPermissions.join(
|
|
386
|
-
", "
|
|
387
|
-
)}`,
|
|
388
|
-
ephemeral: true
|
|
389
|
-
});
|
|
390
|
-
return true;
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
|
|
394
367
|
// src/handlers/command-handler/validations/devOnly.ts
|
|
395
368
|
function devOnly_default({ interaction, targetCommand, handlerData }) {
|
|
396
369
|
if (targetCommand.options?.devOnly) {
|
|
@@ -431,35 +404,66 @@ function guildOnly_default({ interaction, targetCommand }) {
|
|
|
431
404
|
}
|
|
432
405
|
}
|
|
433
406
|
|
|
434
|
-
// src/handlers/command-handler/validations/
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
407
|
+
// src/handlers/command-handler/validations/permissions.ts
|
|
408
|
+
var import_discord = require("discord.js");
|
|
409
|
+
function permissions_default({ interaction, targetCommand }) {
|
|
410
|
+
const userPermissions = interaction.memberPermissions;
|
|
411
|
+
let userPermissionsRequired = targetCommand.options?.userPermissions;
|
|
412
|
+
let missingUserPermissions = [];
|
|
413
|
+
const botPermissions = interaction.guild?.members.me?.permissions;
|
|
414
|
+
let botPermissionsRequired = targetCommand.options?.botPermissions;
|
|
415
|
+
let missingBotPermissions = [];
|
|
416
|
+
if (!userPermissionsRequired?.length && !botPermissionsRequired?.length) {
|
|
439
417
|
return;
|
|
440
|
-
if (!Array.isArray(commandPermissions)) {
|
|
441
|
-
commandPermissions = [commandPermissions];
|
|
442
418
|
}
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
419
|
+
if (userPermissions && userPermissionsRequired) {
|
|
420
|
+
for (const permission of userPermissionsRequired) {
|
|
421
|
+
const hasPermission = userPermissions.has(permission);
|
|
422
|
+
if (!hasPermission) {
|
|
423
|
+
missingUserPermissions.push(permission);
|
|
424
|
+
}
|
|
448
425
|
}
|
|
449
426
|
}
|
|
450
|
-
if (
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
}
|
|
457
|
-
|
|
427
|
+
if (botPermissions && botPermissionsRequired) {
|
|
428
|
+
for (const permission of botPermissionsRequired) {
|
|
429
|
+
const hasPermission = botPermissions.has(permission);
|
|
430
|
+
if (!hasPermission) {
|
|
431
|
+
missingBotPermissions.push(permission);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
if (!missingUserPermissions.length && !missingBotPermissions.length) {
|
|
436
|
+
return;
|
|
458
437
|
}
|
|
438
|
+
const pattern = /([a-z])([A-Z])|([A-Z]+)([A-Z][a-z])/g;
|
|
439
|
+
missingUserPermissions = missingUserPermissions.map((str) => str.replace(pattern, "$1$3 $2$4"));
|
|
440
|
+
missingBotPermissions = missingBotPermissions.map((str) => str.replace(pattern, "$1$3 $2$4"));
|
|
441
|
+
let embedDescription = "";
|
|
442
|
+
const formatter = new Intl.ListFormat("en", { style: "long", type: "conjunction" });
|
|
443
|
+
const getPermissionWord = (permissions) => permissions.length === 1 ? "permission" : "permissions";
|
|
444
|
+
if (missingUserPermissions.length) {
|
|
445
|
+
const formattedPermissions = missingUserPermissions.map((p) => `\`${p}\``);
|
|
446
|
+
const permissionsString = formatter.format(formattedPermissions);
|
|
447
|
+
embedDescription += `- You must have the ${permissionsString} ${getPermissionWord(
|
|
448
|
+
missingUserPermissions
|
|
449
|
+
)} to be able to run this command.
|
|
450
|
+
`;
|
|
451
|
+
}
|
|
452
|
+
if (missingBotPermissions.length) {
|
|
453
|
+
const formattedPermissions = missingBotPermissions.map((p) => `\`${p}\``);
|
|
454
|
+
const permissionsString = formatter.format(formattedPermissions);
|
|
455
|
+
embedDescription += `- I must have the ${permissionsString} ${getPermissionWord(
|
|
456
|
+
missingBotPermissions
|
|
457
|
+
)} to be able to execute this command.
|
|
458
|
+
`;
|
|
459
|
+
}
|
|
460
|
+
const embed = new import_discord.EmbedBuilder().setTitle(`:x: Missing permissions!`).setDescription(embedDescription).setColor("Red");
|
|
461
|
+
interaction.reply({ embeds: [embed], ephemeral: true });
|
|
462
|
+
return true;
|
|
459
463
|
}
|
|
460
464
|
|
|
461
465
|
// src/handlers/command-handler/validations/index.ts
|
|
462
|
-
var validations_default = [
|
|
466
|
+
var validations_default = [devOnly_default, guildOnly_default, permissions_default];
|
|
463
467
|
|
|
464
468
|
// src/handlers/command-handler/CommandHandler.ts
|
|
465
469
|
var import_rfdc = __toESM(require("rfdc"));
|
|
@@ -904,13 +908,13 @@ var CommandKit = class {
|
|
|
904
908
|
};
|
|
905
909
|
|
|
906
910
|
// src/components/Button.ts
|
|
907
|
-
var
|
|
908
|
-
var ButtonKit = class extends
|
|
911
|
+
var import_discord2 = require("discord.js");
|
|
912
|
+
var ButtonKit = class extends import_discord2.ButtonBuilder {
|
|
909
913
|
#onClickHandler = null;
|
|
910
914
|
#contextData = null;
|
|
911
915
|
#collector = null;
|
|
912
916
|
onClick(handler, data) {
|
|
913
|
-
if (this.data.style ===
|
|
917
|
+
if (this.data.style === import_discord2.ButtonStyle.Link) {
|
|
914
918
|
throw new TypeError('Cannot setup "onClick" handler for link buttons');
|
|
915
919
|
}
|
|
916
920
|
this.#destroyCollector();
|
|
@@ -939,7 +943,7 @@ var ButtonKit = class extends import_discord.ButtonBuilder {
|
|
|
939
943
|
};
|
|
940
944
|
const collector = this.#collector = message.createMessageComponentCollector({
|
|
941
945
|
filter: (interaction) => interaction.customId === this.data.custom_id && interaction.message.id === message.id,
|
|
942
|
-
componentType:
|
|
946
|
+
componentType: import_discord2.ComponentType.Button,
|
|
943
947
|
...data
|
|
944
948
|
});
|
|
945
949
|
this.#collector.on("collect", (interaction) => {
|
package/dist/index.mjs
CHANGED
|
@@ -331,33 +331,6 @@ async function registerDevCommands(client, commands, guildIds) {
|
|
|
331
331
|
}
|
|
332
332
|
}
|
|
333
333
|
|
|
334
|
-
// src/handlers/command-handler/validations/botPermissions.ts
|
|
335
|
-
function botPermissions_default({ interaction, targetCommand }) {
|
|
336
|
-
const botMember = interaction.guild?.members.me;
|
|
337
|
-
let commandPermissions = targetCommand.options?.botPermissions;
|
|
338
|
-
if (!botMember || !commandPermissions)
|
|
339
|
-
return;
|
|
340
|
-
if (!Array.isArray(commandPermissions)) {
|
|
341
|
-
commandPermissions = [commandPermissions];
|
|
342
|
-
}
|
|
343
|
-
const missingPermissions = [];
|
|
344
|
-
for (const permission of commandPermissions) {
|
|
345
|
-
const hasPermission = botMember.permissions.has(permission);
|
|
346
|
-
if (!hasPermission) {
|
|
347
|
-
missingPermissions.push(`\`${permission.toString()}\``);
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
if (missingPermissions.length) {
|
|
351
|
-
interaction.reply({
|
|
352
|
-
content: `\u274C I do not have enough permissions to execute this command. Missing: ${missingPermissions.join(
|
|
353
|
-
", "
|
|
354
|
-
)}`,
|
|
355
|
-
ephemeral: true
|
|
356
|
-
});
|
|
357
|
-
return true;
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
|
|
361
334
|
// src/handlers/command-handler/validations/devOnly.ts
|
|
362
335
|
function devOnly_default({ interaction, targetCommand, handlerData }) {
|
|
363
336
|
if (targetCommand.options?.devOnly) {
|
|
@@ -398,35 +371,66 @@ function guildOnly_default({ interaction, targetCommand }) {
|
|
|
398
371
|
}
|
|
399
372
|
}
|
|
400
373
|
|
|
401
|
-
// src/handlers/command-handler/validations/
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
374
|
+
// src/handlers/command-handler/validations/permissions.ts
|
|
375
|
+
import { EmbedBuilder } from "discord.js";
|
|
376
|
+
function permissions_default({ interaction, targetCommand }) {
|
|
377
|
+
const userPermissions = interaction.memberPermissions;
|
|
378
|
+
let userPermissionsRequired = targetCommand.options?.userPermissions;
|
|
379
|
+
let missingUserPermissions = [];
|
|
380
|
+
const botPermissions = interaction.guild?.members.me?.permissions;
|
|
381
|
+
let botPermissionsRequired = targetCommand.options?.botPermissions;
|
|
382
|
+
let missingBotPermissions = [];
|
|
383
|
+
if (!userPermissionsRequired?.length && !botPermissionsRequired?.length) {
|
|
406
384
|
return;
|
|
407
|
-
if (!Array.isArray(commandPermissions)) {
|
|
408
|
-
commandPermissions = [commandPermissions];
|
|
409
385
|
}
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
386
|
+
if (userPermissions && userPermissionsRequired) {
|
|
387
|
+
for (const permission of userPermissionsRequired) {
|
|
388
|
+
const hasPermission = userPermissions.has(permission);
|
|
389
|
+
if (!hasPermission) {
|
|
390
|
+
missingUserPermissions.push(permission);
|
|
391
|
+
}
|
|
415
392
|
}
|
|
416
393
|
}
|
|
417
|
-
if (
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
}
|
|
424
|
-
|
|
394
|
+
if (botPermissions && botPermissionsRequired) {
|
|
395
|
+
for (const permission of botPermissionsRequired) {
|
|
396
|
+
const hasPermission = botPermissions.has(permission);
|
|
397
|
+
if (!hasPermission) {
|
|
398
|
+
missingBotPermissions.push(permission);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
if (!missingUserPermissions.length && !missingBotPermissions.length) {
|
|
403
|
+
return;
|
|
425
404
|
}
|
|
405
|
+
const pattern = /([a-z])([A-Z])|([A-Z]+)([A-Z][a-z])/g;
|
|
406
|
+
missingUserPermissions = missingUserPermissions.map((str) => str.replace(pattern, "$1$3 $2$4"));
|
|
407
|
+
missingBotPermissions = missingBotPermissions.map((str) => str.replace(pattern, "$1$3 $2$4"));
|
|
408
|
+
let embedDescription = "";
|
|
409
|
+
const formatter = new Intl.ListFormat("en", { style: "long", type: "conjunction" });
|
|
410
|
+
const getPermissionWord = (permissions) => permissions.length === 1 ? "permission" : "permissions";
|
|
411
|
+
if (missingUserPermissions.length) {
|
|
412
|
+
const formattedPermissions = missingUserPermissions.map((p) => `\`${p}\``);
|
|
413
|
+
const permissionsString = formatter.format(formattedPermissions);
|
|
414
|
+
embedDescription += `- You must have the ${permissionsString} ${getPermissionWord(
|
|
415
|
+
missingUserPermissions
|
|
416
|
+
)} to be able to run this command.
|
|
417
|
+
`;
|
|
418
|
+
}
|
|
419
|
+
if (missingBotPermissions.length) {
|
|
420
|
+
const formattedPermissions = missingBotPermissions.map((p) => `\`${p}\``);
|
|
421
|
+
const permissionsString = formatter.format(formattedPermissions);
|
|
422
|
+
embedDescription += `- I must have the ${permissionsString} ${getPermissionWord(
|
|
423
|
+
missingBotPermissions
|
|
424
|
+
)} to be able to execute this command.
|
|
425
|
+
`;
|
|
426
|
+
}
|
|
427
|
+
const embed = new EmbedBuilder().setTitle(`:x: Missing permissions!`).setDescription(embedDescription).setColor("Red");
|
|
428
|
+
interaction.reply({ embeds: [embed], ephemeral: true });
|
|
429
|
+
return true;
|
|
426
430
|
}
|
|
427
431
|
|
|
428
432
|
// src/handlers/command-handler/validations/index.ts
|
|
429
|
-
var validations_default = [
|
|
433
|
+
var validations_default = [devOnly_default, guildOnly_default, permissions_default];
|
|
430
434
|
|
|
431
435
|
// src/handlers/command-handler/CommandHandler.ts
|
|
432
436
|
import rdfc from "rfdc";
|
package/package.json
CHANGED