@naplink/naplink 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +95 -0
- package/dist/index.d.ts +745 -0
- package/dist/index.js +1572 -0
- package/dist/index.js.map +1 -0
- package/package.json +57 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,745 @@
|
|
|
1
|
+
import EventEmitter from 'events';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* NapLink 配置接口
|
|
5
|
+
* 提供完整的配置选项,所有参数都有合理的默认值
|
|
6
|
+
*/
|
|
7
|
+
interface NapLinkConfig {
|
|
8
|
+
/** 连接配置 */
|
|
9
|
+
connection: {
|
|
10
|
+
/** WebSocket 服务器 URL */
|
|
11
|
+
url: string;
|
|
12
|
+
/** 访问令牌(可选) */
|
|
13
|
+
token?: string;
|
|
14
|
+
/** 连接超时时间(毫秒) */
|
|
15
|
+
timeout?: number;
|
|
16
|
+
/** 心跳间隔(毫秒,0表示禁用) */
|
|
17
|
+
pingInterval?: number;
|
|
18
|
+
/** 自定义心跳动作(默认 get_status) */
|
|
19
|
+
heartbeatAction?: {
|
|
20
|
+
action: string;
|
|
21
|
+
params?: Record<string, any>;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
/** 重连配置 */
|
|
25
|
+
reconnect: {
|
|
26
|
+
/** 是否启用自动重连 */
|
|
27
|
+
enabled: boolean;
|
|
28
|
+
/** 最大重连次数 */
|
|
29
|
+
maxAttempts: number;
|
|
30
|
+
/** 指数退避配置 */
|
|
31
|
+
backoff: {
|
|
32
|
+
/** 初始延迟(毫秒) */
|
|
33
|
+
initial: number;
|
|
34
|
+
/** 最大延迟(毫秒) */
|
|
35
|
+
max: number;
|
|
36
|
+
/** 退避倍数 */
|
|
37
|
+
multiplier: number;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
/** 日志配置 */
|
|
41
|
+
logging: {
|
|
42
|
+
/** 日志等级 */
|
|
43
|
+
level: 'debug' | 'info' | 'warn' | 'error' | 'off';
|
|
44
|
+
/** 自定义logger(可选) */
|
|
45
|
+
logger?: Logger;
|
|
46
|
+
};
|
|
47
|
+
/** API配置 */
|
|
48
|
+
api: {
|
|
49
|
+
/** API调用超时时间(毫秒) */
|
|
50
|
+
timeout: number;
|
|
51
|
+
/** 失败重试次数 */
|
|
52
|
+
retries: number;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* 日志接口
|
|
57
|
+
* 允许用户提供自定义logger实现
|
|
58
|
+
*/
|
|
59
|
+
interface Logger {
|
|
60
|
+
debug(message: string, ...meta: any[]): void;
|
|
61
|
+
info(message: string, ...meta: any[]): void;
|
|
62
|
+
warn(message: string, ...meta: any[]): void;
|
|
63
|
+
error(message: string, error?: Error, ...meta: any[]): void;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* 部分配置类型(用于构造函数)
|
|
67
|
+
* 用户只需提供必要的配置,其他使用默认值
|
|
68
|
+
*/
|
|
69
|
+
type PartialNapLinkConfig = {
|
|
70
|
+
connection: {
|
|
71
|
+
url: string;
|
|
72
|
+
token?: string;
|
|
73
|
+
timeout?: number;
|
|
74
|
+
pingInterval?: number;
|
|
75
|
+
heartbeatAction?: {
|
|
76
|
+
action: string;
|
|
77
|
+
params?: Record<string, any>;
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
reconnect?: Partial<NapLinkConfig['reconnect']>;
|
|
81
|
+
logging?: Partial<NapLinkConfig['logging']>;
|
|
82
|
+
api?: Partial<NapLinkConfig['api']>;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* WebSocket 连接状态
|
|
87
|
+
*/
|
|
88
|
+
declare enum ConnectionState {
|
|
89
|
+
DISCONNECTED = "disconnected",
|
|
90
|
+
CONNECTING = "connecting",
|
|
91
|
+
CONNECTED = "connected",
|
|
92
|
+
RECONNECTING = "reconnecting"
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* WebSocket 连接管理器
|
|
97
|
+
* 负责管理连接生命周期、重连、心跳等
|
|
98
|
+
*/
|
|
99
|
+
declare class ConnectionManager {
|
|
100
|
+
private config;
|
|
101
|
+
private logger;
|
|
102
|
+
private onMessage;
|
|
103
|
+
private onStateChange;
|
|
104
|
+
private ws?;
|
|
105
|
+
private state;
|
|
106
|
+
private reconnectService;
|
|
107
|
+
private heartbeatService?;
|
|
108
|
+
private connectPromise?;
|
|
109
|
+
private connectTimeout?;
|
|
110
|
+
constructor(config: NapLinkConfig, logger: Logger, onMessage: (data: string) => void, onStateChange: (state: ConnectionState) => void);
|
|
111
|
+
/**
|
|
112
|
+
* 连接到WebSocket服务器
|
|
113
|
+
*/
|
|
114
|
+
connect(): Promise<void>;
|
|
115
|
+
/**
|
|
116
|
+
* 执行实际的连接逻辑
|
|
117
|
+
*/
|
|
118
|
+
private performConnect;
|
|
119
|
+
/**
|
|
120
|
+
* 断开连接
|
|
121
|
+
* @param code 关闭代码
|
|
122
|
+
* @param reason 关闭原因
|
|
123
|
+
*/
|
|
124
|
+
disconnect(code?: number, reason?: string): void;
|
|
125
|
+
/**
|
|
126
|
+
* 发送数据
|
|
127
|
+
*/
|
|
128
|
+
send(data: string): void;
|
|
129
|
+
/**
|
|
130
|
+
* 获取当前状态
|
|
131
|
+
*/
|
|
132
|
+
getState(): ConnectionState;
|
|
133
|
+
/**
|
|
134
|
+
* 检查是否已连接
|
|
135
|
+
*/
|
|
136
|
+
isConnected(): boolean;
|
|
137
|
+
/**
|
|
138
|
+
* 设置状态并通知
|
|
139
|
+
*/
|
|
140
|
+
private setState;
|
|
141
|
+
/**
|
|
142
|
+
* 停止心跳
|
|
143
|
+
*/
|
|
144
|
+
private stopHeartbeat;
|
|
145
|
+
/**
|
|
146
|
+
* 处理心跳超时
|
|
147
|
+
*/
|
|
148
|
+
private handleHeartbeatTimeout;
|
|
149
|
+
/**
|
|
150
|
+
* 处理连接关闭并尝试重连
|
|
151
|
+
*/
|
|
152
|
+
private clearConnectTimeout;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* API客户端
|
|
157
|
+
* 负责发送API请求并处理响应
|
|
158
|
+
* 支持超时控制、自动重试、请求清理
|
|
159
|
+
*/
|
|
160
|
+
declare class ApiClient {
|
|
161
|
+
private connection;
|
|
162
|
+
private config;
|
|
163
|
+
private logger;
|
|
164
|
+
private readonly registry;
|
|
165
|
+
private cleanupTimer?;
|
|
166
|
+
private requestIdCounter;
|
|
167
|
+
constructor(connection: ConnectionManager, config: NapLinkConfig, logger: Logger);
|
|
168
|
+
/**
|
|
169
|
+
* 调用API
|
|
170
|
+
* @param method API方法名
|
|
171
|
+
* @param params API参数
|
|
172
|
+
* @param options 调用选项
|
|
173
|
+
*/
|
|
174
|
+
call<T = any>(method: string, params?: any, options?: {
|
|
175
|
+
timeout?: number;
|
|
176
|
+
retries?: number;
|
|
177
|
+
}): Promise<T>;
|
|
178
|
+
/**
|
|
179
|
+
* 处理API响应
|
|
180
|
+
* 由连接管理器调用
|
|
181
|
+
*/
|
|
182
|
+
handleResponse(echo: string, response: any): void;
|
|
183
|
+
/**
|
|
184
|
+
* 销毁API客户端
|
|
185
|
+
*/
|
|
186
|
+
destroy(): void;
|
|
187
|
+
/**
|
|
188
|
+
* 发送API请求
|
|
189
|
+
*/
|
|
190
|
+
private sendRequest;
|
|
191
|
+
/**
|
|
192
|
+
* 延迟
|
|
193
|
+
*/
|
|
194
|
+
private delay;
|
|
195
|
+
/**
|
|
196
|
+
* 生成请求ID
|
|
197
|
+
*/
|
|
198
|
+
private generateRequestId;
|
|
199
|
+
/**
|
|
200
|
+
* 启动清理定时器
|
|
201
|
+
* 定期清理超时的待处理请求
|
|
202
|
+
*/
|
|
203
|
+
private startCleanupTimer;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* OneBot 11 Protocol Base Types
|
|
208
|
+
*/
|
|
209
|
+
type PostType = 'message' | 'notice' | 'request' | 'meta_event';
|
|
210
|
+
interface BaseEvent {
|
|
211
|
+
time: number;
|
|
212
|
+
self_id: number;
|
|
213
|
+
post_type: PostType;
|
|
214
|
+
}
|
|
215
|
+
type MessageSegment = any;
|
|
216
|
+
|
|
217
|
+
interface MessageEvent extends BaseEvent {
|
|
218
|
+
post_type: 'message';
|
|
219
|
+
message_type: 'private' | 'group';
|
|
220
|
+
sub_type: string;
|
|
221
|
+
message_id: number;
|
|
222
|
+
user_id: number;
|
|
223
|
+
message: MessageSegment[];
|
|
224
|
+
raw_message: string;
|
|
225
|
+
font: number;
|
|
226
|
+
sender: Sender;
|
|
227
|
+
}
|
|
228
|
+
interface PrivateMessageEvent extends MessageEvent {
|
|
229
|
+
message_type: 'private';
|
|
230
|
+
sub_type: 'friend' | 'group' | 'other';
|
|
231
|
+
target_id: number;
|
|
232
|
+
}
|
|
233
|
+
interface GroupMessageEvent extends MessageEvent {
|
|
234
|
+
message_type: 'group';
|
|
235
|
+
sub_type: 'normal' | 'anonymous' | 'notice';
|
|
236
|
+
group_id: number;
|
|
237
|
+
anonymous?: Anonymous;
|
|
238
|
+
}
|
|
239
|
+
interface Sender {
|
|
240
|
+
user_id?: number;
|
|
241
|
+
nickname?: string;
|
|
242
|
+
sex?: 'male' | 'female' | 'unknown';
|
|
243
|
+
age?: number;
|
|
244
|
+
card?: string;
|
|
245
|
+
area?: string;
|
|
246
|
+
level?: string;
|
|
247
|
+
role?: 'owner' | 'admin' | 'member';
|
|
248
|
+
title?: string;
|
|
249
|
+
}
|
|
250
|
+
interface Anonymous {
|
|
251
|
+
id: number;
|
|
252
|
+
name: string;
|
|
253
|
+
flag: string;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
interface FileInfo {
|
|
257
|
+
id: string;
|
|
258
|
+
name: string;
|
|
259
|
+
size: number;
|
|
260
|
+
busid: number;
|
|
261
|
+
}
|
|
262
|
+
interface GroupInviteRequest {
|
|
263
|
+
request_id?: number;
|
|
264
|
+
invitor_uin: number;
|
|
265
|
+
invitor_nick?: string;
|
|
266
|
+
group_id: number;
|
|
267
|
+
group_name?: string;
|
|
268
|
+
checked: boolean;
|
|
269
|
+
actor?: number;
|
|
270
|
+
}
|
|
271
|
+
interface GroupJoinRequest {
|
|
272
|
+
request_id?: number;
|
|
273
|
+
user_id: number;
|
|
274
|
+
nickname?: string;
|
|
275
|
+
group_id: number;
|
|
276
|
+
group_name?: string;
|
|
277
|
+
comment?: string;
|
|
278
|
+
checked: boolean;
|
|
279
|
+
actor?: number;
|
|
280
|
+
}
|
|
281
|
+
interface GroupSystemMessages {
|
|
282
|
+
invited_requests: GroupInviteRequest[];
|
|
283
|
+
join_requests: GroupJoinRequest[];
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
interface NoticeEvent extends BaseEvent {
|
|
287
|
+
post_type: 'notice';
|
|
288
|
+
notice_type: string;
|
|
289
|
+
}
|
|
290
|
+
interface GroupRecallNotice extends NoticeEvent {
|
|
291
|
+
notice_type: 'group_recall';
|
|
292
|
+
group_id: number;
|
|
293
|
+
user_id: number;
|
|
294
|
+
operator_id: number;
|
|
295
|
+
message_id: number;
|
|
296
|
+
}
|
|
297
|
+
interface FriendRecallNotice extends NoticeEvent {
|
|
298
|
+
notice_type: 'friend_recall';
|
|
299
|
+
user_id: number;
|
|
300
|
+
message_id: number;
|
|
301
|
+
}
|
|
302
|
+
interface GroupUploadNotice extends NoticeEvent {
|
|
303
|
+
notice_type: 'group_upload';
|
|
304
|
+
group_id: number;
|
|
305
|
+
user_id: number;
|
|
306
|
+
file: FileInfo;
|
|
307
|
+
}
|
|
308
|
+
interface GroupAdminNotice extends NoticeEvent {
|
|
309
|
+
notice_type: 'group_admin';
|
|
310
|
+
sub_type: 'set' | 'unset';
|
|
311
|
+
group_id: number;
|
|
312
|
+
user_id: number;
|
|
313
|
+
}
|
|
314
|
+
interface GroupDecreaseNotice extends NoticeEvent {
|
|
315
|
+
notice_type: 'group_decrease';
|
|
316
|
+
sub_type: 'leave' | 'kick' | 'kick_me';
|
|
317
|
+
group_id: number;
|
|
318
|
+
operator_id: number;
|
|
319
|
+
user_id: number;
|
|
320
|
+
}
|
|
321
|
+
interface GroupIncreaseNotice extends NoticeEvent {
|
|
322
|
+
notice_type: 'group_increase';
|
|
323
|
+
sub_type: 'approve' | 'invite';
|
|
324
|
+
group_id: number;
|
|
325
|
+
operator_id: number;
|
|
326
|
+
user_id: number;
|
|
327
|
+
}
|
|
328
|
+
interface FriendAddNotice extends NoticeEvent {
|
|
329
|
+
notice_type: 'friend_add';
|
|
330
|
+
user_id: number;
|
|
331
|
+
}
|
|
332
|
+
interface NotifyNotice extends NoticeEvent {
|
|
333
|
+
notice_type: 'notify';
|
|
334
|
+
sub_type: string;
|
|
335
|
+
[key: string]: any;
|
|
336
|
+
}
|
|
337
|
+
interface PokeNotice extends NotifyNotice {
|
|
338
|
+
sub_type: 'poke';
|
|
339
|
+
target_id: number;
|
|
340
|
+
user_id: number;
|
|
341
|
+
group_id?: number;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
interface RequestEvent extends BaseEvent {
|
|
345
|
+
post_type: 'request';
|
|
346
|
+
request_type: string;
|
|
347
|
+
}
|
|
348
|
+
interface FriendRequest extends RequestEvent {
|
|
349
|
+
request_type: 'friend';
|
|
350
|
+
user_id: number;
|
|
351
|
+
comment: string;
|
|
352
|
+
flag: string;
|
|
353
|
+
}
|
|
354
|
+
interface GroupRequest extends RequestEvent {
|
|
355
|
+
request_type: 'group';
|
|
356
|
+
sub_type: 'add' | 'invite';
|
|
357
|
+
group_id: number;
|
|
358
|
+
user_id: number;
|
|
359
|
+
comment: string;
|
|
360
|
+
flag: string;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
interface MetaEvent extends BaseEvent {
|
|
364
|
+
post_type: 'meta_event';
|
|
365
|
+
meta_event_type: string;
|
|
366
|
+
}
|
|
367
|
+
interface LifecycleMetaEvent extends MetaEvent {
|
|
368
|
+
meta_event_type: 'lifecycle';
|
|
369
|
+
sub_type: 'enable' | 'disable' | 'connect';
|
|
370
|
+
}
|
|
371
|
+
interface HeartbeatMetaEvent extends MetaEvent {
|
|
372
|
+
meta_event_type: 'heartbeat';
|
|
373
|
+
status: any;
|
|
374
|
+
interval: number;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
interface GroupHonorInfo {
|
|
378
|
+
group_id: number;
|
|
379
|
+
current_talkative?: any;
|
|
380
|
+
talkative_list?: any[];
|
|
381
|
+
performer_list?: any[];
|
|
382
|
+
legend_list?: any[];
|
|
383
|
+
strong_newbie_list?: any[];
|
|
384
|
+
emotion_list?: any[];
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
type MessageApi = {
|
|
388
|
+
sendMessage(params: {
|
|
389
|
+
message_type?: 'private' | 'group';
|
|
390
|
+
user_id?: number | string;
|
|
391
|
+
group_id?: number | string;
|
|
392
|
+
message: any;
|
|
393
|
+
auto_escape?: boolean;
|
|
394
|
+
}): Promise<any>;
|
|
395
|
+
sendPrivateMessage(userId: number | string, message: any): Promise<any>;
|
|
396
|
+
sendGroupMessage(groupId: number | string, message: any): Promise<any>;
|
|
397
|
+
deleteMessage(messageId: number | string): Promise<any>;
|
|
398
|
+
getMessage(messageId: number | string): Promise<any>;
|
|
399
|
+
getForwardMessage(id: string): Promise<any>;
|
|
400
|
+
sendGroupForwardMessage(groupId: number | string, messages: any[]): Promise<any>;
|
|
401
|
+
setEssenceMessage(messageId: number | string): Promise<any>;
|
|
402
|
+
deleteEssenceMessage(messageId: number | string): Promise<any>;
|
|
403
|
+
getEssenceMessageList(groupId: number | string): Promise<any>;
|
|
404
|
+
markMessageAsRead(messageId: number | string): Promise<any>;
|
|
405
|
+
getGroupAtAllRemain(groupId: number | string): Promise<number>;
|
|
406
|
+
getGroupSystemMsg(): Promise<GroupSystemMessages>;
|
|
407
|
+
getGroupHonorInfo(groupId: number | string, type: 'all' | 'talkative' | 'performer' | 'legend' | 'strong_newbie' | 'emotion'): Promise<GroupHonorInfo>;
|
|
408
|
+
};
|
|
409
|
+
|
|
410
|
+
type MediaApi = {
|
|
411
|
+
getImage(file: string): Promise<any>;
|
|
412
|
+
getRecord(file: string, outFormat?: string): Promise<any>;
|
|
413
|
+
getFile(file: string): Promise<any>;
|
|
414
|
+
hydrateMedia(message: any[]): Promise<void>;
|
|
415
|
+
};
|
|
416
|
+
|
|
417
|
+
type AccountApi = {
|
|
418
|
+
getLoginInfo(): Promise<any>;
|
|
419
|
+
getStatus(): Promise<any>;
|
|
420
|
+
getFriendList(): Promise<any>;
|
|
421
|
+
getGroupList(): Promise<any>;
|
|
422
|
+
getGroupInfo(groupId: number | string, noCache?: boolean): Promise<any>;
|
|
423
|
+
getGroupMemberList(groupId: number | string): Promise<any>;
|
|
424
|
+
getGroupMemberInfo(groupId: number | string, userId: number | string, noCache?: boolean): Promise<any>;
|
|
425
|
+
getStrangerInfo(userId: number | string, noCache?: boolean): Promise<any>;
|
|
426
|
+
getVersionInfo(): Promise<any>;
|
|
427
|
+
};
|
|
428
|
+
|
|
429
|
+
type GroupApi = {
|
|
430
|
+
setGroupBan(groupId: number | string, userId: number | string, duration?: number): Promise<any>;
|
|
431
|
+
unsetGroupBan(groupId: number | string, userId: number | string): Promise<any>;
|
|
432
|
+
setGroupWholeBan(groupId: number | string, enable?: boolean): Promise<any>;
|
|
433
|
+
setGroupKick(groupId: number | string, userId: number | string, rejectAddRequest?: boolean): Promise<any>;
|
|
434
|
+
setGroupLeave(groupId: number | string, isDismiss?: boolean): Promise<any>;
|
|
435
|
+
setGroupCard(groupId: number | string, userId: number | string, card: string): Promise<any>;
|
|
436
|
+
setGroupName(groupId: number | string, groupName: string): Promise<any>;
|
|
437
|
+
setGroupAdmin(groupId: number | string, userId: number | string, enable?: boolean): Promise<any>;
|
|
438
|
+
setGroupAnonymousBan(groupId: number | string, anonymousFlag: string, duration?: number): Promise<any>;
|
|
439
|
+
setGroupSpecialTitle(groupId: number | string, userId: number | string, specialTitle: string, duration?: number): Promise<any>;
|
|
440
|
+
sendLike(userId: number | string, times?: number): Promise<any>;
|
|
441
|
+
};
|
|
442
|
+
|
|
443
|
+
type FileApi = {
|
|
444
|
+
uploadGroupFile(groupId: number | string, file: string | Buffer | Uint8Array | NodeJS.ReadableStream, name: string): Promise<any>;
|
|
445
|
+
uploadPrivateFile(userId: number | string, file: string | Buffer | Uint8Array | NodeJS.ReadableStream, name: string): Promise<any>;
|
|
446
|
+
setGroupPortrait(groupId: number | string, file: string | Buffer | Uint8Array | NodeJS.ReadableStream): Promise<any>;
|
|
447
|
+
getGroupFileSystemInfo(groupId: number | string): Promise<any>;
|
|
448
|
+
getGroupRootFiles(groupId: number | string): Promise<any>;
|
|
449
|
+
getGroupFilesByFolder(groupId: number | string, folderId: string): Promise<any>;
|
|
450
|
+
getGroupFileUrl(groupId: number | string, fileId: string, busid?: number): Promise<any>;
|
|
451
|
+
deleteGroupFile(groupId: number | string, fileId: string, busid?: number): Promise<any>;
|
|
452
|
+
createGroupFileFolder(groupId: number | string, name: string, parentId?: string): Promise<any>;
|
|
453
|
+
deleteGroupFolder(groupId: number | string, folderId: string): Promise<any>;
|
|
454
|
+
downloadFile(url: string, threadCount?: number, headers?: Record<string, string>): Promise<any>;
|
|
455
|
+
};
|
|
456
|
+
|
|
457
|
+
type StreamApi = {
|
|
458
|
+
uploadFileStream(file: string | Buffer | Uint8Array | NodeJS.ReadableStream, options?: {
|
|
459
|
+
chunkSize?: number;
|
|
460
|
+
streamId?: string;
|
|
461
|
+
expectedSha256?: string;
|
|
462
|
+
fileRetention?: number;
|
|
463
|
+
filename?: string;
|
|
464
|
+
reset?: boolean;
|
|
465
|
+
verifyOnly?: boolean;
|
|
466
|
+
}): Promise<any>;
|
|
467
|
+
getUploadStreamStatus(streamId: string): Promise<any>;
|
|
468
|
+
};
|
|
469
|
+
|
|
470
|
+
type RequestApi = {
|
|
471
|
+
handleFriendRequest(flag: string, approve?: boolean, remark?: string): Promise<any>;
|
|
472
|
+
handleGroupRequest(flag: string, subType: 'add' | 'invite', approve?: boolean, reason?: string): Promise<any>;
|
|
473
|
+
};
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* OneBot 11 API 封装
|
|
477
|
+
* 将 ApiClient 的底层 call 转为清晰的业务方法
|
|
478
|
+
* 通过组合各领域 API,保持类方法名称不变。
|
|
479
|
+
*/
|
|
480
|
+
declare class OneBotApi {
|
|
481
|
+
private messageApi;
|
|
482
|
+
private mediaApi;
|
|
483
|
+
private accountApi;
|
|
484
|
+
private groupApi;
|
|
485
|
+
private fileApi;
|
|
486
|
+
private streamApi;
|
|
487
|
+
private requestApi;
|
|
488
|
+
constructor(client: ApiClient, logger: Logger);
|
|
489
|
+
}
|
|
490
|
+
interface OneBotApi extends MessageApi, MediaApi, AccountApi, GroupApi, FileApi, StreamApi, RequestApi {
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* 统一封装 OneBot API 代理,避免 NapLink 主类塞满转发方法。
|
|
495
|
+
* 通过 bindOneBotApiMethods 在实例上动态挂载对应方法,保持对外 API 不变。
|
|
496
|
+
*/
|
|
497
|
+
type OneBotApiMethods = {
|
|
498
|
+
getLoginInfo(): Promise<any>;
|
|
499
|
+
getStatus(): Promise<any>;
|
|
500
|
+
sendMessage(params: {
|
|
501
|
+
message_type?: 'private' | 'group';
|
|
502
|
+
user_id?: number | string;
|
|
503
|
+
group_id?: number | string;
|
|
504
|
+
message: any;
|
|
505
|
+
auto_escape?: boolean;
|
|
506
|
+
}): Promise<any>;
|
|
507
|
+
sendPrivateMessage(userId: number | string, message: any): Promise<any>;
|
|
508
|
+
sendGroupMessage(groupId: number | string, message: any): Promise<any>;
|
|
509
|
+
deleteMessage(messageId: number | string): Promise<any>;
|
|
510
|
+
getMessage(messageId: number | string): Promise<any>;
|
|
511
|
+
getForwardMessage(id: string): Promise<any>;
|
|
512
|
+
getEssenceMessageList(groupId: number | string): Promise<any>;
|
|
513
|
+
markMessageAsRead(messageId: number | string): Promise<any>;
|
|
514
|
+
getGroupAtAllRemain(groupId: number | string): Promise<any>;
|
|
515
|
+
getGroupSystemMsg(): Promise<any>;
|
|
516
|
+
getGroupHonorInfo(groupId: number | string, type: 'all' | 'talkative' | 'performer' | 'legend' | 'strong_newbie' | 'emotion'): Promise<any>;
|
|
517
|
+
getGroupFileSystemInfo(groupId: number | string): Promise<any>;
|
|
518
|
+
getGroupRootFiles(groupId: number | string): Promise<any>;
|
|
519
|
+
getGroupFilesByFolder(groupId: number | string, folderId: string): Promise<any>;
|
|
520
|
+
getGroupFileUrl(groupId: number | string, fileId: string, busid?: number): Promise<any>;
|
|
521
|
+
deleteGroupFile(groupId: number | string, fileId: string, busid?: number): Promise<any>;
|
|
522
|
+
createGroupFileFolder(groupId: number | string, name: string, parentId?: string): Promise<any>;
|
|
523
|
+
deleteGroupFolder(groupId: number | string, folderId: string): Promise<any>;
|
|
524
|
+
downloadFile(url: string, threadCount?: number, headers?: Record<string, string>): Promise<any>;
|
|
525
|
+
uploadFileStream(file: string | Buffer | Uint8Array | NodeJS.ReadableStream, options?: {
|
|
526
|
+
chunkSize?: number;
|
|
527
|
+
streamId?: string;
|
|
528
|
+
expectedSha256?: string;
|
|
529
|
+
fileRetention?: number;
|
|
530
|
+
filename?: string;
|
|
531
|
+
reset?: boolean;
|
|
532
|
+
verifyOnly?: boolean;
|
|
533
|
+
}): Promise<any>;
|
|
534
|
+
getUploadStreamStatus(streamId: string): Promise<any>;
|
|
535
|
+
sendGroupForwardMessage(groupId: number | string, messages: any[]): Promise<any>;
|
|
536
|
+
getImage(file: string): Promise<any>;
|
|
537
|
+
getRecord(file: string, outFormat?: string): Promise<any>;
|
|
538
|
+
getFile(file: string): Promise<any>;
|
|
539
|
+
getFriendList(): Promise<any>;
|
|
540
|
+
getGroupList(): Promise<any>;
|
|
541
|
+
getGroupInfo(groupId: number | string, noCache?: boolean): Promise<any>;
|
|
542
|
+
getGroupMemberList(groupId: number | string): Promise<any>;
|
|
543
|
+
getGroupMemberInfo(groupId: number | string, userId: number | string, noCache?: boolean): Promise<any>;
|
|
544
|
+
setGroupBan(groupId: number | string, userId: number | string, duration?: number): Promise<any>;
|
|
545
|
+
unsetGroupBan(groupId: number | string, userId: number | string): Promise<any>;
|
|
546
|
+
setGroupWholeBan(groupId: number | string, enable?: boolean): Promise<any>;
|
|
547
|
+
setGroupKick(groupId: number | string, userId: number | string, rejectAddRequest?: boolean): Promise<any>;
|
|
548
|
+
setGroupLeave(groupId: number | string, isDismiss?: boolean): Promise<any>;
|
|
549
|
+
setGroupCard(groupId: number | string, userId: number | string, card: string): Promise<any>;
|
|
550
|
+
setGroupName(groupId: number | string, groupName: string): Promise<any>;
|
|
551
|
+
setGroupPortrait(groupId: number | string, file: string | Buffer | Uint8Array | NodeJS.ReadableStream): Promise<any>;
|
|
552
|
+
setGroupAdmin(groupId: number | string, userId: number | string, enable?: boolean): Promise<any>;
|
|
553
|
+
setGroupAnonymousBan(groupId: number | string, anonymousFlag: string, duration?: number): Promise<any>;
|
|
554
|
+
setEssenceMessage(messageId: number | string): Promise<any>;
|
|
555
|
+
deleteEssenceMessage(messageId: number | string): Promise<any>;
|
|
556
|
+
setGroupSpecialTitle(groupId: number | string, userId: number | string, specialTitle: string, duration?: number): Promise<any>;
|
|
557
|
+
sendLike(userId: number | string, times?: number): Promise<any>;
|
|
558
|
+
uploadGroupFile(groupId: number | string, file: string, name: string): Promise<any>;
|
|
559
|
+
uploadPrivateFile(userId: number | string, file: string, name: string): Promise<any>;
|
|
560
|
+
getStrangerInfo(userId: number | string, noCache?: boolean): Promise<any>;
|
|
561
|
+
getVersionInfo(): Promise<any>;
|
|
562
|
+
handleFriendRequest(flag: string, approve?: boolean, remark?: string): Promise<any>;
|
|
563
|
+
handleGroupRequest(flag: string, subType: 'add' | 'invite', approve?: boolean, reason?: string): Promise<any>;
|
|
564
|
+
};
|
|
565
|
+
|
|
566
|
+
/**
|
|
567
|
+
* NapLink客户端
|
|
568
|
+
* 现代化的NapCat WebSocket客户端SDK
|
|
569
|
+
*/
|
|
570
|
+
declare class NapLink extends EventEmitter {
|
|
571
|
+
private config;
|
|
572
|
+
private logger;
|
|
573
|
+
private connection;
|
|
574
|
+
private apiClient;
|
|
575
|
+
private eventRouter;
|
|
576
|
+
private dispatcher;
|
|
577
|
+
private oneBotApi;
|
|
578
|
+
constructor(config: PartialNapLinkConfig);
|
|
579
|
+
/**
|
|
580
|
+
* 连接到NapCat服务器
|
|
581
|
+
*/
|
|
582
|
+
connect(): Promise<void>;
|
|
583
|
+
/**
|
|
584
|
+
* 断开连接
|
|
585
|
+
*/
|
|
586
|
+
disconnect(): void;
|
|
587
|
+
/**
|
|
588
|
+
* 获取连接状态
|
|
589
|
+
*/
|
|
590
|
+
getState(): ConnectionState;
|
|
591
|
+
/**
|
|
592
|
+
* 检查是否已连接
|
|
593
|
+
*/
|
|
594
|
+
isConnected(): boolean;
|
|
595
|
+
/**
|
|
596
|
+
* 补充消息中的媒体直链
|
|
597
|
+
* 自动通过 get_file / get_image / get_record 获取真实下载链接
|
|
598
|
+
*/
|
|
599
|
+
hydrateMessage(message: any[]): Promise<void>;
|
|
600
|
+
/**
|
|
601
|
+
* 调用自定义API
|
|
602
|
+
*/
|
|
603
|
+
callApi<T = any>(method: string, params?: any): Promise<T>;
|
|
604
|
+
/**
|
|
605
|
+
* 暴露 OneBot API 便于直接使用
|
|
606
|
+
*/
|
|
607
|
+
get api(): OneBotApi;
|
|
608
|
+
/**
|
|
609
|
+
* 设置事件转发
|
|
610
|
+
*/
|
|
611
|
+
private setupEventForwarding;
|
|
612
|
+
}
|
|
613
|
+
interface NapLink extends OneBotApiMethods {
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
/**
|
|
617
|
+
* NapLink 错误基类
|
|
618
|
+
* 所有SDK错误都继承自此类
|
|
619
|
+
*/
|
|
620
|
+
declare class NapLinkError extends Error {
|
|
621
|
+
code: string;
|
|
622
|
+
details?: any | undefined;
|
|
623
|
+
constructor(message: string, code: string, details?: any | undefined);
|
|
624
|
+
/**
|
|
625
|
+
* 转换为JSON格式
|
|
626
|
+
*/
|
|
627
|
+
toJSON(): {
|
|
628
|
+
name: string;
|
|
629
|
+
message: string;
|
|
630
|
+
code: string;
|
|
631
|
+
details: any;
|
|
632
|
+
};
|
|
633
|
+
}
|
|
634
|
+
/**
|
|
635
|
+
* 连接错误
|
|
636
|
+
* 当WebSocket连接失败时抛出
|
|
637
|
+
*/
|
|
638
|
+
declare class ConnectionError extends NapLinkError {
|
|
639
|
+
constructor(message: string, cause?: any);
|
|
640
|
+
}
|
|
641
|
+
/**
|
|
642
|
+
* API超时错误
|
|
643
|
+
* 当API调用超过设定时间时抛出
|
|
644
|
+
*/
|
|
645
|
+
declare class ApiTimeoutError extends NapLinkError {
|
|
646
|
+
constructor(method: string, timeout: number);
|
|
647
|
+
}
|
|
648
|
+
/**
|
|
649
|
+
* API错误
|
|
650
|
+
* 当API调用返回错误时抛出
|
|
651
|
+
*/
|
|
652
|
+
declare class ApiError extends NapLinkError {
|
|
653
|
+
constructor(method: string, retcode: number, message: string, wording?: string);
|
|
654
|
+
}
|
|
655
|
+
/**
|
|
656
|
+
* 达到最大重连次数错误
|
|
657
|
+
*/
|
|
658
|
+
declare class MaxReconnectAttemptsError extends NapLinkError {
|
|
659
|
+
constructor(attempts: number);
|
|
660
|
+
}
|
|
661
|
+
/**
|
|
662
|
+
* 连接关闭错误
|
|
663
|
+
*/
|
|
664
|
+
declare class ConnectionClosedError extends NapLinkError {
|
|
665
|
+
constructor(code: number, reason: string);
|
|
666
|
+
}
|
|
667
|
+
/**
|
|
668
|
+
* 无效配置错误
|
|
669
|
+
*/
|
|
670
|
+
declare class InvalidConfigError extends NapLinkError {
|
|
671
|
+
constructor(field: string, reason: string);
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
type TextSegment = {
|
|
675
|
+
type: 'text';
|
|
676
|
+
data: {
|
|
677
|
+
text: string;
|
|
678
|
+
};
|
|
679
|
+
};
|
|
680
|
+
type AtSegment = {
|
|
681
|
+
type: 'at';
|
|
682
|
+
data: {
|
|
683
|
+
qq: string | 'all';
|
|
684
|
+
};
|
|
685
|
+
};
|
|
686
|
+
type FaceSegment = {
|
|
687
|
+
type: 'face';
|
|
688
|
+
data: {
|
|
689
|
+
id: string;
|
|
690
|
+
};
|
|
691
|
+
};
|
|
692
|
+
type ReplySegment = {
|
|
693
|
+
type: 'reply';
|
|
694
|
+
data: {
|
|
695
|
+
id: string;
|
|
696
|
+
};
|
|
697
|
+
};
|
|
698
|
+
type ImageSegment = {
|
|
699
|
+
type: 'image';
|
|
700
|
+
data: {
|
|
701
|
+
file: string;
|
|
702
|
+
summary?: string;
|
|
703
|
+
sub_type?: string;
|
|
704
|
+
};
|
|
705
|
+
};
|
|
706
|
+
type RecordSegment = {
|
|
707
|
+
type: 'record';
|
|
708
|
+
data: {
|
|
709
|
+
file: string;
|
|
710
|
+
};
|
|
711
|
+
};
|
|
712
|
+
type VideoSegment = {
|
|
713
|
+
type: 'video';
|
|
714
|
+
data: {
|
|
715
|
+
file: string;
|
|
716
|
+
};
|
|
717
|
+
};
|
|
718
|
+
type FileSegment = {
|
|
719
|
+
type: 'file';
|
|
720
|
+
data: {
|
|
721
|
+
file: string;
|
|
722
|
+
name?: string;
|
|
723
|
+
};
|
|
724
|
+
};
|
|
725
|
+
type JsonSegment = {
|
|
726
|
+
type: 'json';
|
|
727
|
+
data: {
|
|
728
|
+
data: string;
|
|
729
|
+
};
|
|
730
|
+
};
|
|
731
|
+
type XmlSegment = {
|
|
732
|
+
type: 'xml';
|
|
733
|
+
data: {
|
|
734
|
+
data: string;
|
|
735
|
+
};
|
|
736
|
+
};
|
|
737
|
+
type MarkdownSegment = {
|
|
738
|
+
type: 'markdown';
|
|
739
|
+
data: {
|
|
740
|
+
content: string;
|
|
741
|
+
};
|
|
742
|
+
};
|
|
743
|
+
type OneBotMessageSegment = TextSegment | AtSegment | FaceSegment | ReplySegment | ImageSegment | RecordSegment | VideoSegment | FileSegment | JsonSegment | XmlSegment | MarkdownSegment;
|
|
744
|
+
|
|
745
|
+
export { type Anonymous, ApiError, ApiTimeoutError, type AtSegment, type BaseEvent, ConnectionClosedError, ConnectionError, ConnectionState, type FaceSegment, type FileInfo, type FileSegment, type FriendAddNotice, type FriendRecallNotice, type FriendRequest, type GroupAdminNotice, type GroupDecreaseNotice, type GroupHonorInfo, type GroupIncreaseNotice, type GroupInviteRequest, type GroupJoinRequest, type GroupMessageEvent, type GroupRecallNotice, type GroupRequest, type GroupSystemMessages, type GroupUploadNotice, type HeartbeatMetaEvent, type ImageSegment, InvalidConfigError, type JsonSegment, type LifecycleMetaEvent, type Logger, type MarkdownSegment, MaxReconnectAttemptsError, type MessageEvent, type MessageSegment, type MetaEvent, NapLink, type NapLinkConfig, NapLinkError, type NoticeEvent, type NotifyNotice, OneBotApi, type OneBotMessageSegment, type PartialNapLinkConfig, type PokeNotice, type PostType, type PrivateMessageEvent, type RecordSegment, type ReplySegment, type RequestEvent, type Sender, type TextSegment, type VideoSegment, type XmlSegment, NapLink as default };
|