-
Notifications
You must be signed in to change notification settings - Fork 12
/
load.js
102 lines (83 loc) · 3.05 KB
/
load.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
const { ShardingManager, Client } = require('discord.js');
const mongoose = require('mongoose');
const si = require("systeminformation");
const express = require('express');
const path = require("path");
const router = express.Router();
const fs = require("fs");
const https = require("https");
const hostname = "toowake.live";
const authRouter = require('./express/dashboard/auth');
const chalk = require("chalk");
var mongooseStatus = false
// MongoDB Connection
async function connectToMongoDB() {
try {
mongoose.set('strictQuery', false);
mongoose.connect(process.env.MONGOURI, {
useNewUrlParser: true,
useUnifiedTopology: true
})
.catch(err => console.error('Could not connect to MongoDB:', err));
mongoose.connection.on('connected', () => {
mongooseStatus = true;
});
mongoose.connection.on('error', (err) => {
mongooseStatus = false;
});
mongoose.connection.on('disconnected', () => {
mongooseStatus = false;
});
} catch (error) {
console.error(chalk.red(`Failed to connect to database. \n${error}`));
process.exit(1);
}
}
async function getSystemInfo() {
try {
const cpuInfo = await si.cpu();
console.log("-> CPU: ", `${cpuInfo.manufacturer} ${cpuInfo.brand}`);
const memInfo = await si.memLayout();
memInfo.forEach((mem, index) => {
console.log(chalk.blue(`-> RAM Slot ${index + 1}: ${mem.manufacturer || "No data available"} ${mem.partNum}`));
});
const gpuInfo = await si.graphics();
gpuInfo.controllers.forEach((gpu, index) => {
console.log(chalk.blue(`-> GPU ${index + 1}: ${gpu.model}`));
});
} catch (error) {
console.error(chalk.red(`Error occurred while getting system information: \n${error}`));
}
}
// Main function to run the application
async function main() {
const amountShards = "auto"; //parseInt(process.env.SHARDS) ||
const t = `${process.env.TOKEN}`
const manager = new ShardingManager('./src/index.js', {
token: t,
totalShards: amountShards
});
manager.on('shardCreate', shard => console.log(chalk.blue("[ SHARD ] Launched Shard: ", `${shard.id + 1}`)));
manager.spawn().catch(console.error);
if (process.env.SITE === 'on') {
// Express Setup
const app = express();
const PORT = process.env.PORT || 3129;
app.set('view engine', 'ejs');
app.use('/auth', authRouter);
// Load Express
fs.readdirSync('./express').forEach((dir) => {
fs.readdirSync(`./express/${dir}`).forEach((handler) => {
require(`./express/${dir}/${handler}`)(app);
});
});
app.listen(PORT, 'localhost', () => console.log(chalk.yellow("[ EXPRESS ] Server running on port ", `${PORT}`)));
}
}
// Execute the main function
main().catch(error => {
console.error(chalk.red(`An error occurred:\n ${error}`));
process.exit(1);
});
connectToMongoDB();
module.exports = {mongooseStatus}