Something went wrong. Try again.
Yet another Fluxer bot built with TypeScript and Bun
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233import path from "node:path";import type { CommandRegistry } from "./commandRegistry";import { isCommandCtor } from "@/utils";import { Logger } from "tslog";
const logger = new Logger({ type: "pretty", name: "loadCommands",});
export async function loadCommands( registry: CommandRegistry, prefix: string, pattern = "src/commands/**/*.ts",): Promise<void> { const glob = new Bun.Glob(pattern);
for await (const file of glob.scan(".")) { const absPath = path.resolve(file);
logger.debug(`Loading "${absPath}"`);
// Import without caching. const mod = await import(Bun.pathToFileURL(absPath).href);
for (const exported of Object.values(mod)) { if (isCommandCtor(exported)) { registry.register(prefix, absPath, exported); } } }}