-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
85 lines (64 loc) · 2.16 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
require('dotenv').config({ path: './Configs/.env' });
const { ClusterManager, HeartbeatManager, ReClusterManager } = require('discord-hybrid-sharding');
const { Process, Error, Debug } = require('./Modules/Structures/Logs');
const Check = require('./Modules/Utils/DataChecker');
const chalk = require('chalk');
const { TOKEN_DISCORD } = process.env;
(async () => {
// Check all datas
const dataStatus = await Check.checkAllData();
if(!dataStatus) return;
// Maintenance Status
await Check.checkMaintenance();
// Cluster creation
const manager = new ClusterManager(`${__dirname}/Modules/Client.js`, {
totalShards: 'auto',
shardsPerClusters: 5,
totalClusters: 'auto',
mode: 'process',
respawn: true,
restarts: {
max: "Infinity",
interval: 60000 * 60,
},
spawnOptions: {
timeout: 30000,
},
token: TOKEN_DISCORD,
});
manager.on('clusterCreate', cluster => {
Process(`launched Cluster ${chalk.bold.blueBright(cluster.id)}`);
// edit
cluster.on("death", (cc, t) => {
Error(`cluster ${chalk.bold.redBright(cluster.id)} died`)
Error(`ID: ${cc.id}`);
Error(`Exit Code: ${t.exitCode}`);
Error(`Killed: ${t.killed}`);
Error(`Args: ${t.spawnargs}`);
});
cluster.on("error", (e) => {
Error(`cluster ${chalk.bold.redBright(cluster.id)} has an error`)
Error(e.name);
Error(e.message);
Error(e.stack);
});
});
manager.extend(
new HeartbeatManager({ interval: 5000, maxMissedHeartbeats: 10 }),
new ReClusterManager({ restartMode: "rolling" })
);
manager.spawn({ timeout: -1 })
.catch((e) => {
Error('manager spawn error')
});
// edit
process.on('uncaughtException', (err, origin) => {
fs.writeSync(
process.stderr.fd,
`Caught exception: ${err}\n` +
`Exception origin: ${origin}\n`,
);
});
process.on("unhandledRejection", async (reason, promise) => {
});
})();