forked from heroslender/EliteBOT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
87 lines (73 loc) · 2.68 KB
/
app.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
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
const Discord = require('discord.js'); //definindo conexão com discord padrão
const fs = require('fs'); //Definindo constante fs para inicialização de eventos
const client = new Discord.Client(); //definindo o bot como um novo client
const c = require('colors');
const fileUtils = require('./utils/fileUtils');
client.Database = require('./database.js');
client.Discord = require('discord.js');
config = require('./config');
client.commands = new Discord.Collection();
client.aliases = new Discord.Collection();
/**
* Initialize and start the bot.
*/
function start() {
console.log(c.cyan('Carregando eventos...'));
loadEvents('./eventos');
console.log(c.cyan('Carregando comandos...'));
loadCommands('./comandos');
console.log(c.cyan('Conectando o bot...'));
client.login(config.token);
}
/**
* Load all commands in a specific directory.
*
* @param {string} dir - The commands directory.
*/
function loadCommands(dir) {
for (const dirInfo of fileUtils.searchByExtension(dir, 'js')) {
const dirList = dirInfo.directory.split('/');
dirList.shift();
dirList.shift();
const commandCategory = dirList
.join('/');
for (const file of dirInfo.files) {
let cmd = require(file);
if(!cmd.help) {
// Invalid command.
continue;
}
client.commands.set(cmd.help.name, cmd);
if(cmd.help.aliases) {
cmd.help.aliases
.filter(alias => alias.trim() !== '')
.forEach(alias => client.aliases.set(alias, cmd.help.name));
}
}
const formatedFiles = dirInfo.files.map(file => file.split('/').pop().split('.').shift())
console.log(`[COMANDO] ` + c.yellow('Foram carregados ') + dirInfo.files.length + c.yellow(' comandos na categoria ') + commandCategory + c.yellow('. [') + formatedFiles.join(c.yellow(', ')) + c.yellow(']'));
}
}
/**
* Load all events in a specific directory.
*
* @param {string} dir - The events directory.
*/
function loadEvents(dir) {
for (const dirInfo of fileUtils.searchByExtension(dir, 'js')) {
for (const file of dirInfo.files) {
let events = require(file);
if(!Array.isArray(events)) {
events = [events];
}
for (const event of events) {
if(!event.name || !event.run) {
continue;
}
console.log(`[EVENTO] ` + c.yellow('O evento ') + event.name + c.yellow(' foi carregado!'));
client.on(event.name, (...args) => event.run(client, ...args));
}
}
}
}
start();