apps/bot/src/lib/structures/ComponentRegistry.ts (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
import type { Interaction } from "discord.js";
import type { ComponentDefinition } from "./ComponentDefinition";
export interface RegisteredComponent<Int extends Interaction, Args extends string[]> {
definition: ComponentDefinition<any, Args>;
run(interaction: Int, args: Args): unknown | Promise<unknown>;
}
export class ComponentRegistry<Int extends Interaction> {
private registry = new Map<string, RegisteredComponent<Int, any>>();
public register<Args extends string[]>(
definition: ComponentDefinition<any, Args>,
run: (interaction: Int, args: Args) => unknown | Promise<unknown>,
) {
this.registry.set(definition.id, { definition, run });
}
public get(id: string) {
return this.registry.get(id);
}
}
|