-
Notifications
You must be signed in to change notification settings - Fork 302
/
commandHandler.js
40 lines (30 loc) · 1.01 KB
/
commandHandler.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const fs = require('fs');
const path = require('path');
const cmdsDir = path.join(__dirname, 'Cmds');
function findAllCommandFiles(dir) {
let commandFiles = [];
let totalCommands = 0;
function findFiles(directory) {
const files = fs.readdirSync(directory);
for (const file of files) {
const filePath = path.join(directory, file);
const stat = fs.statSync(filePath);
if (stat.isDirectory()) {
findFiles(filePath);
} else if (file.endsWith('.js')) {
commandFiles.push(filePath);
totalCommands++;
}
}
}
findFiles(dir);
return { commandFiles, totalCommands };
}
const { commandFiles, totalCommands } = findAllCommandFiles(cmdsDir);
const commands = {};
commandFiles.forEach(file => {
const commandName = path.basename(file, '.js');
const commandModule = require(file);
commands[commandName] = commandModule;
});
module.exports = { commands, totalCommands };