a
This commit is contained in:
parent
f434b91e42
commit
6db9f29b26
43
api.js
Normal file
43
api.js
Normal file
|
@ -0,0 +1,43 @@
|
|||
// API Server entry point
|
||||
const path = require('path');
|
||||
require('dotenv').config();
|
||||
|
||||
// Global variable to hold our service
|
||||
let apiServer;
|
||||
|
||||
async function startServer() {
|
||||
try {
|
||||
// Start API server
|
||||
console.log('Starting API server...');
|
||||
apiServer = require('./api/server');
|
||||
console.log('API server started successfully');
|
||||
console.log('API server fully operational');
|
||||
} catch (error) {
|
||||
console.error('Error starting API server:', error);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// Handle graceful shutdown
|
||||
async function shutdown(signal) {
|
||||
console.log(`Received ${signal}. Shutting down API server gracefully...`);
|
||||
|
||||
// Add API server shutdown logic here if needed
|
||||
// For example: apiServer.close()
|
||||
|
||||
console.log('API server shutdown complete');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
// Register shutdown handlers
|
||||
process.on('SIGINT', () => shutdown('SIGINT'));
|
||||
process.on('SIGTERM', () => shutdown('SIGTERM'));
|
||||
|
||||
// Catch uncaught exceptions
|
||||
process.on('uncaughtException', (error) => {
|
||||
console.error('Uncaught exception in API server:', error);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
// Start server
|
||||
startServer();
|
60
discord.js
Normal file
60
discord.js
Normal file
|
@ -0,0 +1,60 @@
|
|||
// Discord Bot entry point
|
||||
const path = require('path');
|
||||
require('dotenv').config();
|
||||
|
||||
// Import the Bot class
|
||||
const Bot = require('./discord/classes/Bot');
|
||||
|
||||
// Global variable to hold our bot
|
||||
let discordBot;
|
||||
|
||||
async function startBot() {
|
||||
try {
|
||||
// Initialize and start Discord bot
|
||||
console.log('Starting Discord bot...');
|
||||
discordBot = new Bot();
|
||||
await discordBot.start();
|
||||
console.log('Discord bot started successfully');
|
||||
console.log('Discord bot fully operational');
|
||||
} catch (error) {
|
||||
console.error('Error starting Discord bot:', error);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// Handle graceful shutdown
|
||||
async function shutdown(signal) {
|
||||
console.log(`Received ${signal}. Shutting down Discord bot gracefully...`);
|
||||
|
||||
// Shutdown Discord bot if it exists
|
||||
if (discordBot) {
|
||||
try {
|
||||
await discordBot.sendShutdownNotification(`Manual shutdown triggered by ${signal}`);
|
||||
await discordBot.stop();
|
||||
console.log('Discord bot shutdown complete');
|
||||
} catch (error) {
|
||||
console.error('Error shutting down Discord bot:', error);
|
||||
}
|
||||
}
|
||||
|
||||
console.log('Discord bot shutdown complete');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
// Register shutdown handlers
|
||||
process.on('SIGINT', () => shutdown('SIGINT'));
|
||||
process.on('SIGTERM', () => shutdown('SIGTERM'));
|
||||
|
||||
// Catch uncaught exceptions
|
||||
process.on('uncaughtException', (error) => {
|
||||
console.error('Uncaught exception in Discord bot:', error);
|
||||
if (discordBot) {
|
||||
discordBot.sendShutdownNotification('Uncaught exception', error)
|
||||
.finally(() => process.exit(1));
|
||||
} else {
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
|
||||
// Start bot
|
||||
startBot();
|
Loading…
Reference in a new issue