commandkit 0.0.9 → 0.0.10
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/index.d.mts +51 -0
- package/dist/index.d.ts +51 -1
- package/dist/index.js +552 -15
- package/dist/index.mjs +517 -0
- package/package.json +21 -4
- package/.github/workflows/publish.yaml +0 -26
- package/CHANGELOG.md +0 -52
- package/dist/CommandKit.d.ts +0 -36
- package/dist/CommandKit.js +0 -57
- package/dist/handlers/command-handler/CommandHandler.d.ts +0 -12
- package/dist/handlers/command-handler/CommandHandler.js +0 -62
- package/dist/handlers/command-handler/functions/handleCommands.d.ts +0 -2
- package/dist/handlers/command-handler/functions/handleCommands.js +0 -50
- package/dist/handlers/command-handler/functions/registerCommands.d.ts +0 -2
- package/dist/handlers/command-handler/functions/registerCommands.js +0 -135
- package/dist/handlers/command-handler/utils/areSlashCommandsDifferent.d.ts +0 -1
- package/dist/handlers/command-handler/utils/areSlashCommandsDifferent.js +0 -17
- package/dist/handlers/command-handler/validations/botPermissions.d.ts +0 -1
- package/dist/handlers/command-handler/validations/botPermissions.js +0 -17
- package/dist/handlers/command-handler/validations/devOnly.d.ts +0 -1
- package/dist/handlers/command-handler/validations/devOnly.js +0 -29
- package/dist/handlers/command-handler/validations/guildOnly.d.ts +0 -1
- package/dist/handlers/command-handler/validations/guildOnly.js +0 -11
- package/dist/handlers/command-handler/validations/userPermissions.d.ts +0 -1
- package/dist/handlers/command-handler/validations/userPermissions.js +0 -17
- package/dist/handlers/event-handler/EventHandler.d.ts +0 -11
- package/dist/handlers/event-handler/EventHandler.js +0 -52
- package/dist/handlers/index.d.ts +0 -3
- package/dist/handlers/index.js +0 -19
- package/dist/handlers/validation-handler/ValidationHandler.d.ts +0 -7
- package/dist/handlers/validation-handler/ValidationHandler.js +0 -29
- package/dist/utils/get-paths.d.ts +0 -3
- package/dist/utils/get-paths.js +0 -42
- package/tsconfig.json +0 -14
- package/typings.d.ts +0 -63
package/dist/CommandKit.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CommandKit = void 0;
|
|
4
|
-
const handlers_1 = require("./handlers");
|
|
5
|
-
class CommandKit {
|
|
6
|
-
_data;
|
|
7
|
-
constructor({ ...options }) {
|
|
8
|
-
if (!options.client) {
|
|
9
|
-
throw new Error('"client" is required when instantiating CommandKit.');
|
|
10
|
-
}
|
|
11
|
-
if (options.validationsPath && !options.commandsPath) {
|
|
12
|
-
throw new Error('"commandsPath" is required when "validationsPath" is set.');
|
|
13
|
-
}
|
|
14
|
-
this._data = {
|
|
15
|
-
...options,
|
|
16
|
-
commands: [],
|
|
17
|
-
};
|
|
18
|
-
this._init();
|
|
19
|
-
}
|
|
20
|
-
_init() {
|
|
21
|
-
// Event handler
|
|
22
|
-
if (this._data.eventsPath) {
|
|
23
|
-
new handlers_1.EventHandler({
|
|
24
|
-
client: this._data.client,
|
|
25
|
-
eventsPath: this._data.eventsPath,
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
// Validation handler
|
|
29
|
-
let validationFunctions = [];
|
|
30
|
-
if (this._data.validationsPath) {
|
|
31
|
-
const validationHandler = new handlers_1.ValidationHandler({
|
|
32
|
-
validationsPath: this._data.validationsPath,
|
|
33
|
-
});
|
|
34
|
-
validationHandler.getValidations().forEach((v) => validationFunctions.push(v));
|
|
35
|
-
}
|
|
36
|
-
// Command handler
|
|
37
|
-
if (this._data.commandsPath) {
|
|
38
|
-
const commandHandler = new handlers_1.CommandHandler({
|
|
39
|
-
client: this._data.client,
|
|
40
|
-
commandsPath: this._data.commandsPath,
|
|
41
|
-
devGuildIds: this._data.devGuildIds || [],
|
|
42
|
-
devUserIds: this._data.devUserIds || [],
|
|
43
|
-
devRoleIds: this._data.devRoleIds || [],
|
|
44
|
-
customValidations: validationFunctions,
|
|
45
|
-
skipBuiltInValidations: this._data.skipBuiltInValidations || false,
|
|
46
|
-
});
|
|
47
|
-
this._data.commands = commandHandler.getCommands();
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
get commands() {
|
|
51
|
-
return this._data.commands.map((cmd) => {
|
|
52
|
-
const { run, ...command } = cmd;
|
|
53
|
-
return command;
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
exports.CommandKit = CommandKit;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { CommandHandlerData, CommandHandlerOptions } from './typings';
|
|
2
|
-
import { ContextCommandObject, SlashCommandObject } from '../../../typings';
|
|
3
|
-
export declare class CommandHandler {
|
|
4
|
-
_data: CommandHandlerData;
|
|
5
|
-
constructor({ ...options }: CommandHandlerOptions);
|
|
6
|
-
_init(): void;
|
|
7
|
-
_buildCommands(): void;
|
|
8
|
-
_buildValidations(): void;
|
|
9
|
-
_registerCommands(): void;
|
|
10
|
-
_handleCommands(): void;
|
|
11
|
-
getCommands(): (SlashCommandObject | ContextCommandObject)[];
|
|
12
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.CommandHandler = void 0;
|
|
7
|
-
const get_paths_1 = require("../../utils/get-paths");
|
|
8
|
-
const registerCommands_1 = __importDefault(require("./functions/registerCommands"));
|
|
9
|
-
const handleCommands_1 = __importDefault(require("./functions/handleCommands"));
|
|
10
|
-
const path_1 = __importDefault(require("path"));
|
|
11
|
-
class CommandHandler {
|
|
12
|
-
_data;
|
|
13
|
-
constructor({ ...options }) {
|
|
14
|
-
this._data = {
|
|
15
|
-
...options,
|
|
16
|
-
builtInValidations: [],
|
|
17
|
-
commands: [],
|
|
18
|
-
};
|
|
19
|
-
this._init();
|
|
20
|
-
}
|
|
21
|
-
_init() {
|
|
22
|
-
this._buildCommands();
|
|
23
|
-
this._buildValidations();
|
|
24
|
-
this._registerCommands();
|
|
25
|
-
this._handleCommands();
|
|
26
|
-
}
|
|
27
|
-
_buildCommands() {
|
|
28
|
-
const commandFilePaths = (0, get_paths_1.getFilePaths)(this._data.commandsPath, true).filter((path) => path.endsWith('.js') || path.endsWith('.ts'));
|
|
29
|
-
for (const commandFilePath of commandFilePaths) {
|
|
30
|
-
const commandObj = require(commandFilePath);
|
|
31
|
-
if (!commandObj.data) {
|
|
32
|
-
console.log(`⏩ Ignoring: Command ${commandFilePath} does not export "data".`);
|
|
33
|
-
continue;
|
|
34
|
-
}
|
|
35
|
-
if (!commandObj.run) {
|
|
36
|
-
console.log(`⏩ Ignoring: Command ${commandFilePath} does not export "run".`);
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
this._data.commands.push(commandObj);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
_buildValidations() {
|
|
43
|
-
const validationFilePaths = (0, get_paths_1.getFilePaths)(path_1.default.join(__dirname, 'validations'), true).filter((path) => path.endsWith('.js'));
|
|
44
|
-
for (const validationFilePath of validationFilePaths) {
|
|
45
|
-
const validationFunction = require(validationFilePath);
|
|
46
|
-
if (typeof validationFunction !== 'function') {
|
|
47
|
-
continue;
|
|
48
|
-
}
|
|
49
|
-
this._data.builtInValidations.push(validationFunction);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
_registerCommands() {
|
|
53
|
-
(0, registerCommands_1.default)(this);
|
|
54
|
-
}
|
|
55
|
-
_handleCommands() {
|
|
56
|
-
(0, handleCommands_1.default)(this);
|
|
57
|
-
}
|
|
58
|
-
getCommands() {
|
|
59
|
-
return this._data.commands;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
exports.CommandHandler = CommandHandler;
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
function handleCommands(commandHandler) {
|
|
4
|
-
const client = commandHandler._data.client;
|
|
5
|
-
client.on('interactionCreate', async (interaction) => {
|
|
6
|
-
if (!interaction.isChatInputCommand() && !interaction.isContextMenuCommand())
|
|
7
|
-
return;
|
|
8
|
-
const targetCommand = commandHandler._data.commands.find((cmd) => cmd.data.name === interaction.commandName);
|
|
9
|
-
if (!targetCommand)
|
|
10
|
-
return;
|
|
11
|
-
const { data, options, run, ...rest } = targetCommand;
|
|
12
|
-
const commandObj = {
|
|
13
|
-
data: targetCommand.data,
|
|
14
|
-
options: targetCommand.options,
|
|
15
|
-
...rest,
|
|
16
|
-
};
|
|
17
|
-
let canRun = true;
|
|
18
|
-
for (const validationFunction of commandHandler._data.customValidations) {
|
|
19
|
-
const stopValidationLoop = await validationFunction({
|
|
20
|
-
interaction,
|
|
21
|
-
client,
|
|
22
|
-
commandObj,
|
|
23
|
-
});
|
|
24
|
-
if (stopValidationLoop) {
|
|
25
|
-
canRun = false;
|
|
26
|
-
break;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
if (!canRun)
|
|
30
|
-
return;
|
|
31
|
-
// If custom validations pass and !skipBuiltInValidations, run built-in CommandKit validation functions
|
|
32
|
-
if (!commandHandler._data.skipBuiltInValidations) {
|
|
33
|
-
for (const validation of commandHandler._data.builtInValidations) {
|
|
34
|
-
const stopValidationLoop = validation({
|
|
35
|
-
targetCommand,
|
|
36
|
-
interaction,
|
|
37
|
-
handlerData: commandHandler._data,
|
|
38
|
-
});
|
|
39
|
-
if (stopValidationLoop) {
|
|
40
|
-
canRun = false;
|
|
41
|
-
break;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
if (!canRun)
|
|
46
|
-
return;
|
|
47
|
-
targetCommand.run({ interaction, client });
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
exports.default = handleCommands;
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const areSlashCommandsDifferent_1 = __importDefault(require("../utils/areSlashCommandsDifferent"));
|
|
7
|
-
function registerCommands(commandHandler) {
|
|
8
|
-
const client = commandHandler._data.client;
|
|
9
|
-
const devGuildIds = commandHandler._data.devGuildIds;
|
|
10
|
-
const commands = commandHandler._data.commands;
|
|
11
|
-
client.once('ready', async () => {
|
|
12
|
-
const devGuilds = [];
|
|
13
|
-
for (const devGuildId of devGuildIds) {
|
|
14
|
-
const guild = client.guilds.cache.get(devGuildId);
|
|
15
|
-
if (!guild) {
|
|
16
|
-
console.log(`⏩ Ignoring: Guild ${devGuildId} does not exist or client isn't in this guild.`);
|
|
17
|
-
continue;
|
|
18
|
-
}
|
|
19
|
-
devGuilds.push(guild);
|
|
20
|
-
}
|
|
21
|
-
const appCommands = client.application?.commands;
|
|
22
|
-
await appCommands?.fetch();
|
|
23
|
-
const devGuildCommands = [];
|
|
24
|
-
for (const guild of devGuilds) {
|
|
25
|
-
const guildCommands = guild.commands;
|
|
26
|
-
await guildCommands?.fetch();
|
|
27
|
-
devGuildCommands.push(guildCommands);
|
|
28
|
-
}
|
|
29
|
-
for (const command of commands) {
|
|
30
|
-
// <!-- Delete command if options.deleted -->
|
|
31
|
-
if (command.options?.deleted) {
|
|
32
|
-
const targetCommand = appCommands?.cache.find((cmd) => cmd.name === command.data.name);
|
|
33
|
-
if (!targetCommand) {
|
|
34
|
-
console.log(`⏩ Ignoring: Command "${command.data.name}" is globally marked as deleted.`);
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
targetCommand.delete().then(() => {
|
|
38
|
-
console.log(`🚮 Deleted command "${command.data.name}" globally.`);
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
for (const guildCommands of devGuildCommands) {
|
|
42
|
-
const targetCommand = guildCommands.cache.find((cmd) => cmd.name === command.data.name);
|
|
43
|
-
if (!targetCommand) {
|
|
44
|
-
console.log(`⏩ Ignoring: Command "${command.data.name}" is marked as deleted for ${guildCommands.guild.name}.`);
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
targetCommand.delete().then(() => {
|
|
48
|
-
console.log(`🚮 Deleted command "${command.data.name}" in ${guildCommands.guild.name}.`);
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
continue;
|
|
53
|
-
}
|
|
54
|
-
// <!-- Edit command -->
|
|
55
|
-
let commandData = command.data;
|
|
56
|
-
let editedCommand = false;
|
|
57
|
-
// Edit command globally
|
|
58
|
-
const appGlobalCommand = appCommands?.cache.find((cmd) => cmd.name === command.data.name);
|
|
59
|
-
if (appGlobalCommand) {
|
|
60
|
-
const commandsAreDifferent = (0, areSlashCommandsDifferent_1.default)(appGlobalCommand, commandData);
|
|
61
|
-
if (commandsAreDifferent) {
|
|
62
|
-
appGlobalCommand
|
|
63
|
-
.edit(commandData)
|
|
64
|
-
.then(() => {
|
|
65
|
-
console.log(`✅ Edited command "${commandData.name}" globally.`);
|
|
66
|
-
})
|
|
67
|
-
.catch((error) => {
|
|
68
|
-
console.log(`❌ Failed to edit command "${commandData.name}" globally.`);
|
|
69
|
-
console.error(error);
|
|
70
|
-
});
|
|
71
|
-
editedCommand = true;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
// Edit command in a specific guild
|
|
75
|
-
for (const guildCommands of devGuildCommands) {
|
|
76
|
-
const appGuildCommand = guildCommands.cache.find((cmd) => cmd.name === commandData.name);
|
|
77
|
-
if (appGuildCommand) {
|
|
78
|
-
const commandsAreDifferent = (0, areSlashCommandsDifferent_1.default)(appGuildCommand, commandData);
|
|
79
|
-
if (commandsAreDifferent) {
|
|
80
|
-
appGuildCommand
|
|
81
|
-
.edit(commandData)
|
|
82
|
-
.then(() => {
|
|
83
|
-
console.log(`✅ Edited command "${commandData.name}" in ${guildCommands.guild.name}.`);
|
|
84
|
-
})
|
|
85
|
-
.catch((error) => {
|
|
86
|
-
console.log(`❌ Failed to edit command "${commandData.name}" in ${guildCommands.guild.name}.`);
|
|
87
|
-
console.error(error);
|
|
88
|
-
});
|
|
89
|
-
editedCommand = true;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
if (editedCommand)
|
|
94
|
-
continue;
|
|
95
|
-
// <!-- Register command -->
|
|
96
|
-
// Register command in a specific guild
|
|
97
|
-
if (command.options?.devOnly) {
|
|
98
|
-
if (!devGuilds.length) {
|
|
99
|
-
console.log(`⏩ Ignoring: Cannot register command "${command.data.name}" as no valid "devGuildIds" were provided.`);
|
|
100
|
-
continue;
|
|
101
|
-
}
|
|
102
|
-
for (const guild of devGuilds) {
|
|
103
|
-
const cmdExists = guild.commands.cache.some((cmd) => cmd.name === command.data.name);
|
|
104
|
-
if (cmdExists)
|
|
105
|
-
continue;
|
|
106
|
-
guild?.commands
|
|
107
|
-
.create(command.data)
|
|
108
|
-
.then(() => {
|
|
109
|
-
console.log(`✅ Registered command "${command.data.name}" in ${guild.name}.`);
|
|
110
|
-
})
|
|
111
|
-
.catch((error) => {
|
|
112
|
-
console.log(`❌ Failed to register command "${command.data.name}" in ${guild.name}.`);
|
|
113
|
-
console.error(error);
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
// Register command globally
|
|
118
|
-
else {
|
|
119
|
-
const cmdExists = appCommands?.cache.some((cmd) => cmd.name === command.data.name);
|
|
120
|
-
if (cmdExists)
|
|
121
|
-
continue;
|
|
122
|
-
appCommands
|
|
123
|
-
?.create(command.data)
|
|
124
|
-
.then(() => {
|
|
125
|
-
console.log(`✅ Registered command "${command.data.name}" globally.`);
|
|
126
|
-
})
|
|
127
|
-
.catch((error) => {
|
|
128
|
-
console.log(`❌ Failed to register command "${command.data.name}" globally.`);
|
|
129
|
-
console.error(error);
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
exports.default = registerCommands;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function areSlashCommandsDifferent(appCommand: any, localCommand: any): true | undefined;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
function areSlashCommandsDifferent(appCommand, localCommand) {
|
|
4
|
-
if (!appCommand.options)
|
|
5
|
-
appCommand.options = [];
|
|
6
|
-
if (!localCommand.options)
|
|
7
|
-
localCommand.options = [];
|
|
8
|
-
if (!appCommand.description)
|
|
9
|
-
appCommand.description = '';
|
|
10
|
-
if (!localCommand.description)
|
|
11
|
-
localCommand.description = '';
|
|
12
|
-
if (localCommand.description !== appCommand.description ||
|
|
13
|
-
localCommand.options.length !== appCommand.options.length) {
|
|
14
|
-
return true;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
exports.default = areSlashCommandsDifferent;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
module.exports = ({ interaction, targetCommand }) => {
|
|
4
|
-
const botMember = interaction.guild?.members.me;
|
|
5
|
-
if (targetCommand.options?.botPermissions && botMember) {
|
|
6
|
-
for (const permission of targetCommand.options.botPermissions) {
|
|
7
|
-
const hasPermission = botMember.permissions.has(permission);
|
|
8
|
-
if (!hasPermission) {
|
|
9
|
-
interaction.reply({
|
|
10
|
-
content: `❌ I do not have enough permission to execute this command. Required permission: \`${permission}\``,
|
|
11
|
-
ephemeral: true,
|
|
12
|
-
});
|
|
13
|
-
return true;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
module.exports = ({ interaction, targetCommand, handlerData }) => {
|
|
4
|
-
if (targetCommand.options?.devOnly) {
|
|
5
|
-
if (interaction.inGuild() && !handlerData.devGuildIds.includes(interaction.guildId)) {
|
|
6
|
-
interaction.reply({
|
|
7
|
-
content: '❌ This command can only be used inside development servers.',
|
|
8
|
-
ephemeral: true,
|
|
9
|
-
});
|
|
10
|
-
return true;
|
|
11
|
-
}
|
|
12
|
-
const guildMember = interaction.guild?.members.cache.get(interaction.user.id);
|
|
13
|
-
const memberRoles = guildMember?.roles.cache;
|
|
14
|
-
let hasDevRole = false;
|
|
15
|
-
memberRoles?.forEach((role) => {
|
|
16
|
-
if (handlerData.devRoleIds?.includes(role.id)) {
|
|
17
|
-
hasDevRole = true;
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
const isDevUser = handlerData.devUserIds.includes(interaction.user.id) || hasDevRole;
|
|
21
|
-
if (!isDevUser) {
|
|
22
|
-
interaction.reply({
|
|
23
|
-
content: '❌ This command can only be used by developers.',
|
|
24
|
-
ephemeral: true,
|
|
25
|
-
});
|
|
26
|
-
return true;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
module.exports = ({ interaction, targetCommand }) => {
|
|
4
|
-
if (targetCommand.options?.guildOnly && !interaction.inGuild()) {
|
|
5
|
-
interaction.reply({
|
|
6
|
-
content: '❌ This command can only be used inside a server.',
|
|
7
|
-
ephemeral: true,
|
|
8
|
-
});
|
|
9
|
-
return true;
|
|
10
|
-
}
|
|
11
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
module.exports = ({ interaction, targetCommand }) => {
|
|
4
|
-
const memberPermissions = interaction.memberPermissions;
|
|
5
|
-
if (targetCommand.options?.userPermissions && memberPermissions) {
|
|
6
|
-
for (const permission of targetCommand.options.userPermissions) {
|
|
7
|
-
const hasPermission = memberPermissions.has(permission);
|
|
8
|
-
if (!hasPermission) {
|
|
9
|
-
interaction.reply({
|
|
10
|
-
content: `❌ You do not have enough permission to run this command. Required permission: \`${permission}\``,
|
|
11
|
-
ephemeral: true,
|
|
12
|
-
});
|
|
13
|
-
return true;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { EventHandlerOptions, EventHandlerData } from './typings';
|
|
2
|
-
export declare class EventHandler {
|
|
3
|
-
_data: EventHandlerData;
|
|
4
|
-
constructor({ ...options }: EventHandlerOptions);
|
|
5
|
-
_buildEvents(): void;
|
|
6
|
-
_registerEvents(): void;
|
|
7
|
-
getEvents(): {
|
|
8
|
-
name: string;
|
|
9
|
-
functions: Function[];
|
|
10
|
-
}[];
|
|
11
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EventHandler = void 0;
|
|
4
|
-
const get_paths_1 = require("../../utils/get-paths");
|
|
5
|
-
class EventHandler {
|
|
6
|
-
_data;
|
|
7
|
-
constructor({ ...options }) {
|
|
8
|
-
this._data = {
|
|
9
|
-
...options,
|
|
10
|
-
events: [],
|
|
11
|
-
};
|
|
12
|
-
this._buildEvents();
|
|
13
|
-
this._registerEvents();
|
|
14
|
-
}
|
|
15
|
-
_buildEvents() {
|
|
16
|
-
const eventFolderPaths = (0, get_paths_1.getFolderPaths)(this._data.eventsPath);
|
|
17
|
-
for (const eventFolderPath of eventFolderPaths) {
|
|
18
|
-
const eventName = eventFolderPath.replace(/\\/g, '/').split('/').pop();
|
|
19
|
-
const eventFilePaths = (0, get_paths_1.getFilePaths)(eventFolderPath, true).filter((path) => path.endsWith('.js') || path.endsWith('.ts'));
|
|
20
|
-
const eventObj = {
|
|
21
|
-
name: eventName,
|
|
22
|
-
functions: [],
|
|
23
|
-
};
|
|
24
|
-
this._data.events.push(eventObj);
|
|
25
|
-
for (const eventFilePath of eventFilePaths) {
|
|
26
|
-
const eventFunction = require(eventFilePath);
|
|
27
|
-
if (typeof eventFunction !== 'function') {
|
|
28
|
-
console.log(`Ignoring: Event ${eventFilePath} does not export a function.`);
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
eventObj.functions.push(eventFunction);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
_registerEvents() {
|
|
36
|
-
const client = this._data.client;
|
|
37
|
-
for (const eventObj of this._data.events) {
|
|
38
|
-
client.on(eventObj.name, async (...params) => {
|
|
39
|
-
for (const eventFunction of eventObj.functions) {
|
|
40
|
-
const stopEventLoop = await eventFunction(...params, client);
|
|
41
|
-
if (stopEventLoop) {
|
|
42
|
-
break;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
getEvents() {
|
|
49
|
-
return this._data.events;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
exports.EventHandler = EventHandler;
|
package/dist/handlers/index.d.ts
DELETED
package/dist/handlers/index.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./command-handler/CommandHandler"), exports);
|
|
18
|
-
__exportStar(require("./event-handler/EventHandler"), exports);
|
|
19
|
-
__exportStar(require("./validation-handler/ValidationHandler"), exports);
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { ValidationHandlerData, ValidationHandlerOptions } from './typings';
|
|
2
|
-
export declare class ValidationHandler {
|
|
3
|
-
_data: ValidationHandlerData;
|
|
4
|
-
constructor({ ...options }: ValidationHandlerOptions);
|
|
5
|
-
_buildValidations(): void;
|
|
6
|
-
getValidations(): Function[];
|
|
7
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ValidationHandler = void 0;
|
|
4
|
-
const get_paths_1 = require("../../utils/get-paths");
|
|
5
|
-
class ValidationHandler {
|
|
6
|
-
_data;
|
|
7
|
-
constructor({ ...options }) {
|
|
8
|
-
this._data = {
|
|
9
|
-
...options,
|
|
10
|
-
validations: [],
|
|
11
|
-
};
|
|
12
|
-
this._buildValidations();
|
|
13
|
-
}
|
|
14
|
-
_buildValidations() {
|
|
15
|
-
const validationFilePaths = (0, get_paths_1.getFilePaths)(this._data.validationsPath, true).filter((path) => path.endsWith('.js') || path.endsWith('.ts'));
|
|
16
|
-
for (const validationFilePath of validationFilePaths) {
|
|
17
|
-
const validationFunction = require(validationFilePath);
|
|
18
|
-
if (typeof validationFunction !== 'function') {
|
|
19
|
-
console.log(`Ignoring: Validation ${validationFilePath} does not export a function.`);
|
|
20
|
-
continue;
|
|
21
|
-
}
|
|
22
|
-
this._data.validations.push(validationFunction);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
getValidations() {
|
|
26
|
-
return this._data.validations;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
exports.ValidationHandler = ValidationHandler;
|
package/dist/utils/get-paths.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getFolderPaths = exports.getFilePaths = void 0;
|
|
7
|
-
const path_1 = __importDefault(require("path"));
|
|
8
|
-
const fs_1 = __importDefault(require("fs"));
|
|
9
|
-
function getFilePaths(directory, nesting) {
|
|
10
|
-
let filePaths = [];
|
|
11
|
-
if (!directory)
|
|
12
|
-
return filePaths;
|
|
13
|
-
const files = fs_1.default.readdirSync(directory, { withFileTypes: true });
|
|
14
|
-
for (const file of files) {
|
|
15
|
-
const filePath = path_1.default.join(directory, file.name);
|
|
16
|
-
if (file.isFile()) {
|
|
17
|
-
filePaths.push(filePath);
|
|
18
|
-
}
|
|
19
|
-
if (nesting && file.isDirectory()) {
|
|
20
|
-
filePaths = [...filePaths, ...getFilePaths(filePath, true)];
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return filePaths;
|
|
24
|
-
}
|
|
25
|
-
exports.getFilePaths = getFilePaths;
|
|
26
|
-
function getFolderPaths(directory, nesting) {
|
|
27
|
-
let folderPaths = [];
|
|
28
|
-
if (!directory)
|
|
29
|
-
return folderPaths;
|
|
30
|
-
const folders = fs_1.default.readdirSync(directory, { withFileTypes: true });
|
|
31
|
-
for (const folder of folders) {
|
|
32
|
-
const folderPath = path_1.default.join(directory, folder.name);
|
|
33
|
-
if (folder.isDirectory()) {
|
|
34
|
-
folderPaths.push(folderPath);
|
|
35
|
-
if (nesting) {
|
|
36
|
-
folderPaths = [...folderPaths, ...getFolderPaths(folderPath, true)];
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return folderPaths;
|
|
41
|
-
}
|
|
42
|
-
exports.getFolderPaths = getFolderPaths;
|
package/tsconfig.json
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"outDir": "dist",
|
|
4
|
-
"strict": true,
|
|
5
|
-
"noImplicitAny": true,
|
|
6
|
-
"esModuleInterop": true,
|
|
7
|
-
"strictNullChecks": true,
|
|
8
|
-
"target": "ES2022",
|
|
9
|
-
"moduleResolution": "Node",
|
|
10
|
-
"module": "CommonJS",
|
|
11
|
-
"declaration": true
|
|
12
|
-
},
|
|
13
|
-
"include": ["src/**/*"]
|
|
14
|
-
}
|