-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
96 lines (87 loc) · 2.35 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
const modules = require(`./modules.js`);
const storage = require(`./storage.js`);
const functions = require(`./functions.js`);
const methods = require(`./methods.js`);
const models = require(`./models.js`);
const client = new modules.Discord.Client({
disableEveryone: false,
shardCount: 1,
totalShardCount: 1,
messageCacheMaxSize: 200,
messageCacheLifetime: 0,
messageSweepInterval: 0,
fetchAllMembers: false,
restWsBridgeTimeout: 5000,
restTimeOffset: 500,
restSweepInterval: 60,
disabledEvents: ["TYPING_START"]
});
const auth = require(`./storage/auth`);
if (!auth) {
console.error(`[ERROR] Could not find auth.js in /storage/`);
return;
}
/*
HANDLERS
*/
let url = auth.mongoUrl;
if (!url) {
console.error(`[ERROR] Could not find mongoUrl in auth.js /storage/`);
return;
}
if (typeof url !== "string") {
console.error(`[ERROR] mongoUrl provided is NOT string`);
return;
}
modules.mongoose.connect(url, {
useNewUrlParser: true,
useUnifiedTopology: true
});
modules.mongoose.connection.on(
"error",
console.error.bind(console, `[ERROR] Connection error:`)
);
modules.mongoose.connection.once("open", () => {
console.log(`[LOG] Connected to the database.`);
});
modules.fs.readdir(`./events/`, (err, files) => {
if (err) return console.error(err);
files.forEach(file => {
if (!file.endsWith(".js")) return;
let event = require(`./events/${file}`);
let eventName = file.split(".")[0];
client.on(eventName, event.bind(null, client));
delete require.cache[require.resolve(`./events/${file}`)];
console.log(`[LOG] Loaded event ${file}`);
});
});
const { CommandHandler } = require(`djs-commands`);
let cmdHandler = new CommandHandler({
folder: __dirname + `/commands/`,
prefix: ["."]
});
/*
BINDINGS
*/
client.modules = modules;
client.commandHandler = cmdHandler;
client.storage = storage;
client.functions = functions;
client.methods = methods;
client.models = models;
const mineSelected = new Map();
client.mineSelected = mineSelected;
/*
EXPORTS + LOGIN
*/
module.exports = client;
let token = auth.token;
if (!token) {
console.error(`[ERROR] Cannot find token in auth.js in /storage/`);
return;
}
if (typeof token !== "string") {
console.error(`[ERROR] Token presented in auth.js /storage/ not a string!`);
return;
}
client.login(require(`./storage/auth`).token);