@gwigz/homunculus-bot
Version:
A bot framework for creating Second Life bots with chat commands and LSL communication
24 lines (23 loc) • 1.28 kB
TypeScript
import { type Client, type NearbyChatMessage } from "@gwigz/homunculus-core";
import type { ZodType, z } from "zod/v4";
import type { BotOptions } from "./bot";
type Format = "json" | "string";
type InferTypeFromFormat<F extends Format> = F extends "string" ? string : unknown;
type SchemaOutput<F extends Format, Schema extends ZodType<any, any> | undefined> = Schema extends undefined ? InferTypeFromFormat<F> : z.infer<NonNullable<Schema>>;
export interface CommandHandlerOptions<F extends Format = "string", Schema extends ZodType<any, any> | undefined = undefined> {
action: string;
process: (client: Client, data: SchemaOutput<F, Schema>, message: NearbyChatMessage) => Promise<string> | Promise<void> | string | void;
format?: Schema extends undefined ? F : Schema extends ZodType<any, string> ? "string" : F;
schema?: Schema;
}
export declare class CommandHandler {
private client;
private prefix;
private commands;
private onError?;
constructor(client: Client, options: BotOptions);
registerCommand<F extends Format = "string", Schema extends ZodType<any, any> | undefined = undefined>(command: CommandHandlerOptions<F, Schema>): void;
handleChatMessage(chat: NearbyChatMessage): Promise<void>;
private parseData;
}
export {};