-
Notifications
You must be signed in to change notification settings - Fork 100
/
Copy pathutils.js
53 lines (45 loc) · 1.46 KB
/
utils.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
41
42
43
44
45
46
47
48
49
50
51
52
53
const { readdirSync, lstatSync } = require('fs')
/*
* Carrega commandos que estão na pasta **commands** e em grupos de subpastas
*/
function loadCommands(collection, directory) {
const cmdFiles = readdirSync(directory)
console.log(
'log',
`Carregando o total de ${cmdFiles.length} comandos em ${directory}`,
)
for (const file of cmdFiles) {
try {
const path = `${directory}/${file}`
if (file.endsWith('.js')) {
const command = require(path)
console.log('log', `Carregando comando: ${command.help.name}`)
collection.set(command.help.name, command)
if (command.help.aliases) {
command.help.aliases.forEach((alias) =>
collection.set(alias, command),
)
}
} else if (lstatSync(path).isDirectory()) {
loadCommands(collection, path)
}
} catch (e) {
console.error(`Não foi possível carregar o comando ${file}: ${e}`)
}
}
}
function loadEvents(directory, client) {
const eventFiles = readdirSync(directory)
console.log('log', `Carregando o total de ${eventFiles.length} eventos`)
for (const file of eventFiles) {
const eventName = file.split('.')[0]
const event = require(`./events/${file}`)
try {
client.on(eventName, event.bind(null, client))
} catch (error) {
console.error(`Não foi possível carregar o evento ${eventName}: error`)
}
}
}
exports.loadEvents = loadEvents
exports.loadCommands = loadCommands