-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.js
76 lines (72 loc) · 2.74 KB
/
main.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
'use strict';
const { Client, Intents } = require('discord.js');
const CommandsManager = require('./src/utils/CommandsManager.js');
const EventsManager = require('./src/utils/EventsManager.js');
const dashManager = require('./src/utils/dashboardManager')
const DbManager = require('./src/utils/DbManager.js');
const Logger = require('./src/utils/Logger.js');
const { resolve } = require("path");
const mongo = require('./src/utils/MongoDB')
const ApiManager = require('./src/utils/ApiManager.js');
class Bot extends Client {
constructor() {
super({
messageCacheMaxSize: 5,
messageCacheLifetime: 300,
intents: [
Intents.FLAGS.GUILDS,
],
allowedMentions: {
parse: ["users"]
},
restRequestTimeout: 30000
});
this.config = require('./config.json');
this.database = new DbManager(this);
this.baseApi = new ApiManager(this);
this.dashboard = new dashManager(this)
this.logger = new Logger("Shard #" + this.shard.ids);
this.events = new EventsManager(this);
this.launch().then(() => {
this.logger.sucess("All was sucessfuly launched");
this.user.setActivity("/help | allegoria.me", { type: "PLAYING" });
}).catch(err => {
console.log(err)
this.logger.error(`[LaunchError] An error occured at startup ${err}`);
})
}
async launch() {
this.baseApi.checkClient(this)
console.log("[Launching] Bot is launching...");
await this.events.loadEvent();
this.logger.sucess(`[Events] Loaded ${this.events.events.size} events`);
console.log("BAHAHAH")
try {
await this.login(this.config.bot.token);
this.logger.sucess("[WS] Connected to discord");
} catch (error) {
this.logger.error(`[WS] Connection error: ${e}`);
}
await mongo();
this.commands = new CommandsManager(this);
let slash = await resolve(__dirname, "..", "commands")
await this.commands.loadCommands({ slashed: true, path: slash });
let prefixCmds = await resolve(__dirname, "..", "prefix_cmds")
await this.commands.loadCommands({ slashed: false, path: prefixCmds });
this.logger.sucess(`[Commands] Loaded ${this.commands.commands.size} commands`);
this.dashboard.launch({ domain: "https://allegoria.me", port: 8080 })
}
}
process.on('unhandledRejection', (err) => {
console.log(err)
});
process.on('uncaughtException', (err, origin) => {
return
});
process.on('uncaughtExceptionMonitor', (err, origin) => {
return
});
process.on('multipleResolves', (type, promise, reason) => {
return
});
module.exports = new Bot;