-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommandLoader.js
More file actions
110 lines (90 loc) · 3.37 KB
/
commandLoader.js
File metadata and controls
110 lines (90 loc) · 3.37 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
const fs = require('fs');
const path = require('path');
const logConsole = require("./logger");
function loadCommands(client) {
const baseDirectory = path.resolve(__dirname, './commands');
client.commands = new Map();
function readCommands(directory) {
const files = fs.readdirSync(directory);
for (let file of files) {
const fullPath = path.resolve(directory, file);
const stats = fs.statSync(fullPath);
if (stats.isDirectory()) {
readCommands(fullPath);
} else {
const command = require(fullPath);
client.commands.set(command.name, {
execute: command.execute,
params: command.params,
tags: command.tags || false
});
// log the command name and category.
logConsole(`${command.category}: ${command.name} | ${command.description} loaded`);
// if (command.params) {
// logConsole(`Command '${command.name}' allows params.`);
// }
}
}
}
readCommands(baseDirectory);
}
function fetchCommands(showSystemCommands) {
const baseDirectory = path.resolve(__dirname, './commands');
let commandsArray = [];
function readCommands(directory) {
const files = fs.readdirSync(directory);
for (let file of files) {
const fullPath = path.resolve(directory, file);
const stats = fs.statSync(fullPath);
if (stats.isDirectory()) {
readCommands(fullPath);
} else {
const command = require(fullPath);
// Exclude commands from the 'system' category
if (showSystemCommands) {
commandsArray.push({
name: command.name,
description: command.description,
execute: command.execute,
category: command.category,
params: command.params || false
});
} else {
if (command.category !== 'system') {
commandsArray.push({
name: command.name,
description: command.description,
execute: command.execute,
category: command.category,
params: command.params || false
});
}
}
}
}
}
readCommands(baseDirectory);
return commandsArray;
}
function countCommands() {
const baseDirectory = path.resolve(__dirname, './commands');
let commandCount = 0;
function count(directory) {
const files = fs.readdirSync(directory);
for (let file of files) {
const fullPath = path.resolve(directory, file);
const stats = fs.statSync(fullPath);
if (stats.isDirectory()) {
count(fullPath);
} else {
const command = require(fullPath);
if (command.category !== '') {
commandCount++;
}
}
}
}
count(baseDirectory);
return commandCount;
}
module.exports = {loadCommands, fetchCommands, countCommands};