const { ClusterManager } = require('status-sharding'); const { logger } = require('./utils'); const express = require('express'); const app = express(); const port = 25634; // Use the port specified in the environment variable or fallback to 3000 const path = require('path'); require('dotenv').config(); process.on('unhandledRejection', (error) => { logger.error(`[SYSTEM] Unhandled Rejection: ${error.stack || error}`); }); process.on('uncaughtException', (error) => { logger.error(`[SYSTEM] Uncaught Exception: ${error.stack || error}`); }); process.on('uncaughtExceptionMonitor', (error) => { logger.error(`[SYSTEM] Uncaught Exception (Monitor): ${error.stack || error}`); }); process.on('warning', (warning) => { logger.warn(`[SYSTEM] Warning: ${warning.name} - ${warning.message}`); }); process.on('exit', (code) => { logger.log(`[SYSTEM] Process exiting with code: ${code}`); }); process.on('beforeExit', (code) => { logger.log(`[SYSTEM] Process about to exit with code: ${code}`); }); process.on('disconnect', () => { logger.warn('[SYSTEM] IPC channel disconnected'); }); const manager = new ClusterManager(path.join(__dirname, 'bot.js'), { mode: 'process', token: process.env.token, totalShards: 2, totalClusters: 1, spawnOptions: { timeout: 30000, delay: 8000, }, }); manager.on('clusterCreate', (cluster) => { logger.log(`[SYSTEM] [ClusterID: ${cluster.id}] Launched`); cluster.on('ready', () => logger.ready(`[SYSTEM] [ClusterID: ${cluster.id}] is ready`)); cluster.on('death', () => { logger.log(`[SYSTEM] [ClusterID: ${cluster.id}] died`); logger.log(`[SYSTEM] [ClusterID: ${cluster.id}] Attempting to respawn...`); cluster .respawn() .then(() => { logger.log(`[SYSTEM] [ClusterID: ${cluster.id}] Successfully respawned`); }) .catch((error) => { logger.error(`[SYSTEM] [ClusterID: ${cluster.id}] Failed to respawn: ${error}`); }); }); cluster.on('error', () => logger.error(`[SYSTEM] [ClusterID: ${cluster.id}] errored`)); cluster.on('spawn', () => logger.log(`[SYSTEM] [ClusterID: ${cluster.id}] has spawned`)); }); manager.spawn(); // Serve TOS page app.get('/tos', (req, res) => { res.sendFile(path.join(__dirname, 'html', 'tos.html')); }); // Serve Privacy Policy page app.get('/privacy', (req, res) => { res.sendFile(path.join(__dirname, 'html', 'privacy.html')); }); // Start the HTTP server app.get('/', (req, res) => { res.send('Page under construction!'); }); app.listen(port, () => { logger.log(`Server is listening on port ${port}`); });