-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathindex.js
More file actions
79 lines (64 loc) · 2.01 KB
/
index.js
File metadata and controls
79 lines (64 loc) · 2.01 KB
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
// ___ _ ___ _
// / __> _ _ ___ ___ ___ _ _ _| |_ | . > ___ _| |_
// \__ \| | || . \| . \/ . \| '_> | | | . \/ . \ | |
// <___/`___|| _/| _/\___/|_| |_| |___/\___/ |_|
// |_| |_|
//
// SupportBot created by Emerald Services
// Installed with MIT License
//
// Discord Support: https://emeraldsrv.dev/discord
// Community Resources: https://community.emeraldsrv.dev
const fs = require("fs");
const path = require("path");
const yaml = require("js-yaml");
const supportbot = yaml.load(
fs.readFileSync("./Configs/supportbot.yml", "utf8")
);
const Client = require("./Structures/Client.js");
const client = new Client({
intents: ['Guilds', 'GuildMembers', 'GuildMessages', 'MessageContent']
});
const APIServer = require("./API/server.js");
client.start(supportbot.General.Token);
client.once('clientReady', () => {
const api = new APIServer(client);
api.start();
});
// SupportBot - New Logging System
const logTypes = ["Output", "Warn", "Error"];
if (!fs.existsSync("./Logs")) {
fs.mkdirSync("./Logs");
}
logTypes.forEach((type) => {
const dir = `./Logs/${type}`;
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}
});
function logToFile(type, data) {
const date = new Date().toISOString().split("T")[0];
const file = path.join(`./Logs/${type}`, `${type}-${date}.log`);
fs.appendFileSync(file, `[${new Date().toISOString()}] ${data}\n`);
}
const origLog = console.log;
console.log = (...args) => {
origLog(...args);
logToFile("Output", args.join(" "));
};
const origWarn = console.warn;
console.warn = (...args) => {
origWarn(...args);
logToFile("Warn", args.join(" "));
};
const origError = console.error;
console.error = (...args) => {
origError(...args);
logToFile("Error", args.join(" "));
};
process.on("unhandledRejection", (reason) => {
console.error("Unhandled Rejection:", reason);
});
process.on("uncaughtException", (err) => {
console.error("Uncaught Exception:", err);
});