troutbot/src/events.ts
NotAShelf f8db097ba9
initial commit
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: Ic08e7c4b5b4f4072de9e2f9a701e977b6a6a6964
2026-01-31 02:59:53 +03:00

40 lines
784 B
TypeScript

import type { WebhookEvent, AnalysisResult } from './types.js';
export interface EventEntry {
id: number;
timestamp: string;
event: WebhookEvent;
result: Record<string, unknown>;
analysis?: AnalysisResult;
}
const MAX_ENTRIES = 100;
const buffer: EventEntry[] = [];
let nextId = 1;
export function recordEvent(
event: WebhookEvent,
result: Record<string, unknown>,
analysis?: AnalysisResult
): void {
const entry: EventEntry = {
id: nextId++,
timestamp: new Date().toISOString(),
event,
result,
analysis,
};
buffer.push(entry);
if (buffer.length > MAX_ENTRIES) {
buffer.shift();
}
}
export function getRecentEvents(): EventEntry[] {
return [...buffer].reverse();
}
export function clearEvents(): void {
buffer.length = 0;
}