-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
115 lines (97 loc) · 2.24 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
// Start time
let startDate = new Date();
// Bot Dependencies
const Discord = require("discord.js");
const fs = require("fs");
const Enmap = require('enmap');
require('moment-duration-format');
// Set mobile status
Discord.Constants.DefaultOptions.ws.properties.$browser = "Discord Android";
// Create client
const client = new Discord.Client({
ws: {
intents: [
'GUILD_MESSAGES',
'GUILDS',
'GUILD_MEMBERS',
'DIRECT_MESSAGES'
]
}
});
// Loads config.js
config = require('./config.js');
client.config = config;
// Start time
client.startDate = startDate;
client.commands = new Discord.Collection();
client.aliases = new Discord.Collection();
client.serverDB = new Enmap({
name: "servers",
fetchAll: true,
autoFetch: true,
dataDir: "./database/servers/",
cloneLevel: 'deep'
});
client.userDB = new Enmap({
name: "users",
fetchAll: true,
autoFetch: true,
dataDir: "./database/users/",
cloneLevel: 'deep'
});
client.defaultServerDB = {
prefix: client.config.dmPrefix,
stats: {
commandsRun: 0,
serversCreated: 0
},
panel: {
apiKey: "",
url: ""
},
nodes: [],
store: {
payments: [],
packages: [],
logChannel: null
},
config: {
}
}
client.modules = [
"general",
"owner",
"panel",
"staff",
"billing"
]
// Load modules
fs.readdir(`${process.cwd()}/modules/`, (err, files) => {
if (err) { throw err }
for (const file of files) {
if (!file.endsWith(".js")) continue;
require(`${process.cwd()}/modules/${file}`)(client);
}
client.log("BOT", "Starting...");
client.log("BOT", "Loaded modules");
// Load discord events
client.loadEvents();
// Load commands
client.loadCommands();
});
// Process events
process.on('exit', async () => {
await client.serverDB.close();
await client.userDB.close();
process.exit(1);
});
process.on('SIGHUP', () => process.exit(128 + 1));
process.on('SIGINT', () => process.exit(128 + 2));
process.on('SIGTERM', () => process.exit(128 + 15));
// Log into client
try {
client.login(client.config.token);
} catch(e) {
console.error(`Invalid token: ${e}`);
return;
}