import dotenv from 'dotenv'; dotenv.config(); import WorkflowOrchestrator from './workflows/WorkflowOrchestrator'; import rDramaSession from './rdrama/session/SessionManager'; import redditSession from './reddit/session/SessionManager'; import { CommentParser } from './rdrama/services/CommentParser'; import { DatabaseInitializer } from './db/initializeDatabase'; import { DatabaseService } from './db/services/Database'; import { DatabaseMaintenanceService } from './db/services/DatabaseMaintenance'; import { CommentProcessor } from './rdrama/services/CommentProcessor'; import { MessageService } from './utils/MessageService'; import { CommentPoster } from './rdrama/services/CommentPoster'; // Import other necessary services or configurations async function startApplication() { console.log('Database Start') const databaseInitializer = DatabaseInitializer.getInstance(); const db = await databaseInitializer.getDbInstance() if (!db) { throw new Error('Failed to initialize the database.'); } const databaseService = new DatabaseService(db) const canSend = await databaseService.canSendNotification(); const coolDownHours = process.env.NOTIFICATION_COOLDOWN_HOURS if (!canSend) { console.log(`Last Message Sent less than ${coolDownHours ? coolDownHours : 4} hours ago. Set NOTIFICATION_COOLDOWN_HOURS to change this`) return; } console.log('RDrama Session Start') // Initialize SessionManager or other global configurations const rDramaSessionManager = rDramaSession.getInstance(); if (!process.env.RDRAMA_API_KEY) { throw new Error('RDRAMA_API_KEY is undefined. Please set this environment variable.'); } rDramaSessionManager.setAuthorizationToken(process.env.RDRAMA_API_KEY); console.log('Database Maintenance Start') const databaseMaintenance = new DatabaseMaintenanceService(databaseService) await databaseMaintenance.runMaintenanceTasks() console.log('Reddit Session Start') await redditSession.getInstance(databaseService) // Initialize services with any required dependencies const commentFetcher = new CommentProcessor(databaseService); const commentParser = new CommentParser(); const commentPoster = new CommentPoster() const messageService = new MessageService(); // Initialize and start your workflow const workflowOrchestrator = new WorkflowOrchestrator( commentFetcher, commentParser, commentPoster, messageService, databaseService, ); await workflowOrchestrator.executeWorkflow(); } startApplication() .then(() => console.log('Application started successfully.')) .catch((error) => console.error('Application failed to start:', error));