import type { ResourceStep } from "../../types/Step"; import type { Resource, EventResource } from "../../types/Resource"; import type { VoidyClient } from "../../core/VoidyClient"; import type { ResourceCache } from "../../core/cache"; import { createEventContext } from "../../core/context"; export const eventStep: ResourceStep = { name: "event", match(resource: Resource): boolean { return resource.type === "event"; }, process(resource: Resource, { cache }): Resource | null { const evt = resource as EventResource; if (!evt.id || !evt.name || !evt.execute) { console.warn(`[EventStep] Skipping invalid event: missing id, name, or execute`); return null; } cache.set("event", evt.id, evt); return evt; }, finalize(client: VoidyClient, cache: ResourceCache): void { const events = cache.getAll("event"); for (const [, evt] of events) { const ctx = createEventContext(client, evt); const handler = (...args: unknown[]) => evt.execute(ctx, ...args); if (evt.once) client.once(evt.name, handler); else client.on(evt.name, handler); } }, };