hotcat-bot-qq 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 +53 -0
- package/dist/botApi.d.ts +1163 -0
- package/dist/botApi.js +794 -0
- package/dist/botClient.d.ts +35 -0
- package/dist/botClient.js +75 -0
- package/dist/botConsole.d.ts +72 -0
- package/dist/botConsole.js +297 -0
- package/dist/botEvent.d.ts +182 -0
- package/dist/botEvent.js +557 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +5 -0
- package/dist/message.d.ts +96 -0
- package/dist/message.js +187 -0
- package/logo.png +0 -0
- package/package.json +73 -0
package/dist/botEvent.js
ADDED
|
@@ -0,0 +1,557 @@
|
|
|
1
|
+
import { BotConsole } from './botConsole';
|
|
2
|
+
/**
|
|
3
|
+
* 当接收到消息时触发的事件。
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* bot.event.message.onGroupMessage(async (bot, event) => {
|
|
8
|
+
* await bot.api.sendGroupMessage(event.group_id, Message.text('收到'));
|
|
9
|
+
* });
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export class MessageEvent {
|
|
13
|
+
constructor(napcat, client) {
|
|
14
|
+
Object.defineProperty(this, "napcat", {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
configurable: true,
|
|
17
|
+
writable: true,
|
|
18
|
+
value: void 0
|
|
19
|
+
});
|
|
20
|
+
Object.defineProperty(this, "client", {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
configurable: true,
|
|
23
|
+
writable: true,
|
|
24
|
+
value: void 0
|
|
25
|
+
});
|
|
26
|
+
this.napcat = napcat;
|
|
27
|
+
this.client = client;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* 注册群消息事件回调
|
|
31
|
+
* @param fn - 回调 `(bot, event) => any`
|
|
32
|
+
*/
|
|
33
|
+
onGroupMessage(fn) {
|
|
34
|
+
this.napcat.on('message.group', async (event) => {
|
|
35
|
+
try {
|
|
36
|
+
new BotConsole('groupMessage', event).log();
|
|
37
|
+
await fn(this.client, event);
|
|
38
|
+
}
|
|
39
|
+
catch (e) {
|
|
40
|
+
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* 注册群消息普通事件回调
|
|
46
|
+
* @param fn - 回调 `(bot, event) => any`
|
|
47
|
+
*/
|
|
48
|
+
onGroupNormal(fn) {
|
|
49
|
+
this.napcat.on('message.group.normal', async (event) => {
|
|
50
|
+
try {
|
|
51
|
+
new BotConsole('groupMessage', event).log();
|
|
52
|
+
await fn(this.client, event);
|
|
53
|
+
}
|
|
54
|
+
catch (e) {
|
|
55
|
+
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* 注册私聊消息事件回调
|
|
61
|
+
* @param fn - 回调 `(bot, event) => any`
|
|
62
|
+
*/
|
|
63
|
+
onPrivateMessage(fn) {
|
|
64
|
+
this.napcat.on('message.private', async (event) => {
|
|
65
|
+
try {
|
|
66
|
+
new BotConsole('privateMessage', event).log();
|
|
67
|
+
await fn(this.client, event);
|
|
68
|
+
}
|
|
69
|
+
catch (e) {
|
|
70
|
+
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* 注册私聊消息好友事件回调
|
|
76
|
+
* @param fn - 回调 `(bot, event) => any`
|
|
77
|
+
*/
|
|
78
|
+
onPrivateFriend(fn) {
|
|
79
|
+
this.napcat.on('message.private.friend', async (event) => {
|
|
80
|
+
try {
|
|
81
|
+
new BotConsole('privateMessage', event).log();
|
|
82
|
+
await fn(this.client, event);
|
|
83
|
+
}
|
|
84
|
+
catch (e) {
|
|
85
|
+
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* 注册私聊消息群临时事件回调
|
|
91
|
+
* @param fn - 回调 `(bot, event) => any`
|
|
92
|
+
*/
|
|
93
|
+
onPrivateGroup(fn) {
|
|
94
|
+
this.napcat.on('message.private.group', async (event) => {
|
|
95
|
+
try {
|
|
96
|
+
new BotConsole('privateMessage', event).log();
|
|
97
|
+
await fn(this.client, event);
|
|
98
|
+
}
|
|
99
|
+
catch (e) {
|
|
100
|
+
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* 当 bot 自身发出消息后的事件。
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```ts
|
|
110
|
+
* bot.event.messageSent.onGroupSent(async (bot, event) => {
|
|
111
|
+
* console.log('群消息已发送:', event.message_id);
|
|
112
|
+
* });
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
export class MessageSent {
|
|
116
|
+
constructor(napcat, client) {
|
|
117
|
+
Object.defineProperty(this, "napcat", {
|
|
118
|
+
enumerable: true,
|
|
119
|
+
configurable: true,
|
|
120
|
+
writable: true,
|
|
121
|
+
value: void 0
|
|
122
|
+
});
|
|
123
|
+
Object.defineProperty(this, "client", {
|
|
124
|
+
enumerable: true,
|
|
125
|
+
configurable: true,
|
|
126
|
+
writable: true,
|
|
127
|
+
value: void 0
|
|
128
|
+
});
|
|
129
|
+
this.napcat = napcat;
|
|
130
|
+
this.client = client;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* 注册群消息发送回执
|
|
134
|
+
* @param fn - 回调 `(bot, event) => any`
|
|
135
|
+
*/
|
|
136
|
+
onGroupSent(fn) {
|
|
137
|
+
this.napcat.on('message_sent.group', async (event) => {
|
|
138
|
+
try {
|
|
139
|
+
new BotConsole('groupMessageSelf', event).log();
|
|
140
|
+
await fn(this.client, event);
|
|
141
|
+
}
|
|
142
|
+
catch (e) {
|
|
143
|
+
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* 注册群消息发送回执(仅普通消息)
|
|
149
|
+
* @param fn - 回调 `(bot, event) => any`
|
|
150
|
+
*/
|
|
151
|
+
onGroupNormal(fn) {
|
|
152
|
+
this.napcat.on('message_sent.group.normal', async (event) => {
|
|
153
|
+
try {
|
|
154
|
+
new BotConsole('groupMessageSelf', event).log();
|
|
155
|
+
await fn(this.client, event);
|
|
156
|
+
}
|
|
157
|
+
catch (e) {
|
|
158
|
+
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* 注册私聊消息发送回执
|
|
164
|
+
* @param fn - 回调 `(bot, event) => any`
|
|
165
|
+
*/
|
|
166
|
+
onPrivateSent(fn) {
|
|
167
|
+
this.napcat.on('message_sent.private', async (event) => {
|
|
168
|
+
try {
|
|
169
|
+
new BotConsole('privateMessageSelf', event).log();
|
|
170
|
+
await fn(this.client, event);
|
|
171
|
+
}
|
|
172
|
+
catch (e) {
|
|
173
|
+
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* 注册私聊好友消息发送回执
|
|
179
|
+
* @param fn - 回调 `(bot, event) => any`
|
|
180
|
+
*/
|
|
181
|
+
onPrivateFriend(fn) {
|
|
182
|
+
this.napcat.on('message_sent.private.friend', async (event) => {
|
|
183
|
+
try {
|
|
184
|
+
new BotConsole('privateMessageSelf', event).log();
|
|
185
|
+
await fn(this.client, event);
|
|
186
|
+
}
|
|
187
|
+
catch (e) {
|
|
188
|
+
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* 注册私聊群临时消息发送回执
|
|
194
|
+
* @param fn - 回调 `(bot, event) => any`
|
|
195
|
+
*/
|
|
196
|
+
onPrivateGroup(fn) {
|
|
197
|
+
this.napcat.on('message_sent.private.group', async (event) => {
|
|
198
|
+
try {
|
|
199
|
+
new BotConsole('privateMessageSelf', event).log();
|
|
200
|
+
await fn(this.client, event);
|
|
201
|
+
}
|
|
202
|
+
catch (e) {
|
|
203
|
+
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* 请求事件监听(加好友、加群、邀请入群)。
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* ```ts
|
|
213
|
+
* bot.event.request.onFriend(async (bot, event) => {
|
|
214
|
+
* await bot.api.handleFriendAddRequest(event.flag, true);
|
|
215
|
+
* });
|
|
216
|
+
* ```
|
|
217
|
+
*/
|
|
218
|
+
export class RequestEvent {
|
|
219
|
+
constructor(napcat, client) {
|
|
220
|
+
Object.defineProperty(this, "napcat", {
|
|
221
|
+
enumerable: true,
|
|
222
|
+
configurable: true,
|
|
223
|
+
writable: true,
|
|
224
|
+
value: void 0
|
|
225
|
+
});
|
|
226
|
+
Object.defineProperty(this, "client", {
|
|
227
|
+
enumerable: true,
|
|
228
|
+
configurable: true,
|
|
229
|
+
writable: true,
|
|
230
|
+
value: void 0
|
|
231
|
+
});
|
|
232
|
+
this.napcat = napcat;
|
|
233
|
+
this.client = client;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* 注册加好友请求回调
|
|
237
|
+
* @param fn - 回调 `(bot, event) => any`,event.flag 可传给 handleFriendAddRequest
|
|
238
|
+
*/
|
|
239
|
+
onFriend(fn) {
|
|
240
|
+
this.napcat.on('request.friend', async (event) => {
|
|
241
|
+
try {
|
|
242
|
+
new BotConsole('requestFriend', event).log();
|
|
243
|
+
await fn(this.client, event);
|
|
244
|
+
}
|
|
245
|
+
catch (e) {
|
|
246
|
+
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* 注册加群请求回调
|
|
252
|
+
* @param fn - 回调 `(bot, event) => any`,event.flag 可传给 handleGroupAddRequest
|
|
253
|
+
*/
|
|
254
|
+
onGroupAdd(fn) {
|
|
255
|
+
this.napcat.on('request.group.add', async (event) => {
|
|
256
|
+
try {
|
|
257
|
+
new BotConsole('requestGroupAdd', event).log();
|
|
258
|
+
await fn(this.client, event);
|
|
259
|
+
}
|
|
260
|
+
catch (e) {
|
|
261
|
+
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* 注册邀请入群回调
|
|
267
|
+
* @param fn - 回调 `(bot, event) => any`
|
|
268
|
+
*/
|
|
269
|
+
onGroupInvite(fn) {
|
|
270
|
+
this.napcat.on('request.group.invite', async (event) => {
|
|
271
|
+
try {
|
|
272
|
+
new BotConsole('requestGroupInvite', event).log();
|
|
273
|
+
await fn(this.client, event);
|
|
274
|
+
}
|
|
275
|
+
catch (e) {
|
|
276
|
+
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* 注册所有群请求回调(加群 + 邀请)
|
|
282
|
+
* @param fn - 回调 `(bot, event) => any`
|
|
283
|
+
*/
|
|
284
|
+
onGroupRequest(fn) {
|
|
285
|
+
this.napcat.on('request.group', async (event) => {
|
|
286
|
+
try {
|
|
287
|
+
const type = event.sub_type === 'add' ? 'requestGroupAdd' : 'requestGroupInvite';
|
|
288
|
+
new BotConsole(type, event).log();
|
|
289
|
+
await fn(this.client, event);
|
|
290
|
+
}
|
|
291
|
+
catch (e) {
|
|
292
|
+
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* 通知事件监听(好友添加、群成员变动、禁言、撤回等)。
|
|
299
|
+
*
|
|
300
|
+
* @example
|
|
301
|
+
* ```ts
|
|
302
|
+
* bot.event.notice.onFriendAdd(async (bot, event) => { ... });
|
|
303
|
+
* bot.event.notice.onGroupIncrease(async (bot, event) => { ... });
|
|
304
|
+
* ```
|
|
305
|
+
*/
|
|
306
|
+
export class NoticeEvent {
|
|
307
|
+
constructor(napcat, client) {
|
|
308
|
+
Object.defineProperty(this, "napcat", {
|
|
309
|
+
enumerable: true,
|
|
310
|
+
configurable: true,
|
|
311
|
+
writable: true,
|
|
312
|
+
value: void 0
|
|
313
|
+
});
|
|
314
|
+
Object.defineProperty(this, "client", {
|
|
315
|
+
enumerable: true,
|
|
316
|
+
configurable: true,
|
|
317
|
+
writable: true,
|
|
318
|
+
value: void 0
|
|
319
|
+
});
|
|
320
|
+
this.napcat = napcat;
|
|
321
|
+
this.client = client;
|
|
322
|
+
}
|
|
323
|
+
/** 好友添加 */
|
|
324
|
+
onFriendAdd(fn) {
|
|
325
|
+
this.napcat.on('notice.friend_add', async (event) => {
|
|
326
|
+
try {
|
|
327
|
+
new BotConsole('notice', event).log();
|
|
328
|
+
await fn(this.client, event);
|
|
329
|
+
}
|
|
330
|
+
catch (e) {
|
|
331
|
+
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
332
|
+
}
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
/** 私聊消息撤回 */
|
|
336
|
+
onFriendRecall(fn) {
|
|
337
|
+
this.napcat.on('notice.friend_recall', async (event) => {
|
|
338
|
+
try {
|
|
339
|
+
new BotConsole('notice', event).log();
|
|
340
|
+
await fn(this.client, event);
|
|
341
|
+
}
|
|
342
|
+
catch (e) {
|
|
343
|
+
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
/** 群管理员变动(设置/取消) */
|
|
348
|
+
onGroupAdmin(fn) {
|
|
349
|
+
this.napcat.on('notice.group_admin', async (event) => {
|
|
350
|
+
try {
|
|
351
|
+
new BotConsole('notice', event).log();
|
|
352
|
+
await fn(this.client, event);
|
|
353
|
+
}
|
|
354
|
+
catch (e) {
|
|
355
|
+
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
356
|
+
}
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
/** 群禁言变动(禁言/解除) */
|
|
360
|
+
onGroupBan(fn) {
|
|
361
|
+
this.napcat.on('notice.group_ban', async (event) => {
|
|
362
|
+
try {
|
|
363
|
+
new BotConsole('notice', event).log();
|
|
364
|
+
await fn(this.client, event);
|
|
365
|
+
}
|
|
366
|
+
catch (e) {
|
|
367
|
+
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
368
|
+
}
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
/** 群名片变更 */
|
|
372
|
+
onGroupCard(fn) {
|
|
373
|
+
this.napcat.on('notice.group_card', async (event) => {
|
|
374
|
+
try {
|
|
375
|
+
new BotConsole('notice', event).log();
|
|
376
|
+
await fn(this.client, event);
|
|
377
|
+
}
|
|
378
|
+
catch (e) {
|
|
379
|
+
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
/** 群成员减少(退群/被踢/bot被踢) */
|
|
384
|
+
onGroupDecrease(fn) {
|
|
385
|
+
this.napcat.on('notice.group_decrease', async (event) => {
|
|
386
|
+
try {
|
|
387
|
+
new BotConsole('notice', event).log();
|
|
388
|
+
await fn(this.client, event);
|
|
389
|
+
}
|
|
390
|
+
catch (e) {
|
|
391
|
+
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
392
|
+
}
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
/** 群成员增加(审批/邀请) */
|
|
396
|
+
onGroupIncrease(fn) {
|
|
397
|
+
this.napcat.on('notice.group_increase', async (event) => {
|
|
398
|
+
try {
|
|
399
|
+
new BotConsole('notice', event).log();
|
|
400
|
+
await fn(this.client, event);
|
|
401
|
+
}
|
|
402
|
+
catch (e) {
|
|
403
|
+
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
/** 群消息撤回 */
|
|
408
|
+
onGroupRecall(fn) {
|
|
409
|
+
this.napcat.on('notice.group_recall', async (event) => {
|
|
410
|
+
try {
|
|
411
|
+
new BotConsole('notice', event).log();
|
|
412
|
+
await fn(this.client, event);
|
|
413
|
+
}
|
|
414
|
+
catch (e) {
|
|
415
|
+
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
416
|
+
}
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
/** 群文件上传 */
|
|
420
|
+
onGroupUpload(fn) {
|
|
421
|
+
this.napcat.on('notice.group_upload', async (event) => {
|
|
422
|
+
try {
|
|
423
|
+
new BotConsole('notice', event).log();
|
|
424
|
+
await fn(this.client, event);
|
|
425
|
+
}
|
|
426
|
+
catch (e) {
|
|
427
|
+
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
428
|
+
}
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
/** 群表情回应 */
|
|
432
|
+
onGroupEmojiLike(fn) {
|
|
433
|
+
this.napcat.on('notice.group_msg_emoji_like', async (event) => {
|
|
434
|
+
try {
|
|
435
|
+
new BotConsole('notice', event).log();
|
|
436
|
+
await fn(this.client, event);
|
|
437
|
+
}
|
|
438
|
+
catch (e) {
|
|
439
|
+
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
440
|
+
}
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
/** 群设精(添加/删除) */
|
|
444
|
+
onGroupEssence(fn) {
|
|
445
|
+
this.napcat.on('notice.essence', async (event) => {
|
|
446
|
+
try {
|
|
447
|
+
new BotConsole('notice', event).log();
|
|
448
|
+
await fn(this.client, event);
|
|
449
|
+
}
|
|
450
|
+
catch (e) {
|
|
451
|
+
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
452
|
+
}
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
/** 戳一戳(好友/群) */
|
|
456
|
+
onPoke(fn) {
|
|
457
|
+
this.napcat.on('notice.notify.poke', async (event) => {
|
|
458
|
+
try {
|
|
459
|
+
new BotConsole('notice', event).log();
|
|
460
|
+
await fn(this.client, event);
|
|
461
|
+
}
|
|
462
|
+
catch (e) {
|
|
463
|
+
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
464
|
+
}
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
/** 群名称变更 */
|
|
468
|
+
onGroupNameChange(fn) {
|
|
469
|
+
this.napcat.on('notice.notify.group_name', async (event) => {
|
|
470
|
+
try {
|
|
471
|
+
new BotConsole('notice', event).log();
|
|
472
|
+
await fn(this.client, event);
|
|
473
|
+
}
|
|
474
|
+
catch (e) {
|
|
475
|
+
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
476
|
+
}
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
/** 群头衔变更 */
|
|
480
|
+
onTitleChange(fn) {
|
|
481
|
+
this.napcat.on('notice.notify.title', async (event) => {
|
|
482
|
+
try {
|
|
483
|
+
new BotConsole('notice', event).log();
|
|
484
|
+
await fn(this.client, event);
|
|
485
|
+
}
|
|
486
|
+
catch (e) {
|
|
487
|
+
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
488
|
+
}
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
/** 个人资料点赞 */
|
|
492
|
+
onProfileLike(fn) {
|
|
493
|
+
this.napcat.on('notice.notify.profile_like', async (event) => {
|
|
494
|
+
try {
|
|
495
|
+
new BotConsole('notice', event).log();
|
|
496
|
+
await fn(this.client, event);
|
|
497
|
+
}
|
|
498
|
+
catch (e) {
|
|
499
|
+
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
500
|
+
}
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
/** bot 离线 */
|
|
504
|
+
onBotOffline(fn) {
|
|
505
|
+
this.napcat.on('notice.bot_offline', async (event) => {
|
|
506
|
+
try {
|
|
507
|
+
new BotConsole('notice', event).log();
|
|
508
|
+
await fn(this.client, event);
|
|
509
|
+
}
|
|
510
|
+
catch (e) {
|
|
511
|
+
new BotConsole('error', e instanceof Error ? e.message : JSON.stringify(e)).log();
|
|
512
|
+
}
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* 事件监听入口,按类别分组暴露监听器。
|
|
518
|
+
*
|
|
519
|
+
* @example
|
|
520
|
+
* ```ts
|
|
521
|
+
* bot.event.message.onGroupMessage(...);
|
|
522
|
+
* bot.event.messageSent.onGroupSent(...);
|
|
523
|
+
* bot.event.request.onFriend(...);
|
|
524
|
+
* ```
|
|
525
|
+
*/
|
|
526
|
+
export class BotEvent {
|
|
527
|
+
constructor(api, client) {
|
|
528
|
+
Object.defineProperty(this, "message", {
|
|
529
|
+
enumerable: true,
|
|
530
|
+
configurable: true,
|
|
531
|
+
writable: true,
|
|
532
|
+
value: void 0
|
|
533
|
+
});
|
|
534
|
+
Object.defineProperty(this, "messageSent", {
|
|
535
|
+
enumerable: true,
|
|
536
|
+
configurable: true,
|
|
537
|
+
writable: true,
|
|
538
|
+
value: void 0
|
|
539
|
+
});
|
|
540
|
+
Object.defineProperty(this, "request", {
|
|
541
|
+
enumerable: true,
|
|
542
|
+
configurable: true,
|
|
543
|
+
writable: true,
|
|
544
|
+
value: void 0
|
|
545
|
+
});
|
|
546
|
+
Object.defineProperty(this, "notice", {
|
|
547
|
+
enumerable: true,
|
|
548
|
+
configurable: true,
|
|
549
|
+
writable: true,
|
|
550
|
+
value: void 0
|
|
551
|
+
});
|
|
552
|
+
this.message = new MessageEvent(api.napcat, client);
|
|
553
|
+
this.messageSent = new MessageSent(api.napcat, client);
|
|
554
|
+
this.request = new RequestEvent(api.napcat, client);
|
|
555
|
+
this.notice = new NoticeEvent(api.napcat, client);
|
|
556
|
+
}
|
|
557
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { BotClient } from './botClient';
|
|
2
|
+
export { BotApi } from './botApi';
|
|
3
|
+
export { BotEvent, MessageEvent, MessageSent, RequestEvent, NoticeEvent } from './botEvent';
|
|
4
|
+
export { BotConsole, colors, parseCQ, formatMessage } from './botConsole';
|
|
5
|
+
export type { BotConsoleType, PrivateMessage, PrivateMessageSelf, RequestGroup, NoticeEvent as NoticeEventType } from './botConsole';
|
|
6
|
+
export { Message } from './message';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { BotClient } from './botClient';
|
|
2
|
+
export { BotApi } from './botApi';
|
|
3
|
+
export { BotEvent, MessageEvent, MessageSent, RequestEvent, NoticeEvent } from './botEvent';
|
|
4
|
+
export { BotConsole, colors, parseCQ, formatMessage } from './botConsole';
|
|
5
|
+
export { Message } from './message';
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 消息段,搭配 {@link BotApi.sendMessage} / {@link BotApi.sendGroupMessage} 等发送方法使用。
|
|
3
|
+
*
|
|
4
|
+
* ## 收发支持情况
|
|
5
|
+
* | 类型 | 发送 | 接收 | 说明 |
|
|
6
|
+
* |------|:----:|:----:|------|
|
|
7
|
+
* | `text` | ✅ | ✅ | 文本 |
|
|
8
|
+
* | `at` | ✅ | ✅ | @某人 / @全体 |
|
|
9
|
+
* | `reply` | ✅ | ✅ | 引用回复 |
|
|
10
|
+
* | `face` | ✅ | ✅ | QQ 表情 |
|
|
11
|
+
* | `image` | ✅ | ✅ | 图片 |
|
|
12
|
+
* | `file` | ✅ | ✅ | 文件 |
|
|
13
|
+
* | `video` | ✅ | ✅ | 短视频 |
|
|
14
|
+
* | `record` | ✅ | ✅ | 语音 |
|
|
15
|
+
* | `json` | ✅ | ✅ | JSON 消息段 |
|
|
16
|
+
* | `dice` | ✅ | ✅ | 骰子 |
|
|
17
|
+
* | `rps` | ✅ | ✅ | 猜拳 |
|
|
18
|
+
* | `markdown` | ✅ | ✅ | Markdown |
|
|
19
|
+
* | `forward` | ✅ | ✅ | 合并转发 |
|
|
20
|
+
* | `mface` | ✅ | — | 商城表情(收归入 `image`) |
|
|
21
|
+
* | `music` | ✅ | — | 音乐分享 |
|
|
22
|
+
* | `node` | ✅ | — | 合并转发节点 |
|
|
23
|
+
* | `contact` | ✅ | — | 推荐联系人/群 |
|
|
24
|
+
* | `poke` | — | ✅ | 戳一戳(仅接收) |
|
|
25
|
+
*/
|
|
26
|
+
export declare class Message {
|
|
27
|
+
type: string;
|
|
28
|
+
data: Record<string, any>;
|
|
29
|
+
private constructor();
|
|
30
|
+
/** 文本消息段(发+收) */
|
|
31
|
+
static text(text: string): Message;
|
|
32
|
+
/** @某人,传 QQ 号或 `'all'`(发+收) */
|
|
33
|
+
static at(qq: string | number): Message;
|
|
34
|
+
/** @全体成员(发) */
|
|
35
|
+
static atAll(): Message;
|
|
36
|
+
/** QQ 表情,传表情 ID(发+收) */
|
|
37
|
+
static face(id: string | number): Message;
|
|
38
|
+
/** 商城表情(仅发送,接收时归入 image 段) */
|
|
39
|
+
static mface(emoji_id: string | number, emoji_package_id: string | number, key: string, summary?: string): Message;
|
|
40
|
+
/** 图片,`file` 支持本地路径 / URL / Buffer(发+收) */
|
|
41
|
+
static image(file: string | Buffer, summary?: string, sub_type?: string | number): Message;
|
|
42
|
+
/** 引用回复,传消息 ID(发+收) */
|
|
43
|
+
static reply(id: string | number): Message;
|
|
44
|
+
/** 文件,`file` 支持本地路径 / URL / Buffer(发+收) */
|
|
45
|
+
static file(file: string | Buffer, name?: string): Message;
|
|
46
|
+
/** 短视频,`file` 支持本地路径 / URL / Buffer(发+收) */
|
|
47
|
+
static video(file: string | Buffer, name?: string, thumb?: string): Message;
|
|
48
|
+
/** 语音,`file` 支持本地路径 / URL / Buffer(发+收) */
|
|
49
|
+
static record(file: string | Buffer, name?: string, thumb?: string): Message;
|
|
50
|
+
/** JSON 消息段(发+收) */
|
|
51
|
+
static json(data: string): Message;
|
|
52
|
+
/** 骰子(发+收) */
|
|
53
|
+
static dice(): Message;
|
|
54
|
+
/** 猜拳(发+收) */
|
|
55
|
+
static rps(): Message;
|
|
56
|
+
/** Markdown 消息(发+收) */
|
|
57
|
+
static markdown(content: string): Message;
|
|
58
|
+
/** 平台音乐分享,type 支持 qq/163/kugou/migu/kuwo(仅发送) */
|
|
59
|
+
static music(type: 'qq' | '163' | 'kugou' | 'migu' | 'kuwo', id: string | number): Message;
|
|
60
|
+
/** 自定义音乐分享,需配置签名服务器(仅发送) */
|
|
61
|
+
static customMusic(type: 'qq' | '163' | 'kugou' | 'migu' | 'kuwo' | 'custom', url: string, image: string, audio?: string, title?: string, singer?: string): Message;
|
|
62
|
+
/** 合并转发节点(引用已有消息,仅发送) */
|
|
63
|
+
static node(id: string | number, user_id?: string | number, nickname?: string, source?: string, news?: {
|
|
64
|
+
text: string;
|
|
65
|
+
}[], summary?: string, prompt?: string, time?: string | number): Message;
|
|
66
|
+
/** 合并转发节点(自定义内容,仅发送) */
|
|
67
|
+
static customNode(content: Message[], user_id?: string | number, nickname?: string, source?: string, news?: {
|
|
68
|
+
text: string;
|
|
69
|
+
}[], summary?: string, prompt?: string, time?: string | number): Message;
|
|
70
|
+
/** 合并转发,传 message_id(发+收) */
|
|
71
|
+
static forward(message_id: number): Message;
|
|
72
|
+
/** 推荐联系人/群(仅发送) */
|
|
73
|
+
static contact(type: 'qq' | 'group', id: string | number): Message;
|
|
74
|
+
/**
|
|
75
|
+
* 从 napcat 事件中的 message 段构造 Message(收消息还原)
|
|
76
|
+
* 支持的接收类型:text/at/image/file/poke/dice/rps/face/reply/video/record/forward/json/markdown
|
|
77
|
+
* @param seg - `{ type: string, data: object }`
|
|
78
|
+
*/
|
|
79
|
+
static from(seg: {
|
|
80
|
+
type: string;
|
|
81
|
+
data: Record<string, any>;
|
|
82
|
+
}): Message;
|
|
83
|
+
/**
|
|
84
|
+
* 转为 napcat API 所需的 JSON 格式
|
|
85
|
+
* @returns `{ type, data }`
|
|
86
|
+
*/
|
|
87
|
+
toJson(): {
|
|
88
|
+
type: string;
|
|
89
|
+
data: Record<string, any>;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* 转为 CQ 码字符串
|
|
93
|
+
* @returns 例如 `[CQ:at,qq=123456]`
|
|
94
|
+
*/
|
|
95
|
+
toCQ(): string;
|
|
96
|
+
}
|