-
-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathindex.js
84 lines (68 loc) · 2.88 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
if (!process.argv.includes("--sharded")){
console.log("Please start ManageInvite with the sharder.js file!");
process.exit(0);
}
const util = require("util"),
fs = require("fs"),
readdir = util.promisify(fs.readdir);
const Constants = require("./helpers/constants");
const config = require("./config.js");
const Sentry = require("@sentry/node");
Sentry.init({ dsn: config.sentryDSN });
// Load ManageInvite class
const ManageInvite = require("./structures/Client"),
client = new ManageInvite();
const init = async () => {
require("./helpers/extenders");
// Search for all commands
const directories = await readdir("./commands/");
directories.forEach(async (dir) => {
const commands = await readdir("./commands/"+dir+"/");
commands.filter((cmd) => cmd.split(".").pop() === "js").forEach((cmd) => {
const response = client.loadCommand("./commands/"+dir, cmd);
if (response){
client.log(response, "error");
}
});
});
// Then we load events, which will include our message and ready event.
const evtFiles = await readdir("./events/");
evtFiles.forEach((file) => {
const eventName = file.split(".")[0];
const event = new (require(`./events/${file}`))(client);
client.on(eventName, (...args) => event.run(...args));
delete require.cache[require.resolve(`./events/${file}`)];
});
const i18n = require("./helpers/i18n");
client.translations = await i18n();
await client.database.connect();
// Gets commands permission
client.levelCache = {};
for (let i = 0; i < client.permLevels.length; i++) {
const thisLevel = client.permLevels[parseInt(i, 10)];
client.levelCache[thisLevel.name] = thisLevel.level;
}
client.on("shardReady", (shardID) => {
client.functions.sendStatusWebhook(`${Constants.Emojis.DND} | Shard #${shardID} is ready!`);
});
client.on("shardDisconnect", (shardID) => {
client.functions.sendStatusWebhook(`${Constants.Emojis.OFFLINE} | Shard #${shardID} is disconnected...`);
});
client.on("shardReconnecting", (shardID) => {
client.functions.sendStatusWebhook(`${Constants.Emojis.IDLE} | Shard #${shardID} is reconnecting...`);
});
client.on("shardResume", (shardID) => {
client.functions.sendStatusWebhook(`${Constants.Emojis.ONLINE} | Shard #${shardID} has resumed!`);
});
client.login(client.config.token); // Log in to the discord api
};
init();
// if there are errors, log them
client.on("disconnect", () => client.log("Bot is disconnecting...", "warn"))
.on("reconnecting", () => client.log("Bot reconnecting...", "log"))
.on("error", (e) => client.log(e, "error"))
.on("warn", (info) => client.log(info, "warn"));
// if there is an unhandledRejection, log them
process.on("unhandledRejection", (err) => {
console.error(err);
});