shirosaki-napcatsdk
Version:
全新的,省心的,NapCatQQ SDK
73 lines (72 loc) • 2.4 kB
TypeScript
import { type anyobject, type EnumKeys } from "@ceale/util";
import type { Logger } from "./interface/Logger";
import { NCMessage } from "./service/NCMessage";
export interface NCClientConfig {
/** 连接 NapCat 的 token */
token?: string | null;
/** 默认 `5000`。超时时长`(ms)`,为`-1`将不限时地等待。
*
* 用于等待sendAction的响应、初次连接后等待`meta_event.connect`等 */
timeout?: number;
/** 重连设置 */
retry?: {
/** 默认 `5000`。重连间隔`(ms)` */
interval?: number;
/** 默认 `5`。重连次数限制。
*
* 为`0`则不尝试重连,为`-1`则不限次数地尝试重连 */
limit?: number;
};
/** 默认 `console`。日志器 */
logger?: Logger;
/** 默认 `false`。是否开启调试模式。
*
* 调试模式下会输出所有发出和接收到的数据等内容 */
debug?: boolean;
}
export declare const NapcatClientState: {
CLOSE: "CLOSE";
OPEN: "OPEN";
};
export declare class NapCatClient {
private url;
private token;
private debug;
private timeout;
private logger;
private wsManager;
private _state;
get state(): EnumKeys<{
CLOSE: "CLOSE";
OPEN: "OPEN";
}>;
get wsState(): EnumKeys<{
CONNECT: "CONNECT";
ACTIVE: "ACTIVE";
CLOSE: "CLOSE";
}>;
Message: NCMessage;
/**
* @param url NapCat 的正向 WS 服务端地址
* @param config 配置项,详见 {@link NCClientConfig}
*/
constructor(url: string, config?: NCClientConfig);
connect(): Promise<boolean>;
close(): Promise<boolean>;
sendData(data: any): boolean;
private dataHandler;
private dataMap;
onData(handler: (data: any) => void): void;
offData(handler: (data: any) => void): void;
private actionMap;
sendAction(action: string, params?: object): Promise<anyobject>;
private actionRespHandler;
private eventMap;
private postDataHandler;
onEvent(handler: (data: any) => void): void;
onEvent(eventName: string, handler: (data: any) => void): void;
onceEvent(handler: (data: any) => void): void;
onceEvent(eventName: string, handler: (data: any) => void): void;
offEvent(handler: (data: any) => void): void;
offEvent(eventName: string, handler: (data: any) => void): void;
}