UNPKG

@hank.chat/pdk

Version:
72 lines (71 loc) 3.3 kB
import { AccessCheck, AccessCheckChain, AccessCheckOperator, ChatCommandInput, ChatMessageInput, HankClientImpl, Message, Metadata, PreparedStatement } from "@hank.chat/types"; import { JsonObject } from "type-fest"; import "polyfill-crypto-methods"; declare class Hank { protected client: HankClientImpl; protected metadata: Metadata | undefined; protected chatMessageHandler: Function | undefined; protected chatCommandHandler: Function | undefined; protected installFn: Function | undefined; protected initializeFn: Function | undefined; protected cronjobs: Map<string, Function>; constructor(); sendMessage(message: Message): void; react(emoji: string, message: Message): void; dbQuery<T extends JsonObject>(preparedStatement: PreparedStatement): Promise<Array<T>>; cron(cron: string, job: Function): void; oneShot(duration: number, job: Function): void; datetime(): Promise<Date>; reloadPlugin(plugin: string): void; get pluginMetadata(): Metadata; set pluginMetadata(metadata: Metadata); registerChatMessageHandler(handler: Function): void; handleChatMessage(input: ChatMessageInput): void; registerChatCommandHandler(handler: Function): void; handleChatCommand({ context, message }: ChatCommandInput): void; registerInstallFunction(fn: Function): void; handleInstall(): void; registerInitializeFunction(fn: Function): void; handleInitialize(): void; handleCron(uuid: string): void; } export declare const hank: Hank; export declare function handle_chat_message(): void; export declare function handle_chat_command(): void; export declare function handle_scheduled_job(): void; export declare function handle_get_metadata(): void; export declare function handle_install(): void; export declare function handle_initialize(): void; type OneOfKeyValueUnion<T> = T extends { $case: infer U extends string; "value": infer V; } ? { [Property in U]: V; } : never; type AccessCheckShorthand = OneOfKeyValueUnion<AccessCheck["kind"]>; type AccessCheckOperators = Exclude<keyof typeof AccessCheckOperator, "UNRECOGNIZED">; type AccessCheckChainShorthand = Partial<Record<AccessCheckOperators, AccessCheckShorthand[]>>; export interface PluginMetadata extends Omit<Metadata, "accessChecks"> { accessChecks: AccessCheckChain | AccessCheckChainShorthand | AccessCheck | AccessCheckShorthand[] | AccessCheckShorthand | undefined; } export declare const PluginMetadata: MessageFns<PluginMetadata, Metadata>; type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; type DeepPartial<T> = T extends Builtin ? T : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends { $case: string; value: unknown; } ? { $case: T["$case"]; value?: DeepPartial<T["value"]>; } : T extends {} ? { [K in keyof T]?: DeepPartial<T[K]>; } : Partial<T>; type KeysOfUnion<T> = T extends T ? keyof T : never; type Exact<P, I extends P> = P extends Builtin ? P : P & { [K in keyof P]: Exact<P[K], I[K]>; } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never; }; interface MessageFns<T, M> { create<I extends Exact<DeepPartial<T>, I>>(base?: I): M; } export {};