A powerful and extendable Discord bot, with it's own module system :3 thevoid.cafe/projects/voidy
at develop 37 lines 1.2 kB view raw
1import type { ResourceStep } from "../../types/Step"; 2import type { Resource, EventResource } from "../../types/Resource"; 3import type { VoidyClient } from "../../core/VoidyClient"; 4import type { ResourceCache } from "../../core/cache"; 5import { createEventContext } from "../../core/context"; 6 7export const eventStep: ResourceStep = { 8 name: "event", 9 10 match(resource: Resource): boolean { 11 return resource.type === "event"; 12 }, 13 14 process(resource: Resource, { cache }): Resource | null { 15 const evt = resource as EventResource; 16 17 if (!evt.id || !evt.name || !evt.execute) { 18 console.warn(`[EventStep] Skipping invalid event: missing id, name, or execute`); 19 return null; 20 } 21 22 cache.set("event", evt.id, evt); 23 return evt; 24 }, 25 26 finalize(client: VoidyClient, cache: ResourceCache): void { 27 const events = cache.getAll<EventResource>("event"); 28 29 for (const [, evt] of events) { 30 const ctx = createEventContext(client, evt); 31 const handler = (...args: unknown[]) => evt.execute(ctx, ...args); 32 33 if (evt.once) client.once(evt.name, handler); 34 else client.on(evt.name, handler); 35 } 36 }, 37};