UNPKG

@gwigz/homunculus-bot

Version:

A bot framework for creating Second Life bots with chat commands and LSL communication

26 lines (25 loc) 1.32 kB
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 ApiHandlerOptions<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 ApiHandler { private client; private prefix; private separator; private channel; private handlers; private onError?; constructor(client: Client, options: BotOptions); registerHandler<F extends Format = "string", Schema extends ZodType<any, any> | undefined = undefined>(handler: ApiHandlerOptions<F, Schema>): void; handleChatMessage(chat: NearbyChatMessage): Promise<void>; private parseData; } export {};