napcat-sdk 0.1.1 → 0.2.0
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/dist/index.cjs +269 -174
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +352 -297
- package/dist/index.d.mts +352 -297
- package/dist/index.mjs +269 -168
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -3
- package/readme.md +70 -0
package/dist/index.d.mts
CHANGED
|
@@ -1,65 +1,53 @@
|
|
|
1
|
-
//#region package.d.ts
|
|
2
|
-
declare let name$1: string;
|
|
3
|
-
declare let type: string;
|
|
4
|
-
declare let version$1: string;
|
|
5
|
-
declare let packageManager: string;
|
|
6
|
-
declare let description: string;
|
|
7
|
-
declare let keywords: string[];
|
|
8
|
-
declare let homepage: string;
|
|
9
|
-
declare let files: string[];
|
|
10
|
-
declare namespace bugs {
|
|
11
|
-
let url: string;
|
|
12
|
-
}
|
|
13
|
-
declare namespace repository {
|
|
14
|
-
let type_1: string;
|
|
15
|
-
export { type_1 as type };
|
|
16
|
-
let url_1: string;
|
|
17
|
-
export { url_1 as url };
|
|
18
|
-
export let directory: string;
|
|
19
|
-
}
|
|
20
|
-
declare namespace scripts {
|
|
21
|
-
let dev: string;
|
|
22
|
-
let build: string;
|
|
23
|
-
}
|
|
24
|
-
declare let exports: {
|
|
25
|
-
".": {
|
|
26
|
-
require: string;
|
|
27
|
-
import: string;
|
|
28
|
-
types: string;
|
|
29
|
-
};
|
|
30
|
-
"./package.json": string;
|
|
31
|
-
};
|
|
32
|
-
declare let author: string;
|
|
33
|
-
declare let license: string;
|
|
34
|
-
declare let devDependencies: {
|
|
35
|
-
"@types/node": string;
|
|
36
|
-
tsdown: string;
|
|
37
|
-
typescript: string;
|
|
38
|
-
};
|
|
39
|
-
declare namespace dependencies {
|
|
40
|
-
let mitt: string;
|
|
41
|
-
}
|
|
42
|
-
declare namespace __json_default_export {
|
|
43
|
-
export { name$1 as name, type, version$1 as version, packageManager, description, keywords, homepage, files, bugs, repository, scripts, exports, author, license, devDependencies, dependencies };
|
|
44
|
-
}
|
|
45
|
-
//#endregion
|
|
46
1
|
//#region src/logger.d.ts
|
|
47
|
-
type LogLevel =
|
|
2
|
+
type LogLevel = "fatal" | "error" | "warn" | "info" | "debug" | "trace";
|
|
48
3
|
type Logger = Record<LogLevel, (...args: unknown[]) => void>;
|
|
4
|
+
declare const noop: () => void;
|
|
49
5
|
declare const ABSTRACT_LOGGER: Logger;
|
|
50
6
|
declare const CONSOLE_LOGGER: Logger;
|
|
51
7
|
//#endregion
|
|
52
|
-
//#region src/
|
|
8
|
+
//#region src/types.d.ts
|
|
9
|
+
interface MiokiOptions {
|
|
10
|
+
/** NapCat 访问令牌 */
|
|
11
|
+
token: string;
|
|
12
|
+
/** NapCat 服务器协议,默认为 ws */
|
|
13
|
+
protocol?: "ws" | "wss";
|
|
14
|
+
/** NapCat 服务器主机,默认为 localhost */
|
|
15
|
+
host?: string;
|
|
16
|
+
/** NapCat 服务器端口,默认为 3333 */
|
|
17
|
+
port?: number;
|
|
18
|
+
/** 日志记录器,默认为控制台日志记录器 */
|
|
19
|
+
logger?: Logger;
|
|
20
|
+
}
|
|
21
|
+
type OptionalKeys<T> = { [K in keyof T]-?: {} extends Pick<T, K> ? K : never }[keyof T];
|
|
22
|
+
type OptionalProps<T> = Pick<T, OptionalKeys<T>>;
|
|
23
|
+
type ExtractByType<T, K$1> = T extends {
|
|
24
|
+
type: K$1;
|
|
25
|
+
} ? T : never;
|
|
26
|
+
interface EventMap extends OneBotEventMap {
|
|
27
|
+
/** WebSocket 连接已打开 */
|
|
28
|
+
"ws.open": void;
|
|
29
|
+
/** WebSocket 连接已关闭 */
|
|
30
|
+
"ws.close": void;
|
|
31
|
+
/** WebSocket 连接发生错误 */
|
|
32
|
+
"ws.error": Event;
|
|
33
|
+
/** 收到 WebSocket 消息 */
|
|
34
|
+
"ws.message": any;
|
|
35
|
+
/** NapCat 连接已建立 */
|
|
36
|
+
"napcat.connected": {
|
|
37
|
+
uin: number;
|
|
38
|
+
ts: number;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
53
41
|
/**
|
|
54
|
-
|
|
55
|
-
|
|
42
|
+
* 媒体消息的通用属性
|
|
43
|
+
*/
|
|
56
44
|
interface MediaProps {
|
|
57
45
|
/** 媒体文件的 URL 地址 */
|
|
58
46
|
url: string;
|
|
59
47
|
/** 媒体文件的本地路径 */
|
|
60
48
|
path: string;
|
|
61
49
|
/** 媒体文件名或特殊标识 */
|
|
62
|
-
file: (string & {}) |
|
|
50
|
+
file: (string & {}) | "marketface";
|
|
63
51
|
/** 媒体文件 ID */
|
|
64
52
|
file_id: string;
|
|
65
53
|
/** 媒体文件大小(字节) */
|
|
@@ -69,31 +57,31 @@ interface MediaProps {
|
|
|
69
57
|
}
|
|
70
58
|
/** 接收的纯文本消息段 */
|
|
71
59
|
interface RecvTextElement {
|
|
72
|
-
type:
|
|
60
|
+
type: "text";
|
|
73
61
|
/** 文本内容 */
|
|
74
62
|
text: string;
|
|
75
63
|
}
|
|
76
64
|
/** 接收的 @ 消息段 */
|
|
77
65
|
interface RecvAtElement {
|
|
78
|
-
type:
|
|
66
|
+
type: "at";
|
|
79
67
|
/** 被 @ 的 QQ 号,'all' 表示 @全体成员 */
|
|
80
|
-
qq:
|
|
68
|
+
qq: "all" | (string & {});
|
|
81
69
|
}
|
|
82
70
|
/** 接收的回复消息段 */
|
|
83
71
|
interface RecvReplyElement {
|
|
84
|
-
type:
|
|
72
|
+
type: "reply";
|
|
85
73
|
/** 被回复的消息 ID */
|
|
86
74
|
id: string;
|
|
87
75
|
}
|
|
88
76
|
/** 接收的 QQ 表情消息段 */
|
|
89
77
|
interface RecvFaceElement {
|
|
90
|
-
type:
|
|
78
|
+
type: "face";
|
|
91
79
|
/** QQ 表情 ID */
|
|
92
80
|
id: number;
|
|
93
81
|
}
|
|
94
82
|
/** 接收的图片消息段 */
|
|
95
83
|
interface RecvImageElement extends MediaProps {
|
|
96
|
-
type:
|
|
84
|
+
type: "image";
|
|
97
85
|
/** 图片摘要/描述 */
|
|
98
86
|
summary?: string;
|
|
99
87
|
/** 图片子类型 */
|
|
@@ -101,43 +89,43 @@ interface RecvImageElement extends MediaProps {
|
|
|
101
89
|
}
|
|
102
90
|
/** 接收的语音消息段 */
|
|
103
91
|
interface RecvRecordElement extends MediaProps {
|
|
104
|
-
type:
|
|
92
|
+
type: "record";
|
|
105
93
|
}
|
|
106
94
|
/** 接收的视频消息段 */
|
|
107
95
|
interface RecvVideoElement extends MediaProps {
|
|
108
|
-
type:
|
|
96
|
+
type: "video";
|
|
109
97
|
}
|
|
110
98
|
/** 接收的猜拳消息段 */
|
|
111
99
|
interface RecvRpsElement {
|
|
112
|
-
type:
|
|
100
|
+
type: "rps";
|
|
113
101
|
/** 猜拳结果:1-石头, 2-剪刀, 3-布 */
|
|
114
102
|
result: string;
|
|
115
103
|
}
|
|
116
104
|
/** 接收的掷骰子消息段 */
|
|
117
105
|
interface RecvDiceElement {
|
|
118
|
-
type:
|
|
106
|
+
type: "dice";
|
|
119
107
|
/** 骰子点数:1-6 */
|
|
120
108
|
result: string;
|
|
121
109
|
}
|
|
122
110
|
/** 接收的窗口抖动消息段(戳一戳) */
|
|
123
111
|
interface RecvShakeElement {
|
|
124
|
-
type:
|
|
112
|
+
type: "shake";
|
|
125
113
|
}
|
|
126
114
|
/** 接收的戳一戳消息段 */
|
|
127
115
|
interface RecvPokeElement {
|
|
128
|
-
type:
|
|
116
|
+
type: "poke";
|
|
129
117
|
}
|
|
130
118
|
/** 接收的分享链接消息段 */
|
|
131
119
|
interface RecvShareElement {
|
|
132
|
-
type:
|
|
120
|
+
type: "share";
|
|
133
121
|
}
|
|
134
122
|
/** 接收的位置消息段 */
|
|
135
123
|
interface RecvLocationElement {
|
|
136
|
-
type:
|
|
124
|
+
type: "location";
|
|
137
125
|
}
|
|
138
126
|
/** 接收的合并转发消息段 */
|
|
139
127
|
interface RecvForwardElement {
|
|
140
|
-
type:
|
|
128
|
+
type: "forward";
|
|
141
129
|
/** 合并转发消息 ID */
|
|
142
130
|
id: string;
|
|
143
131
|
/** 合并转发消息内容 */
|
|
@@ -145,48 +133,48 @@ interface RecvForwardElement {
|
|
|
145
133
|
}
|
|
146
134
|
/** 接收的 JSON 消息段 */
|
|
147
135
|
interface RecvJsonElement {
|
|
148
|
-
type:
|
|
136
|
+
type: "json";
|
|
149
137
|
/** JSON 数据字符串 */
|
|
150
138
|
data: string;
|
|
151
139
|
}
|
|
152
140
|
/** 接收的文件消息段 */
|
|
153
141
|
interface RecvFileElement extends MediaProps {
|
|
154
|
-
type:
|
|
142
|
+
type: "file";
|
|
155
143
|
}
|
|
156
144
|
/** 接收的 Markdown 消息段 */
|
|
157
145
|
interface RecvMarkdownElement {
|
|
158
|
-
type:
|
|
146
|
+
type: "markdown";
|
|
159
147
|
}
|
|
160
148
|
/** 接收的小程序消息段 */
|
|
161
149
|
interface RecvLightAppElement {
|
|
162
|
-
type:
|
|
150
|
+
type: "lightapp";
|
|
163
151
|
}
|
|
164
152
|
/**
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
153
|
+
* 接收的消息段类型联合
|
|
154
|
+
* @description 表示从 QQ 接收到的所有可能的消息段类型
|
|
155
|
+
*/
|
|
168
156
|
type RecvElement = RecvTextElement | RecvAtElement | RecvReplyElement | RecvFaceElement | RecvImageElement | RecvRecordElement | RecvVideoElement | RecvRpsElement | RecvDiceElement | RecvShakeElement | RecvPokeElement | RecvShareElement | RecvLocationElement | RecvForwardElement | RecvJsonElement | RecvFileElement | RecvMarkdownElement | RecvLightAppElement;
|
|
169
157
|
/** 发送的纯文本消息段 */
|
|
170
158
|
interface SendTextElement {
|
|
171
|
-
type:
|
|
159
|
+
type: "text";
|
|
172
160
|
/** 文本内容 */
|
|
173
161
|
text: string;
|
|
174
162
|
}
|
|
175
163
|
/** 发送的 @ 消息段 */
|
|
176
164
|
interface SendAtElement {
|
|
177
|
-
type:
|
|
165
|
+
type: "at";
|
|
178
166
|
/** 被 @ 的 QQ 号,'all' 表示 @全体成员 */
|
|
179
|
-
qq:
|
|
167
|
+
qq: "all" | (string & {}) | number;
|
|
180
168
|
}
|
|
181
169
|
/** 发送的回复消息段 */
|
|
182
170
|
interface SendReplyElement {
|
|
183
|
-
type:
|
|
171
|
+
type: "reply";
|
|
184
172
|
/** 被回复的消息 ID */
|
|
185
173
|
id: string;
|
|
186
174
|
}
|
|
187
175
|
/** 发送的商城表情消息段 */
|
|
188
176
|
interface SendMfaceElement {
|
|
189
|
-
type:
|
|
177
|
+
type: "mface";
|
|
190
178
|
/** 表情 ID */
|
|
191
179
|
id: number;
|
|
192
180
|
/** 表情 key */
|
|
@@ -200,19 +188,19 @@ interface SendMfaceElement {
|
|
|
200
188
|
}
|
|
201
189
|
/** 发送的 QQ 表情消息段 */
|
|
202
190
|
interface SendFaceElement {
|
|
203
|
-
type:
|
|
191
|
+
type: "face";
|
|
204
192
|
/** QQ 表情 ID */
|
|
205
193
|
id: number;
|
|
206
194
|
}
|
|
207
195
|
/** 发送的大表情消息段 */
|
|
208
196
|
interface SendBfaceElement {
|
|
209
|
-
type:
|
|
197
|
+
type: "bface";
|
|
210
198
|
/** 大表情 ID */
|
|
211
199
|
id: number;
|
|
212
200
|
}
|
|
213
201
|
/** 发送的图片消息段 */
|
|
214
202
|
interface SendImageElement {
|
|
215
|
-
type:
|
|
203
|
+
type: "image";
|
|
216
204
|
/** 图片文件,支持 file:// / http:// / base64:// 协议 */
|
|
217
205
|
file: string;
|
|
218
206
|
/** 图片文件名 */
|
|
@@ -224,7 +212,7 @@ interface SendImageElement {
|
|
|
224
212
|
}
|
|
225
213
|
/** 发送的视频消息段 */
|
|
226
214
|
interface SendVideoElement {
|
|
227
|
-
type:
|
|
215
|
+
type: "video";
|
|
228
216
|
/** 视频文件,支持 file:// / http:// / base64:// 协议 */
|
|
229
217
|
file: string;
|
|
230
218
|
/** 视频文件名 */
|
|
@@ -234,7 +222,7 @@ interface SendVideoElement {
|
|
|
234
222
|
}
|
|
235
223
|
/** 发送的语音消息段 */
|
|
236
224
|
interface SendRecordElement {
|
|
237
|
-
type:
|
|
225
|
+
type: "record";
|
|
238
226
|
/** 语音文件,支持 file:// / http:// / base64:// 协议 */
|
|
239
227
|
file: string;
|
|
240
228
|
/** 语音文件名 */
|
|
@@ -242,29 +230,29 @@ interface SendRecordElement {
|
|
|
242
230
|
}
|
|
243
231
|
/** 发送的推荐好友/群消息段 */
|
|
244
232
|
interface SendContactElement {
|
|
245
|
-
type:
|
|
233
|
+
type: "contact";
|
|
246
234
|
/** 推荐类型:qq-好友, group-群 */
|
|
247
|
-
sub_type:
|
|
235
|
+
sub_type: "qq" | "group";
|
|
248
236
|
/** 被推荐的 QQ 号或群号 */
|
|
249
237
|
id: string;
|
|
250
238
|
}
|
|
251
239
|
/** 发送的戳一戳消息段 */
|
|
252
240
|
interface SendPokeElement {
|
|
253
|
-
type:
|
|
241
|
+
type: "poke";
|
|
254
242
|
}
|
|
255
243
|
/** 发送的音乐分享消息段 - 平台音乐 */
|
|
256
244
|
interface SendPlatformMusicElement {
|
|
257
|
-
type:
|
|
245
|
+
type: "music";
|
|
258
246
|
/** 音乐平台 */
|
|
259
|
-
platform:
|
|
247
|
+
platform: "qq" | "163" | "kugou" | "migu" | "kuwo";
|
|
260
248
|
/** 音乐 ID */
|
|
261
249
|
id: string;
|
|
262
250
|
}
|
|
263
251
|
/** 发送的音乐分享消息段 - 自定义音乐 */
|
|
264
252
|
interface SendCustomMusicElement {
|
|
265
|
-
type:
|
|
253
|
+
type: "music";
|
|
266
254
|
/** 自定义音乐标识 */
|
|
267
|
-
platform:
|
|
255
|
+
platform: "custom";
|
|
268
256
|
/** 跳转链接 URL */
|
|
269
257
|
url: string;
|
|
270
258
|
/** 音频链接 URL */
|
|
@@ -280,13 +268,13 @@ interface SendCustomMusicElement {
|
|
|
280
268
|
type SendMusicElement = SendPlatformMusicElement | SendCustomMusicElement;
|
|
281
269
|
/** 发送的合并转发消息段 */
|
|
282
270
|
interface SendForwardElement {
|
|
283
|
-
type:
|
|
271
|
+
type: "forward";
|
|
284
272
|
/** 合并转发消息 ID */
|
|
285
273
|
id: string;
|
|
286
274
|
}
|
|
287
275
|
/** 发送的合并转发节点 - 引用已有消息 */
|
|
288
276
|
interface SendNodeRefElement {
|
|
289
|
-
type:
|
|
277
|
+
type: "node";
|
|
290
278
|
/** 发送者 QQ 号(可选) */
|
|
291
279
|
user_id?: string;
|
|
292
280
|
/** 发送者昵称(可选) */
|
|
@@ -296,27 +284,25 @@ interface SendNodeRefElement {
|
|
|
296
284
|
}
|
|
297
285
|
/** 发送的合并转发节点 - 自定义内容 */
|
|
298
286
|
interface SendNodeContentElement {
|
|
299
|
-
type:
|
|
287
|
+
type: "node";
|
|
300
288
|
/** 发送者 QQ 号(可选) */
|
|
301
289
|
user_id?: string;
|
|
302
290
|
/** 发送者昵称(可选) */
|
|
303
291
|
nickname?: string;
|
|
304
292
|
/** 自定义消息内容 */
|
|
305
|
-
content:
|
|
306
|
-
type: 'node';
|
|
307
|
-
}>[];
|
|
293
|
+
content: SendElement[];
|
|
308
294
|
}
|
|
309
295
|
/** 发送的合并转发节点消息段 */
|
|
310
296
|
type SendNodeElement = SendNodeRefElement | SendNodeContentElement;
|
|
311
297
|
/** 发送的 JSON 消息段 */
|
|
312
298
|
interface SendJsonElement {
|
|
313
|
-
type:
|
|
299
|
+
type: "json";
|
|
314
300
|
/** JSON 数据字符串 */
|
|
315
301
|
data: string;
|
|
316
302
|
}
|
|
317
303
|
/** 发送的文件消息段 */
|
|
318
304
|
interface SendFileElement {
|
|
319
|
-
type:
|
|
305
|
+
type: "file";
|
|
320
306
|
/** 文件,支持 file:// / http:// / base64:// 协议 */
|
|
321
307
|
file: string;
|
|
322
308
|
/** 文件名 */
|
|
@@ -324,33 +310,56 @@ interface SendFileElement {
|
|
|
324
310
|
}
|
|
325
311
|
/** 发送的 Markdown 消息段 */
|
|
326
312
|
interface SendMarkdownElement {
|
|
327
|
-
type:
|
|
313
|
+
type: "markdown";
|
|
328
314
|
}
|
|
329
315
|
/** 发送的小程序消息段 */
|
|
330
316
|
interface SendLightAppElement {
|
|
331
|
-
type:
|
|
317
|
+
type: "lightapp";
|
|
332
318
|
}
|
|
333
319
|
/**
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
320
|
+
* 发送的消息段类型联合
|
|
321
|
+
* @description 表示可以发送给 QQ 的所有可能的消息段类型
|
|
322
|
+
*/
|
|
337
323
|
type SendElement = SendTextElement | SendAtElement | SendReplyElement | SendMfaceElement | SendFaceElement | SendBfaceElement | SendImageElement | SendVideoElement | SendRecordElement | SendContactElement | SendPokeElement | SendMusicElement | SendForwardElement | SendNodeElement | SendJsonElement | SendFileElement | SendMarkdownElement | SendLightAppElement;
|
|
324
|
+
/**
|
|
325
|
+
* 将消息段类型包装为 OneBot 标准格式
|
|
326
|
+
* @description 将 { type, ...data } 转换为 { type, data: { ...data } } 格式
|
|
327
|
+
*/
|
|
328
|
+
type WrapData<T extends {
|
|
329
|
+
type: string;
|
|
330
|
+
}> = {
|
|
331
|
+
type: T["type"];
|
|
332
|
+
data: Omit<T, "type">;
|
|
333
|
+
};
|
|
334
|
+
/**
|
|
335
|
+
* 将 OneBot 标准格式展开为扁平格式
|
|
336
|
+
* @description 将 { type, data: { ...data } } 转换为 { type, ...data } 格式
|
|
337
|
+
*/
|
|
338
|
+
type FlattenData<T extends {
|
|
339
|
+
type: string;
|
|
340
|
+
}> = T extends {
|
|
341
|
+
data: infer U;
|
|
342
|
+
} ? U & {
|
|
343
|
+
type: T["type"];
|
|
344
|
+
} : never;
|
|
345
|
+
/** 标准化后的发送消息段(OneBot 标准格式) */
|
|
346
|
+
type NormalizedElementToSend = WrapData<SendElement>;
|
|
338
347
|
/** 可发送的消息类型,可以是字符串或消息段 */
|
|
339
348
|
type Sendable = string | SendElement;
|
|
340
349
|
/** 上报事件类型 */
|
|
341
|
-
type PostType =
|
|
350
|
+
type PostType = "meta_event" | "message" | "message_sent" | "notice" | "request";
|
|
342
351
|
/** 元事件类型 */
|
|
343
|
-
type MetaEventType =
|
|
352
|
+
type MetaEventType = "heartbeat" | "lifecycle";
|
|
344
353
|
/** 消息类型 */
|
|
345
|
-
type MessageType =
|
|
354
|
+
type MessageType = "private" | "group";
|
|
346
355
|
/** 通知类型 */
|
|
347
|
-
type NoticeType =
|
|
356
|
+
type NoticeType = "friend" | "group" | "client";
|
|
348
357
|
/** 通知子类型 */
|
|
349
|
-
type NoticeSubType =
|
|
358
|
+
type NoticeSubType = "increase" | "decrease" | "recall" | "poke" | "like" | "input" | "admin" | "ban" | "title" | "card" | "upload" | "reaction" | "essence";
|
|
350
359
|
/**
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
360
|
+
* 事件基础类型
|
|
361
|
+
* @description 所有事件的基础结构,包含时间戳、机器人 QQ 号和事件类型
|
|
362
|
+
*/
|
|
354
363
|
type EventBase<T extends PostType, U$1 extends object> = U$1 & {
|
|
355
364
|
/** 事件发生的 Unix 时间戳 */
|
|
356
365
|
time: number;
|
|
@@ -360,17 +369,17 @@ type EventBase<T extends PostType, U$1 extends object> = U$1 & {
|
|
|
360
369
|
post_type: T;
|
|
361
370
|
};
|
|
362
371
|
/**
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
type MetaEventBase<T extends MetaEventType, U$1 extends object> = EventBase<
|
|
372
|
+
* 元事件基础类型
|
|
373
|
+
* @description 元事件表示 OneBot 实现本身的状态变化
|
|
374
|
+
*/
|
|
375
|
+
type MetaEventBase<T extends MetaEventType, U$1 extends object> = EventBase<"meta_event", U$1 & {
|
|
367
376
|
meta_event_type: T;
|
|
368
377
|
}>;
|
|
369
378
|
/**
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
type HeartbeatMetaEvent = MetaEventBase<
|
|
379
|
+
* 心跳元事件
|
|
380
|
+
* @description 定期发送的心跳事件,用于确认连接状态
|
|
381
|
+
*/
|
|
382
|
+
type HeartbeatMetaEvent = MetaEventBase<"heartbeat", {
|
|
374
383
|
/** 状态信息 */
|
|
375
384
|
status: {
|
|
376
385
|
/** 是否在线 */
|
|
@@ -382,12 +391,12 @@ type HeartbeatMetaEvent = MetaEventBase<'heartbeat', {
|
|
|
382
391
|
interval: number;
|
|
383
392
|
}>;
|
|
384
393
|
/**
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
type LifecycleMetaEvent = MetaEventBase<
|
|
394
|
+
* 生命周期元事件
|
|
395
|
+
* @description OneBot 实现的生命周期事件
|
|
396
|
+
*/
|
|
397
|
+
type LifecycleMetaEvent = MetaEventBase<"lifecycle", {
|
|
389
398
|
/** 生命周期子类型 */
|
|
390
|
-
sub_type:
|
|
399
|
+
sub_type: "connect";
|
|
391
400
|
}>;
|
|
392
401
|
/** 元事件联合类型 */
|
|
393
402
|
type MetaEvent = HeartbeatMetaEvent | LifecycleMetaEvent;
|
|
@@ -404,14 +413,16 @@ type ReactionAction = (id: string) => Promise<void>;
|
|
|
404
413
|
/** 撤回消息的函数类型 */
|
|
405
414
|
type Recall = () => Promise<void>;
|
|
406
415
|
/**
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
416
|
+
* 群信息接口
|
|
417
|
+
* @description 包含群的基本信息和常用操作方法
|
|
418
|
+
*/
|
|
410
419
|
interface Group {
|
|
411
420
|
/** 群号 */
|
|
412
421
|
group_id: number;
|
|
413
422
|
/** 群名称 */
|
|
414
423
|
group_name: string;
|
|
424
|
+
/** NapCat 实例 */
|
|
425
|
+
napcat: NapCat;
|
|
415
426
|
/** 群签到 */
|
|
416
427
|
doSign: () => Promise<string>;
|
|
417
428
|
/** 获取群信息 */
|
|
@@ -442,16 +453,18 @@ interface Group {
|
|
|
442
453
|
/** 发送群消息 */
|
|
443
454
|
sendMsg: SendMsg;
|
|
444
455
|
}
|
|
445
|
-
type GroupWithInfo = Group & Awaited<ReturnType<Group[
|
|
456
|
+
type GroupWithInfo = Group & Awaited<ReturnType<Group["getInfo"]>>;
|
|
446
457
|
/**
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
458
|
+
* 好友信息接口
|
|
459
|
+
* @description 包含好友的基本信息和常用操作方法
|
|
460
|
+
*/
|
|
450
461
|
interface Friend {
|
|
451
462
|
/** 好友 QQ 号 */
|
|
452
463
|
user_id: number;
|
|
453
464
|
/** 好友昵称 */
|
|
454
465
|
nickname: string;
|
|
466
|
+
/** NapCat 实例 */
|
|
467
|
+
napcat: NapCat;
|
|
455
468
|
/** 发送私聊消息 */
|
|
456
469
|
sendMsg: SendMsg;
|
|
457
470
|
/** 删除好友 */
|
|
@@ -542,14 +555,16 @@ interface Friend {
|
|
|
542
555
|
login_days: number;
|
|
543
556
|
}>;
|
|
544
557
|
}
|
|
545
|
-
type FriendWithInfo = Friend & Awaited<ReturnType<Friend[
|
|
558
|
+
type FriendWithInfo = Friend & Awaited<ReturnType<Friend["getInfo"]>>;
|
|
546
559
|
/**
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
type MessageEventBase<T extends MessageType, U$1 extends object> = EventBase<
|
|
560
|
+
* 消息事件基础类型
|
|
561
|
+
* @description 所有消息事件的基础结构
|
|
562
|
+
*/
|
|
563
|
+
type MessageEventBase<T extends MessageType, U$1 extends object> = EventBase<"message", U$1 & {
|
|
551
564
|
/** 消息 ID */
|
|
552
565
|
message_id: number;
|
|
566
|
+
/** 引用的消息 ID */
|
|
567
|
+
quote_id: string | null;
|
|
553
568
|
/** 消息类型 */
|
|
554
569
|
message_type: T;
|
|
555
570
|
/** 消息序号 */
|
|
@@ -566,18 +581,20 @@ type MessageEventBase<T extends MessageType, U$1 extends object> = EventBase<'me
|
|
|
566
581
|
reply: Reply;
|
|
567
582
|
}>;
|
|
568
583
|
/**
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
type PrivateMessageEvent = MessageEventBase<
|
|
584
|
+
* 私聊消息事件
|
|
585
|
+
* @description 包含好友私聊、群临时会话等私聊消息
|
|
586
|
+
*/
|
|
587
|
+
type PrivateMessageEvent = MessageEventBase<"private", {
|
|
573
588
|
/** 发送者 QQ 号 */
|
|
574
589
|
user_id: number;
|
|
575
590
|
/** 私聊子类型:friend-好友, group-群临时会话, group_self-群中自己发送, other-其他 */
|
|
576
|
-
sub_type:
|
|
591
|
+
sub_type: "friend" | "group" | "group_self" | "other";
|
|
577
592
|
/** 接收者 QQ 号 */
|
|
578
593
|
target_id: number;
|
|
579
594
|
/** 好友信息对象 */
|
|
580
595
|
friend: Friend;
|
|
596
|
+
/** 获取引用的消息 */
|
|
597
|
+
getQuoteMessage: () => Promise<PrivateMessageEvent | null>;
|
|
581
598
|
/** 发送者信息 */
|
|
582
599
|
sender: {
|
|
583
600
|
/** 发送者 QQ 号 */
|
|
@@ -587,10 +604,10 @@ type PrivateMessageEvent = MessageEventBase<'private', {
|
|
|
587
604
|
};
|
|
588
605
|
}>;
|
|
589
606
|
/**
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
type GroupMessageEvent = MessageEventBase<
|
|
607
|
+
* 群消息事件
|
|
608
|
+
* @description 群聊中的消息事件
|
|
609
|
+
*/
|
|
610
|
+
type GroupMessageEvent = MessageEventBase<"group", {
|
|
594
611
|
/** 群号 */
|
|
595
612
|
group_id: number;
|
|
596
613
|
/** 群名称 */
|
|
@@ -598,13 +615,19 @@ type GroupMessageEvent = MessageEventBase<'group', {
|
|
|
598
615
|
/** 发送者 QQ 号 */
|
|
599
616
|
user_id: number;
|
|
600
617
|
/** 群消息子类型:normal-普通消息, notice-通知消息 */
|
|
601
|
-
sub_type:
|
|
618
|
+
sub_type: "normal" | "notice";
|
|
602
619
|
/** 撤回该消息的方法 */
|
|
603
620
|
recall: Recall;
|
|
604
621
|
/** 添加消息表态的方法 */
|
|
605
622
|
addReaction: ReactionAction;
|
|
606
623
|
/** 删除消息表态的方法 */
|
|
607
624
|
delReaction: ReactionAction;
|
|
625
|
+
/** 获取引用的消息 */
|
|
626
|
+
getQuoteMessage: () => Promise<GroupMessageEvent | null>;
|
|
627
|
+
/** 添加精华消息的方法 */
|
|
628
|
+
addEssence: () => Promise<void>;
|
|
629
|
+
/** 删除精华消息的方法 */
|
|
630
|
+
delEssence: () => Promise<void>;
|
|
608
631
|
/** 群信息对象 */
|
|
609
632
|
group: Group;
|
|
610
633
|
/** 发送者信息 */
|
|
@@ -616,33 +639,33 @@ type GroupMessageEvent = MessageEventBase<'group', {
|
|
|
616
639
|
/** 发送者群名片 */
|
|
617
640
|
card: string;
|
|
618
641
|
/** 发送者群角色:owner-群主, admin-管理员, member-普通成员 */
|
|
619
|
-
role:
|
|
642
|
+
role: "owner" | "admin" | "member";
|
|
620
643
|
};
|
|
621
644
|
}>;
|
|
622
645
|
/** 消息事件联合类型 */
|
|
623
646
|
type MessageEvent = PrivateMessageEvent | GroupMessageEvent;
|
|
624
647
|
/**
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
type ToMessageSent<T extends MessageEvent> = Omit<T,
|
|
629
|
-
post_type:
|
|
648
|
+
* 将消息事件转换为发送消息事件类型
|
|
649
|
+
* @description 用于表示机器人自己发送的消息事件
|
|
650
|
+
*/
|
|
651
|
+
type ToMessageSent<T extends MessageEvent> = Omit<T, "post_type" | "group" | "friend" | "reply"> & {
|
|
652
|
+
post_type: "message_sent";
|
|
630
653
|
};
|
|
631
654
|
/**
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
type NoticeEventBase<T extends NoticeType, U$1 extends object> = EventBase<
|
|
655
|
+
* 通知事件基础类型
|
|
656
|
+
* @description 所有通知事件的基础结构
|
|
657
|
+
*/
|
|
658
|
+
type NoticeEventBase<T extends NoticeType, U$1 extends object> = EventBase<"notice", U$1 & {
|
|
636
659
|
/** 通知类型 */
|
|
637
660
|
notice_type: T;
|
|
638
661
|
/** 原始通知类型 */
|
|
639
662
|
original_notice_type: string;
|
|
640
663
|
}>;
|
|
641
664
|
/**
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
type GroupNoticeEventBase<T extends NoticeSubType, U$1 extends object> = NoticeEventBase<
|
|
665
|
+
* 群通知事件基础类型
|
|
666
|
+
* @description 所有群相关通知事件的基础结构
|
|
667
|
+
*/
|
|
668
|
+
type GroupNoticeEventBase<T extends NoticeSubType, U$1 extends object> = NoticeEventBase<"group", U$1 & {
|
|
646
669
|
/** 通知子类型 */
|
|
647
670
|
sub_type: T;
|
|
648
671
|
/** 群号 */
|
|
@@ -653,10 +676,10 @@ type GroupNoticeEventBase<T extends NoticeSubType, U$1 extends object> = NoticeE
|
|
|
653
676
|
group: Group;
|
|
654
677
|
}>;
|
|
655
678
|
/**
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
type FriendNoticeEventBase<T extends NoticeSubType, U$1 extends object> = NoticeEventBase<
|
|
679
|
+
* 好友通知事件基础类型
|
|
680
|
+
* @description 所有好友相关通知事件的基础结构
|
|
681
|
+
*/
|
|
682
|
+
type FriendNoticeEventBase<T extends NoticeSubType, U$1 extends object> = NoticeEventBase<"friend", U$1 & {
|
|
660
683
|
/** 通知子类型 */
|
|
661
684
|
sub_type: T;
|
|
662
685
|
/** 相关用户 QQ 号 */
|
|
@@ -665,16 +688,16 @@ type FriendNoticeEventBase<T extends NoticeSubType, U$1 extends object> = Notice
|
|
|
665
688
|
friend: Friend;
|
|
666
689
|
}>;
|
|
667
690
|
/** 好友增加通知事件 */
|
|
668
|
-
type FriendIncreaseNoticeEvent = FriendNoticeEventBase<
|
|
691
|
+
type FriendIncreaseNoticeEvent = FriendNoticeEventBase<"increase", {}>;
|
|
669
692
|
/** 好友减少通知事件 */
|
|
670
|
-
type FriendDecreaseNoticeEvent = FriendNoticeEventBase<
|
|
693
|
+
type FriendDecreaseNoticeEvent = FriendNoticeEventBase<"decrease", {}>;
|
|
671
694
|
/** 好友消息撤回通知事件 */
|
|
672
|
-
type FriendRecallNoticeEvent = FriendNoticeEventBase<
|
|
695
|
+
type FriendRecallNoticeEvent = FriendNoticeEventBase<"recall", {
|
|
673
696
|
/** 被撤回的消息 ID */
|
|
674
697
|
message_id: number;
|
|
675
698
|
}>;
|
|
676
699
|
/** 好友戳一戳通知事件 */
|
|
677
|
-
type FriendPokeNoticeEvent = FriendNoticeEventBase<
|
|
700
|
+
type FriendPokeNoticeEvent = FriendNoticeEventBase<"poke", {
|
|
678
701
|
/** 被戳者 QQ 号 */
|
|
679
702
|
target_id: number;
|
|
680
703
|
/** 发送者 QQ 号 */
|
|
@@ -683,7 +706,7 @@ type FriendPokeNoticeEvent = FriendNoticeEventBase<'poke', {
|
|
|
683
706
|
raw_info: any[];
|
|
684
707
|
}>;
|
|
685
708
|
/** 好友点赞通知事件 */
|
|
686
|
-
type FriendLikeNoticeEvent = FriendNoticeEventBase<
|
|
709
|
+
type FriendLikeNoticeEvent = FriendNoticeEventBase<"like", {
|
|
687
710
|
/** 操作者 QQ 号 */
|
|
688
711
|
operator_id: number;
|
|
689
712
|
/** 操作者昵称 */
|
|
@@ -692,7 +715,7 @@ type FriendLikeNoticeEvent = FriendNoticeEventBase<'like', {
|
|
|
692
715
|
times: number;
|
|
693
716
|
}>;
|
|
694
717
|
/** 好友输入状态通知事件 */
|
|
695
|
-
type FriendInputNoticeEvent = FriendNoticeEventBase<
|
|
718
|
+
type FriendInputNoticeEvent = FriendNoticeEventBase<"input", {
|
|
696
719
|
/** 状态文本 */
|
|
697
720
|
status_text: string;
|
|
698
721
|
/** 事件类型 */
|
|
@@ -701,54 +724,54 @@ type FriendInputNoticeEvent = FriendNoticeEventBase<'input', {
|
|
|
701
724
|
/** 好友通知事件联合类型 */
|
|
702
725
|
type FriendNoticeEvent = FriendIncreaseNoticeEvent | FriendDecreaseNoticeEvent | FriendRecallNoticeEvent | FriendPokeNoticeEvent | FriendLikeNoticeEvent | FriendInputNoticeEvent;
|
|
703
726
|
/** 群成员增加通知事件 */
|
|
704
|
-
type GroupIncreaseNoticeEvent = GroupNoticeEventBase<
|
|
727
|
+
type GroupIncreaseNoticeEvent = GroupNoticeEventBase<"increase", {
|
|
705
728
|
/** 操作者 QQ 号(如邀请者) */
|
|
706
729
|
operator_id: number;
|
|
707
730
|
/** 加入类型:invite-邀请, add-主动加群, approve-管理员审批 */
|
|
708
|
-
actions_type:
|
|
731
|
+
actions_type: "invite" | "add" | "approve";
|
|
709
732
|
}>;
|
|
710
733
|
/** 群成员减少通知事件 */
|
|
711
|
-
type GroupDecreaseNoticeEvent = GroupNoticeEventBase<
|
|
734
|
+
type GroupDecreaseNoticeEvent = GroupNoticeEventBase<"decrease", {
|
|
712
735
|
/** 操作者 QQ 号 */
|
|
713
736
|
operator_id: number;
|
|
714
737
|
/** 离开类型:kick-被踢, leave-主动退出 */
|
|
715
|
-
actions_type:
|
|
738
|
+
actions_type: "kick" | "leave";
|
|
716
739
|
}>;
|
|
717
740
|
/** 群管理员变动通知事件 */
|
|
718
|
-
type GroupAdminNoticeEvent = GroupNoticeEventBase<
|
|
741
|
+
type GroupAdminNoticeEvent = GroupNoticeEventBase<"admin", {
|
|
719
742
|
/** 操作类型:set-设置管理员, unset-取消管理员 */
|
|
720
|
-
action_type:
|
|
743
|
+
action_type: "set" | "unset";
|
|
721
744
|
}>;
|
|
722
745
|
/** 群禁言通知事件 */
|
|
723
|
-
type GroupBanNoticeEvent = GroupNoticeEventBase<
|
|
746
|
+
type GroupBanNoticeEvent = GroupNoticeEventBase<"ban", {
|
|
724
747
|
/** 禁言时长(秒),0 表示解除禁言 */
|
|
725
748
|
duration: number;
|
|
726
749
|
/** 操作类型:ban-禁言, lift_ban-解除禁言 */
|
|
727
|
-
action_type:
|
|
750
|
+
action_type: "ban" | "lift_ban";
|
|
728
751
|
/** 操作者 QQ 号 */
|
|
729
752
|
operator_id: number;
|
|
730
753
|
}>;
|
|
731
754
|
/** 群名片变动通知事件 */
|
|
732
|
-
type GroupCardNoticeEvent = GroupNoticeEventBase<
|
|
755
|
+
type GroupCardNoticeEvent = GroupNoticeEventBase<"card", {
|
|
733
756
|
/** 新名片 */
|
|
734
757
|
card_new: string;
|
|
735
758
|
/** 旧名片 */
|
|
736
759
|
card_old: string;
|
|
737
760
|
}>;
|
|
738
761
|
/** 群戳一戳通知事件 */
|
|
739
|
-
type GroupPokeNoticeEvent = GroupNoticeEventBase<
|
|
762
|
+
type GroupPokeNoticeEvent = GroupNoticeEventBase<"poke", {
|
|
740
763
|
/** 被戳者 QQ 号 */
|
|
741
764
|
target_id: number;
|
|
742
765
|
/** 原始信息 */
|
|
743
766
|
raw_info: any[];
|
|
744
767
|
}>;
|
|
745
768
|
/** 群头衔变动通知事件 */
|
|
746
|
-
type GroupTitleNoticeEvent = GroupNoticeEventBase<
|
|
769
|
+
type GroupTitleNoticeEvent = GroupNoticeEventBase<"title", {
|
|
747
770
|
/** 新头衔 */
|
|
748
771
|
title: string;
|
|
749
772
|
}>;
|
|
750
773
|
/** 群文件上传通知事件 */
|
|
751
|
-
type GroupUploadNoticeEvent = GroupNoticeEventBase<
|
|
774
|
+
type GroupUploadNoticeEvent = GroupNoticeEventBase<"upload", {
|
|
752
775
|
/** 上传的文件信息 */
|
|
753
776
|
file: {
|
|
754
777
|
/** 文件 ID */
|
|
@@ -762,7 +785,7 @@ type GroupUploadNoticeEvent = GroupNoticeEventBase<'upload', {
|
|
|
762
785
|
};
|
|
763
786
|
}>;
|
|
764
787
|
/** 群消息表态变动通知事件 */
|
|
765
|
-
type GroupReactionNoticeEvent = GroupNoticeEventBase<
|
|
788
|
+
type GroupReactionNoticeEvent = GroupNoticeEventBase<"reaction", {
|
|
766
789
|
/** 相关消息 ID */
|
|
767
790
|
message_id: number;
|
|
768
791
|
/** 表态列表 */
|
|
@@ -776,7 +799,7 @@ type GroupReactionNoticeEvent = GroupNoticeEventBase<'reaction', {
|
|
|
776
799
|
is_add: boolean;
|
|
777
800
|
}>;
|
|
778
801
|
/** 群精华消息变动通知事件 */
|
|
779
|
-
type GroupEssenceNoticeEvent = GroupNoticeEventBase<
|
|
802
|
+
type GroupEssenceNoticeEvent = GroupNoticeEventBase<"essence", {
|
|
780
803
|
/** 原消息发送者 QQ 号 */
|
|
781
804
|
sender_id: number;
|
|
782
805
|
/** 相关消息 ID */
|
|
@@ -784,10 +807,10 @@ type GroupEssenceNoticeEvent = GroupNoticeEventBase<'essence', {
|
|
|
784
807
|
/** 操作者 QQ 号 */
|
|
785
808
|
operator_id: number;
|
|
786
809
|
/** 操作类型:add-添加精华, remove-移除精华 */
|
|
787
|
-
action_type:
|
|
810
|
+
action_type: "add" | "remove";
|
|
788
811
|
}>;
|
|
789
812
|
/** 群消息撤回通知事件 */
|
|
790
|
-
type GroupRecallNoticeEvent = GroupNoticeEventBase<
|
|
813
|
+
type GroupRecallNoticeEvent = GroupNoticeEventBase<"recall", {
|
|
791
814
|
/** 被撤回的消息 ID */
|
|
792
815
|
message_id: number;
|
|
793
816
|
/** 操作者 QQ 号 */
|
|
@@ -798,10 +821,10 @@ type GroupNoticeEvent = GroupIncreaseNoticeEvent | GroupDecreaseNoticeEvent | Gr
|
|
|
798
821
|
/** 通知事件联合类型 */
|
|
799
822
|
type NoticeEvent = GroupNoticeEvent | FriendNoticeEvent;
|
|
800
823
|
/**
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
type RequestEventBase<T extends string, U$1 extends object> = EventBase<
|
|
824
|
+
* 请求事件基础类型
|
|
825
|
+
* @description 所有请求事件的基础结构
|
|
826
|
+
*/
|
|
827
|
+
type RequestEventBase<T extends string, U$1 extends object> = EventBase<"request", U$1 & {
|
|
805
828
|
/** 请求类型 */
|
|
806
829
|
request_type: T;
|
|
807
830
|
/** 请求者 QQ 号 */
|
|
@@ -812,153 +835,124 @@ type RequestEventBase<T extends string, U$1 extends object> = EventBase<'request
|
|
|
812
835
|
comment: string;
|
|
813
836
|
}>;
|
|
814
837
|
/** 好友添加请求事件 */
|
|
815
|
-
type FriendRequestEvent = RequestEventBase<
|
|
838
|
+
type FriendRequestEvent = RequestEventBase<"friend", {}>;
|
|
816
839
|
/** 加群请求事件(他人申请加入群) */
|
|
817
|
-
type GroupAddRequestEvent = RequestEventBase<
|
|
840
|
+
type GroupAddRequestEvent = RequestEventBase<"group", {
|
|
818
841
|
/** 群号 */
|
|
819
842
|
group_id: number;
|
|
820
843
|
/** 请求子类型:add-主动加群 */
|
|
821
|
-
sub_type:
|
|
844
|
+
sub_type: "add";
|
|
822
845
|
}>;
|
|
823
846
|
/** 邀请入群请求事件(他人邀请机器人入群) */
|
|
824
|
-
type GroupInviteRequestEvent = RequestEventBase<
|
|
847
|
+
type GroupInviteRequestEvent = RequestEventBase<"group", {
|
|
825
848
|
/** 群号 */
|
|
826
849
|
group_id: number;
|
|
827
850
|
/** 请求子类型:invite-被邀请 */
|
|
828
|
-
sub_type:
|
|
851
|
+
sub_type: "invite";
|
|
829
852
|
}>;
|
|
830
853
|
/** 群请求事件联合类型 */
|
|
831
854
|
type GroupRequestEvent = GroupAddRequestEvent | GroupInviteRequestEvent;
|
|
832
855
|
/** 请求事件联合类型 */
|
|
833
856
|
type RequestEvent = FriendRequestEvent | GroupRequestEvent;
|
|
834
857
|
/**
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
858
|
+
* OneBot 事件映射表
|
|
859
|
+
* @description 定义了所有事件名称与对应事件类型的映射关系
|
|
860
|
+
*/
|
|
838
861
|
interface OneBotEventMap {
|
|
839
862
|
/** 元事件,通常与 OneBot 服务端状态相关 */
|
|
840
863
|
meta_event: MetaEvent;
|
|
841
864
|
/** 元事件 - 心跳事件,确认服务端在线状态 */
|
|
842
|
-
|
|
865
|
+
"meta_event.heartbeat": HeartbeatMetaEvent;
|
|
843
866
|
/** 元事件 - 生命周期,服务端状态变化 */
|
|
844
|
-
|
|
867
|
+
"meta_event.lifecycle": LifecycleMetaEvent;
|
|
845
868
|
/** 元事件 - 生命周期 - 连接成功 */
|
|
846
|
-
|
|
869
|
+
"meta_event.lifecycle.connect": LifecycleMetaEvent;
|
|
847
870
|
/** 消息事件,包含私聊和群消息 */
|
|
848
871
|
message: MessageEvent;
|
|
849
872
|
/** 消息事件 - 私聊消息 */
|
|
850
|
-
|
|
873
|
+
"message.private": PrivateMessageEvent;
|
|
851
874
|
/** 消息事件 - 私聊消息 - 好友私聊 */
|
|
852
|
-
|
|
875
|
+
"message.private.friend": PrivateMessageEvent;
|
|
853
876
|
/** 消息事件 - 私聊消息 - 群临时会话 */
|
|
854
|
-
|
|
877
|
+
"message.private.group": PrivateMessageEvent;
|
|
855
878
|
/** 消息事件 - 群消息 */
|
|
856
|
-
|
|
879
|
+
"message.group": GroupMessageEvent;
|
|
857
880
|
/** 消息事件 - 群消息 - 普通消息 */
|
|
858
|
-
|
|
881
|
+
"message.group.normal": GroupMessageEvent;
|
|
859
882
|
message_sent: ToMessageSent<MessageEvent>;
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
883
|
+
"message_sent.private": ToMessageSent<PrivateMessageEvent>;
|
|
884
|
+
"message_sent.private.friend": ToMessageSent<PrivateMessageEvent>;
|
|
885
|
+
"message_sent.private.group": ToMessageSent<PrivateMessageEvent>;
|
|
886
|
+
"message_sent.group": ToMessageSent<GroupMessageEvent>;
|
|
887
|
+
"message_sent.group.normal": ToMessageSent<GroupMessageEvent>;
|
|
865
888
|
/** 请求事件 */
|
|
866
889
|
request: RequestEvent;
|
|
867
890
|
/** 请求事件 - 好友请求 */
|
|
868
|
-
|
|
891
|
+
"request.friend": FriendRequestEvent;
|
|
869
892
|
/** 请求事件 - 群请求 */
|
|
870
|
-
|
|
893
|
+
"request.group": GroupRequestEvent;
|
|
871
894
|
/** 请求事件 - 他人加群请求,当机器人是群主或管理员时收到 */
|
|
872
|
-
|
|
895
|
+
"request.group.add": GroupAddRequestEvent;
|
|
873
896
|
/** 请求事件 - 邀请加群请求,他人邀请机器人加入群时收到 */
|
|
874
|
-
|
|
897
|
+
"request.group.invite": GroupInviteRequestEvent;
|
|
875
898
|
/** 通知事件 */
|
|
876
899
|
notice: NoticeEvent;
|
|
877
900
|
/** 通知事件 - 好友相关通知 */
|
|
878
|
-
|
|
901
|
+
"notice.friend": FriendNoticeEvent;
|
|
879
902
|
/** 通知事件 - 好友增加 */
|
|
880
|
-
|
|
903
|
+
"notice.friend.increase": FriendIncreaseNoticeEvent;
|
|
881
904
|
/** 通知事件 - 好友减少 */
|
|
882
|
-
|
|
905
|
+
"notice.friend.decrease": FriendDecreaseNoticeEvent;
|
|
883
906
|
/** 通知事件 - 好友备注变更 */
|
|
884
|
-
|
|
907
|
+
"notice.friend.recall": FriendRecallNoticeEvent;
|
|
885
908
|
/** 通知事件 - 好友戳一戳 */
|
|
886
|
-
|
|
909
|
+
"notice.friend.poke": FriendPokeNoticeEvent;
|
|
887
910
|
/** 通知事件 - 好友点赞 */
|
|
888
|
-
|
|
911
|
+
"notice.friend.like": FriendLikeNoticeEvent;
|
|
889
912
|
/** 通知事件 - 好友输入状态 */
|
|
890
|
-
|
|
913
|
+
"notice.friend.input": FriendInputNoticeEvent;
|
|
891
914
|
/** 通知事件 - 群相关通知 */
|
|
892
|
-
|
|
915
|
+
"notice.group": GroupNoticeEvent;
|
|
893
916
|
/** 通知事件 - 群成员增加 */
|
|
894
|
-
|
|
917
|
+
"notice.group.increase": GroupIncreaseNoticeEvent;
|
|
895
918
|
/** 通知事件 - 群成员减少 */
|
|
896
|
-
|
|
919
|
+
"notice.group.decrease": GroupDecreaseNoticeEvent;
|
|
897
920
|
/** 通知事件 - 群管理员变更 */
|
|
898
|
-
|
|
921
|
+
"notice.group.admin": GroupAdminNoticeEvent;
|
|
899
922
|
/** 通知事件 - 群成员被禁言 */
|
|
900
|
-
|
|
923
|
+
"notice.group.ban": GroupBanNoticeEvent;
|
|
901
924
|
/** 通知事件 - 群戳一戳 */
|
|
902
|
-
|
|
925
|
+
"notice.group.poke": GroupPokeNoticeEvent;
|
|
903
926
|
/** 通知事件 - 群头衔变更 */
|
|
904
|
-
|
|
927
|
+
"notice.group.title": GroupTitleNoticeEvent;
|
|
905
928
|
/** 通知事件 - 群名片变更 */
|
|
906
|
-
|
|
929
|
+
"notice.group.card": GroupCardNoticeEvent;
|
|
907
930
|
/** 通知事件 - 群公告变更 */
|
|
908
|
-
|
|
931
|
+
"notice.group.recall": GroupRecallNoticeEvent;
|
|
909
932
|
/** 通知事件 - 群上传文件 */
|
|
910
|
-
|
|
933
|
+
"notice.group.upload": GroupUploadNoticeEvent;
|
|
911
934
|
/** 通知事件 - 给群消息添加反应 Reaction */
|
|
912
|
-
|
|
935
|
+
"notice.group.reaction": GroupReactionNoticeEvent;
|
|
913
936
|
/** 通知事件 - 群精华消息变更 */
|
|
914
|
-
|
|
937
|
+
"notice.group.essence": GroupEssenceNoticeEvent;
|
|
915
938
|
}
|
|
916
939
|
/**
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
type OneBotAPI =
|
|
940
|
+
* OneBot 11 标准 API
|
|
941
|
+
* @description OneBot 11 规范定义的标准 API 接口
|
|
942
|
+
*/
|
|
943
|
+
type OneBotAPI = "delete_friend" | "delete_msg" | "get_forward_msg" | "get_friend_list" | "get_group_info" | "get_group_list" | "get_group_member_info" | "get_group_member_list" | "get_group_msg_history" | "get_login_info" | "get_msg" | "get_status" | "get_stranger_info" | "send_group_msg" | "send_private_msg" | "set_friend_add_request" | "set_group_add_request" | "set_group_admin" | "set_group_ban" | "set_group_card" | "set_group_kick" | "set_group_leave" | "set_group_name" | "set_group_portrait" | "set_group_special_title" | "set_qq_profile";
|
|
921
944
|
/**
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
type NapCatExtendAPI =
|
|
945
|
+
* NapCat 扩展 API
|
|
946
|
+
* @description NapCat 实现的额外扩展 API 接口
|
|
947
|
+
*/
|
|
948
|
+
type NapCatExtendAPI = "_del_group_notice" | "_get_group_notice" | "_get_model_show" | "_mark_all_as_read" | "_send_group_notice" | "_set_model_show" | ".handle_quick_operation" | ".ocr_image" | "ArkShareGroup" | "ArkSharePeer" | "bot_exit" | "can_send_image" | "can_send_record" | "clean_cache" | "click_inline_keyboard_button" | "create_collection" | "create_group_file_folder" | "delete_essence_msg" | "delete_group_file" | "delete_group_folder" | "download_file" | "fetch_custom_face" | "fetch_emoji_like" | "forward_friend_single_msg" | "forward_group_single_msg" | "friend_poke" | "get_ai_characters" | "get_ai_record" | "get_clientkey" | "get_collection_list" | "get_cookies" | "get_credentials" | "get_csrf_token" | "get_doubt_friends_add_request" | "get_essence_msg_list" | "get_file" | "get_friend_msg_history" | "get_friends_with_category" | "get_group_at_all_remain" | "get_group_detail_info" | "get_group_file_system_info" | "get_group_file_url" | "get_group_files_by_folder" | "get_group_honor_info" | "get_group_ignored_notifies" | "get_group_info_ex" | "get_group_root_files" | "get_group_shut_list" | "get_group_system_msg" | "get_image" | "get_mini_app_ark" | "get_online_clients" | "get_private_file_url" | "get_profile_like" | "get_recent_contact" | "get_record" | "get_rkey_server" | "get_rkey" | "get_robot_uin_range" | "get_unidirectional_friend_list" | "get_version_info" | "group_poke" | "mark_group_msg_as_read" | "mark_msg_as_read" | "mark_private_msg_as_read" | "move_group_file" | "nc_get_packet_status" | "nc_get_rkey" | "nc_get_user_status" | "ocr_image" | "rename_group_file" | "send_forward_msg" | "send_group_ai_record" | "send_group_sign" | "send_like" | "send_packet" | "send_poke" | "set_diy_online_status" | "set_essence_msg" | "set_friend_remark" | "set_group_add_option" | "set_group_kick_members" | "set_group_remark" | "set_group_robot_add_option" | "set_group_search" | "set_group_sign" | "set_group_whole_ban" | "set_input_status" | "set_msg_emoji_like" | "set_online_status" | "set_qq_avatar" | "set_self_longnick" | "trans_group_file" | "translate_en2zh" | "upload_group_file" | "upload_private_file";
|
|
926
949
|
/** 所有可用的 API 接口联合类型 */
|
|
927
950
|
type API = OneBotAPI | NapCatExtendAPI;
|
|
928
951
|
//#endregion
|
|
929
|
-
//#region src/types.d.ts
|
|
930
|
-
interface MiokiOptions {
|
|
931
|
-
/** NapCat 访问令牌 */
|
|
932
|
-
token: string;
|
|
933
|
-
/** NapCat 服务器协议,默认为 ws */
|
|
934
|
-
protocol?: 'ws' | 'wss';
|
|
935
|
-
/** NapCat 服务器主机,默认为 localhost */
|
|
936
|
-
host?: string;
|
|
937
|
-
/** NapCat 服务器端口,默认为 3333 */
|
|
938
|
-
port?: number;
|
|
939
|
-
/** 日志记录器,默认为控制台日志记录器 */
|
|
940
|
-
logger?: Logger;
|
|
941
|
-
}
|
|
942
|
-
type OptionalKeys<T> = { [K in keyof T]-?: {} extends Pick<T, K> ? K : never }[keyof T];
|
|
943
|
-
type OptionalProps<T> = Pick<T, OptionalKeys<T>>;
|
|
944
|
-
type ExtractByType<T, K$1> = T extends {
|
|
945
|
-
type: K$1;
|
|
946
|
-
} ? T : never;
|
|
947
|
-
interface EventMap extends OneBotEventMap {
|
|
948
|
-
/** WebSocket 连接已打开 */
|
|
949
|
-
'ws.open': void;
|
|
950
|
-
/** WebSocket 连接已关闭 */
|
|
951
|
-
'ws.close': void;
|
|
952
|
-
/** WebSocket 连接发生错误 */
|
|
953
|
-
'ws.error': Event;
|
|
954
|
-
/** 收到 WebSocket 消息 */
|
|
955
|
-
'ws.message': any;
|
|
956
|
-
}
|
|
957
|
-
//#endregion
|
|
958
952
|
//#region src/segment.d.ts
|
|
959
953
|
/**
|
|
960
|
-
|
|
961
|
-
|
|
954
|
+
* 消息片段构造器
|
|
955
|
+
*/
|
|
962
956
|
declare const segment: {
|
|
963
957
|
/** 创建一个文本消息片段 */
|
|
964
958
|
text: (text: string) => SendElement;
|
|
@@ -987,6 +981,8 @@ declare const segment: {
|
|
|
987
981
|
/** 创建一个自定义音乐消息片段 */
|
|
988
982
|
musicCustom: (title: string, audio: string, url: string, options?: Omit<ExtractByType<SendElement, "music">, "type" | "platform" | "url" | "audio" | "title">) => SendElement;
|
|
989
983
|
/** 创建一个合并转发消息片段 */
|
|
984
|
+
node: (options: Partial<ExtractByType<SendElement, "node">>) => SendElement;
|
|
985
|
+
/** 创建一个合并转发消息片段 */
|
|
990
986
|
forward: (id: string) => SendElement;
|
|
991
987
|
/** 创建一个 JSON 消息片段 */
|
|
992
988
|
json: (data: string) => SendElement;
|
|
@@ -1001,12 +997,6 @@ declare const segment: {
|
|
|
1001
997
|
//#region src/napcat.d.ts
|
|
1002
998
|
declare const name: string;
|
|
1003
999
|
declare const version: string;
|
|
1004
|
-
declare const DEFAULT_NAPCAT_OPTIONS: {
|
|
1005
|
-
protocol: "ws";
|
|
1006
|
-
host: string;
|
|
1007
|
-
port: number;
|
|
1008
|
-
logger: Logger;
|
|
1009
|
-
};
|
|
1010
1000
|
declare class NapCat {
|
|
1011
1001
|
#private;
|
|
1012
1002
|
private readonly options;
|
|
@@ -1017,44 +1007,109 @@ declare class NapCat {
|
|
|
1017
1007
|
get logger(): Logger;
|
|
1018
1008
|
/** 消息段构建器 */
|
|
1019
1009
|
get segment(): typeof segment;
|
|
1010
|
+
/**
|
|
1011
|
+
* 机器人 QQ 号
|
|
1012
|
+
*/
|
|
1013
|
+
get user_id(): number;
|
|
1014
|
+
/**
|
|
1015
|
+
* 机器人 QQ 号
|
|
1016
|
+
*/
|
|
1017
|
+
get uin(): number;
|
|
1018
|
+
/**
|
|
1019
|
+
* 机器人昵称
|
|
1020
|
+
*/
|
|
1021
|
+
get nickname(): string;
|
|
1020
1022
|
/** 获取一个群的信息,可以用于发送群消息等操作 */
|
|
1021
|
-
pickGroup(group_id: number): Promise<GroupWithInfo>;
|
|
1023
|
+
pickGroup(group_id: number): Promise<GroupWithInfo | null>;
|
|
1022
1024
|
/** 获取一个好友的信息,可以用于发送私聊消息等操作 */
|
|
1023
|
-
pickFriend(user_id: number): Promise<FriendWithInfo>;
|
|
1025
|
+
pickFriend(user_id: number): Promise<FriendWithInfo | null>;
|
|
1024
1026
|
/**
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
+
* 注册一次性事件监听器
|
|
1028
|
+
*/
|
|
1027
1029
|
once<T extends keyof EventMap>(type: T, handler: (event: EventMap[NoInfer<T>]) => void): void;
|
|
1028
1030
|
/**
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1031
|
+
* 注册事件监听器,支持主类型或者点分子类型
|
|
1032
|
+
*
|
|
1033
|
+
* 如: `notice`、`message.private`、`request.group.invite` 等
|
|
1034
|
+
*
|
|
1035
|
+
* 如果需要移除监听器,请调用 `off` 方法
|
|
1036
|
+
*/
|
|
1035
1037
|
on<T extends keyof EventMap>(type: T, handler: (event: EventMap[NoInfer<T>]) => void): void;
|
|
1036
1038
|
/**
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
+
* 移除事件监听器
|
|
1040
|
+
*/
|
|
1039
1041
|
off<T extends keyof EventMap>(type: T, handler: (event: EventMap[NoInfer<T>]) => void): void;
|
|
1042
|
+
/**
|
|
1043
|
+
* 调用 NapCat API
|
|
1044
|
+
*/
|
|
1040
1045
|
api<T extends any>(action: API | (string & {}), params?: Record<string, any>): Promise<T>;
|
|
1041
1046
|
/**
|
|
1042
|
-
|
|
1043
|
-
|
|
1047
|
+
* 发送私聊消息
|
|
1048
|
+
*/
|
|
1044
1049
|
sendPrivateMsg(user_id: number, sendable: Sendable | Sendable[]): Promise<{
|
|
1045
1050
|
message_id: number;
|
|
1046
1051
|
}>;
|
|
1047
1052
|
/**
|
|
1048
|
-
|
|
1049
|
-
|
|
1053
|
+
* 发送群消息
|
|
1054
|
+
*/
|
|
1050
1055
|
sendGroupMsg(group_id: number, sendable: Sendable | Sendable[]): Promise<{
|
|
1051
1056
|
message_id: number;
|
|
1052
1057
|
}>;
|
|
1058
|
+
/**
|
|
1059
|
+
* 机器人是否在线
|
|
1060
|
+
*/
|
|
1061
|
+
isOnline(): boolean;
|
|
1062
|
+
/**
|
|
1063
|
+
* 计算 GTK 值
|
|
1064
|
+
*/
|
|
1065
|
+
getGTk(pskey: string): number;
|
|
1066
|
+
/**
|
|
1067
|
+
* 获取 NapCat 原始 Cookie 相关信息
|
|
1068
|
+
*/
|
|
1069
|
+
getNapCatCookies(domain: string): Promise<{
|
|
1070
|
+
cookies: string;
|
|
1071
|
+
bkn: string;
|
|
1072
|
+
}>;
|
|
1073
|
+
/**
|
|
1074
|
+
* 获取版本信息
|
|
1075
|
+
*/
|
|
1076
|
+
getVersionInfo(): Promise<{
|
|
1077
|
+
app_name: string;
|
|
1078
|
+
protocol_version: string;
|
|
1079
|
+
app_version: string;
|
|
1080
|
+
}>;
|
|
1081
|
+
/**
|
|
1082
|
+
* 获取登录信息
|
|
1083
|
+
*/
|
|
1084
|
+
getLoginInfo(): Promise<{
|
|
1085
|
+
user_id: number;
|
|
1086
|
+
nickname: string;
|
|
1087
|
+
}>;
|
|
1088
|
+
/**
|
|
1089
|
+
* 获取 Cookie 相关信息
|
|
1090
|
+
*/
|
|
1091
|
+
getCookie(domain: string): Promise<{
|
|
1092
|
+
uin: number;
|
|
1093
|
+
pskey: string;
|
|
1094
|
+
skey: string;
|
|
1095
|
+
gtk: string;
|
|
1096
|
+
bkn: string;
|
|
1097
|
+
cookie: string;
|
|
1098
|
+
legacyCookie: string;
|
|
1099
|
+
}>;
|
|
1100
|
+
/**
|
|
1101
|
+
* 通过域名获取 Pskey
|
|
1102
|
+
*/
|
|
1103
|
+
getPskey(domain: string): Promise<string>;
|
|
1104
|
+
/**
|
|
1105
|
+
* 获取 Bkn 值
|
|
1106
|
+
*/
|
|
1107
|
+
getBkn(): Promise<string>;
|
|
1053
1108
|
/** 启动 NapCat SDK 实例,建立 WebSocket 连接 */
|
|
1054
|
-
|
|
1109
|
+
run(): Promise<void>;
|
|
1055
1110
|
/** 销毁 NapCat SDK 实例,关闭 WebSocket 连接 */
|
|
1056
|
-
|
|
1111
|
+
close(): void;
|
|
1057
1112
|
}
|
|
1058
1113
|
//#endregion
|
|
1059
|
-
export { ABSTRACT_LOGGER, CONSOLE_LOGGER,
|
|
1114
|
+
export { ABSTRACT_LOGGER, API, CONSOLE_LOGGER, EventBase, EventMap, ExtractByType, FlattenData, Friend, FriendDecreaseNoticeEvent, FriendIncreaseNoticeEvent, FriendInputNoticeEvent, FriendLikeNoticeEvent, FriendNoticeEvent, FriendNoticeEventBase, FriendPokeNoticeEvent, FriendRecallNoticeEvent, FriendRequestEvent, FriendWithInfo, Group, GroupAddRequestEvent, GroupAdminNoticeEvent, GroupBanNoticeEvent, GroupCardNoticeEvent, GroupDecreaseNoticeEvent, GroupEssenceNoticeEvent, GroupIncreaseNoticeEvent, GroupInviteRequestEvent, GroupMessageEvent, GroupNoticeEvent, GroupNoticeEventBase, GroupPokeNoticeEvent, GroupReactionNoticeEvent, GroupRecallNoticeEvent, GroupRequestEvent, GroupTitleNoticeEvent, GroupUploadNoticeEvent, GroupWithInfo, HeartbeatMetaEvent, LifecycleMetaEvent, LogLevel, Logger, MediaProps, MessageEvent, MessageEventBase, MessageType, MetaEvent, MetaEventBase, MetaEventType, MiokiOptions, NapCat, NapCatExtendAPI, NormalizedElementToSend, NoticeEvent, NoticeEventBase, NoticeSubType, NoticeType, OneBotAPI, OneBotEventMap, OptionalKeys, OptionalProps, PostType, PrivateMessageEvent, RecvAtElement, RecvDiceElement, RecvElement, RecvFaceElement, RecvFileElement, RecvForwardElement, RecvImageElement, RecvJsonElement, RecvLightAppElement, RecvLocationElement, RecvMarkdownElement, RecvPokeElement, RecvRecordElement, RecvReplyElement, RecvRpsElement, RecvShakeElement, RecvShareElement, RecvTextElement, RecvVideoElement, RequestEvent, RequestEventBase, SendAtElement, SendBfaceElement, SendContactElement, SendCustomMusicElement, SendElement, SendFaceElement, SendFileElement, SendForwardElement, SendImageElement, SendJsonElement, SendLightAppElement, SendMarkdownElement, SendMfaceElement, SendMusicElement, SendNodeContentElement, SendNodeElement, SendNodeRefElement, SendPlatformMusicElement, SendPokeElement, SendRecordElement, SendReplyElement, SendTextElement, SendVideoElement, Sendable, WrapData, name, noop, segment, version };
|
|
1060
1115
|
//# sourceMappingURL=index.d.mts.map
|