Update
This commit is contained in:
1 parent
c552956516
commit
0c5ffc5001
5 files changed
+88
-7
No files matched your search
@@ -56,6 +56,12 @@ export function loadConfig(): Config {
|
||||
}
|
||||
rawConfig.openrouter.apiKey = process.env.OPENROUTER_API_KEY || rawConfig.openrouter.apiKey;
|
||||
|
||||
// Override browser settings from environment
|
||||
if (process.env.BROWSER_HEADLESS !== undefined) {
|
||||
if (!rawConfig.browser) rawConfig.browser = {};
|
||||
rawConfig.browser.headless = process.env.BROWSER_HEADLESS === 'true';
|
||||
}
|
||||
|
||||
if (!rawConfig.openrouter.apiKey) {
|
||||
throw new Error('OPENROUTER_API_KEY environment variable is required');
|
||||
}
|
||||
|
||||
+25
-7
@@ -30,10 +30,8 @@ export class WebServer {
|
||||
private app: express.Application;
|
||||
private server: Server | null = null;
|
||||
private activityLog: ActivityItem[] = [];
|
||||
private botStats = {
|
||||
isRunning: true,
|
||||
messagesThisHour: 0,
|
||||
};
|
||||
private botRunning = false; // Start stopped
|
||||
private messagesThisHour = 0;
|
||||
|
||||
constructor(
|
||||
private port: number,
|
||||
@@ -75,25 +73,45 @@ export class WebServer {
|
||||
res.json(successful);
|
||||
});
|
||||
|
||||
// API: Start bot
|
||||
this.app.post('/api/start', (req, res) => {
|
||||
this.botRunning = true;
|
||||
this.logActivity('sent', 'Bot started by user');
|
||||
this.logger.info('Bot started via web UI');
|
||||
res.json({ success: true, running: true });
|
||||
});
|
||||
|
||||
// API: Stop bot
|
||||
this.app.post('/api/stop', (req, res) => {
|
||||
this.botRunning = false;
|
||||
this.logActivity('skipped', 'Bot stopped by user');
|
||||
this.logger.info('Bot stopped via web UI');
|
||||
res.json({ success: true, running: false });
|
||||
});
|
||||
|
||||
// Serve dashboard for all other routes
|
||||
this.app.get('*', (req, res) => {
|
||||
res.sendFile(path.join(process.cwd(), 'public', 'index.html'));
|
||||
});
|
||||
}
|
||||
|
||||
isRunning(): boolean {
|
||||
return this.botRunning;
|
||||
}
|
||||
|
||||
private getStats(): BotStats {
|
||||
const messages = this.messagesRepo.getRecent(1000);
|
||||
const totalSent = messages.length;
|
||||
const totalResponses = messages.filter((m) => m.gotResponse).length;
|
||||
|
||||
return {
|
||||
isRunning: this.botStats.isRunning,
|
||||
isRunning: this.botRunning,
|
||||
dryRunMode: this.config.browser.dryRun,
|
||||
totalProcessed: this.getTotalProcessed(),
|
||||
totalMessagesSent: totalSent,
|
||||
totalResponses,
|
||||
responseRate: totalSent > 0 ? Math.round((totalResponses / totalSent) * 100) : 0,
|
||||
messagesThisHour: this.botStats.messagesThisHour,
|
||||
messagesThisHour: this.messagesThisHour,
|
||||
maxMessagesPerHour: this.config.rateLimit.maxMessagesPerHour,
|
||||
subreddits: this.config.reddit.subreddits,
|
||||
targetGenders: this.config.reddit.targetGenders,
|
||||
@@ -122,7 +140,7 @@ export class WebServer {
|
||||
}
|
||||
|
||||
updateStats(messagesThisHour: number): void {
|
||||
this.botStats.messagesThisHour = messagesThisHour;
|
||||
this.messagesThisHour = messagesThisHour;
|
||||
}
|
||||
|
||||
start(): void {
|
||||
|
||||
Reference in new issue
Block a user