-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
153 lines (136 loc) · 4.77 KB
/
index.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// Bot online 24/7
require("./keep_alive.js");
// NPMs
const Discord = require("discord.js");
const fs = require("fs");
const Enmap = require("enmap");
// Bot config
require("dotenv").config();
const config = require("./config.json");
const botUtils = require("./utils.js");
const client = new Discord.Client({
fetchAllMembers: true,
disableMentions: "everyone",
autoreconnect: true,
partials: ['MESSAGE', 'REACTION']
});
client.config = config;
const disbut = require('discord-buttons')(client);
// Utils config
chalkClient = botUtils.chalkClient;
newError = botUtils.newError;
isDir = botUtils.isDir;
botUtils.clearAllErrors();
// Handler de erros em promise
process.on('unhandledRejection', (reason, p) => { console.log(reason) });
// Starting Time - by Alstin112
botUtils.jsonChange('./dataBank/serverState.json', server => {
server["serverStarted"] = (new Date()).getTime() - 10800000
return server;
},true)
// Event handler
console.log('\n------------------\nEvents');
let source = fs.readdirSync("./events");
source.forEach(foldert => {
var sla = fs.readdirSync(`./events/${foldert}`);
console.log(`\n${foldert}/`);
sla.forEach(filet => {
try {
if (!filet.endsWith(".js")) {
if (isDir(`./events/${foldert}/${filet}`) && filet == "utils") {
var utilst = fs.readdirSync(`./events/${foldert}/${filet}`);
console.log(`- ${filet}/`);
utilst.forEach(fileutils => {
let nameutil = foldert + fileutils.split(".")[0];
try {
require(`./events/${foldert}/${filet}/${fileutils}`);
console.log(`- - ${fileutils}: ${chalkClient.ok('OK')}`)
} catch (err) {
console.log(`- - ${fileutils}: ${chalkClient.error('ERROR')}`);
console.log(`=> ${newError(err, nameutil)}`);
}
})
}
return;
}
let name = filet.split('.')[0];
console.log(`- ${name}.js: ${chalkClient.ok('OK')}`);
let exported = require(`./events/${foldert}/${filet}`);
client.on(name, exported.bind(null, client));
} catch (err) {
console.log(`- ${filet}: ${chalkClient.error('ERROR')}`);
console.log(`=> ${newError(err, filet)}`);
}
});
});
// Command handler setup
client.commands = new Discord.Collection();
client.commands = new Enmap();
client.aliases = new Discord.Collection();
let commandsFolder = fs.readdirSync("commands");
// Config Utils handler setup
client.utils = {}
client.utilsAliases = {}
// Command handler
console.log('\n------------------\nCommands');
commandsFolder.forEach(folder => {
if (folder === "teste") return console.log("Achou a pasta teste");
var all = fs.readdirSync(`./commands/${folder}`);
var files = all.filter(f => {
let dirCheck = isDir(`./commands/${folder}/${f}`);
return f.split(".").slice(-1)[0] === "js" && !dirCheck;
});
var UtilsFolder = all.filter(u => {
let dirCheck = isDir(`./commands/${folder}/${u}`);
return u === "Utils" && dirCheck;
});
console.log(`\n${folder.replace("ZZZ", "")}/`);
files.forEach(f => {
try {
let pull = require(`./commands/${folder}/${f}`);
console.log(`- ${pull.config.name}.js: ${chalkClient.ok('OK')}`);
client.commands.set(pull.config.name, pull);
pull.config.aliases.forEach(alias => {
client.aliases.set(alias, pull.config.name);
});
} catch (err) {
/*
Caso aconteça algum erro
Cria um arquivo chamado "<nome do arquivo com erro>_Error.log"
*/
console.log(`- ${f}: ${chalkClient.error('ERROR')}`);
console.log(`=> ${newError(err, f)}`);
}
});
// Config Utils handler
client.utils[folder.replace("ZZZ", "")] = {};
client.utilsAliases[folder.replace("ZZZ", "")] = {};
UtilsFolder.forEach(u => {
console.log(`- ${u}/`);
var allUtils = fs.readdirSync(`./commands/${folder}/${u}`);
var UtilsFiles = allUtils.filter(uf => {
let dirCheck = isDir(`./commands/${folder}/${u}/${uf}`);
return uf.split(".").slice(-1)[0] === "js" && !dirCheck;
});
UtilsFiles.forEach(uf => {
try {
let pull = require(`./commands/${folder}/${u}/${uf}`);
console.log(`- - ${pull.config.name}.js: ${chalkClient.ok('OK')}`);
client.utils[folder.replace("ZZZ", "")][pull.config.name] = pull
pull.config.aliases.forEach(alias => {
client.utilsAliases[folder.replace("ZZZ", "")][alias] = pull
});
} catch (err) {
/*
Caso aconteça algum erro
Cria um arquivo chamado "<nome do arquivo com erro>Error.log"
*/
console.log(`- - ${uf}: ${chalkClient.error('ERROR')}`);
console.log(`= => ${newError(err, `Utils_${uf}`)}`);
}
});
});
});
// Login do bot com a API do discord
const token = process.env.TOKEN || client.config.token;
client.login(token);