node-karin 0.12.14 → 0.12.16
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/lib/adapter/input/index.d.ts +1 -1
- package/lib/adapter/input/index.js +1 -1
- package/lib/adapter/onebot/11/event.js +90 -84
- package/lib/adapter/onebot/11/index.d.ts +89 -127
- package/lib/adapter/onebot/11/index.js +192 -254
- package/lib/cli/index.js +2 -2
- package/lib/core/init/config.js +1 -1
- package/lib/core/karin/karin.d.ts +21 -30
- package/lib/core/karin/karin.js +7 -9
- package/lib/core/listener/listener.js +11 -11
- package/lib/core/plugin/base.d.ts +7 -21
- package/lib/core/plugin/base.js +2 -6
- package/lib/core/plugin/loader.d.ts +5 -15
- package/lib/core/plugin/loader.js +5 -15
- package/lib/core/server/server.js +4 -4
- package/lib/event/handler/base.d.ts +1 -3
- package/lib/event/handler/base.js +1 -3
- package/lib/event/handler/message.js +9 -3
- package/lib/event/handler/notice.js +38 -32
- package/lib/event/handler/request.js +6 -6
- package/lib/index.d.ts +5 -0
- package/lib/index.js +5 -0
- package/lib/modules.d.ts +2 -2
- package/lib/modules.js +3 -2
- package/lib/types/adapter/accept.d.ts +24 -0
- package/lib/types/adapter/accept.js +1 -0
- package/lib/types/adapter/api.d.ts +88 -264
- package/lib/types/adapter/base.d.ts +3 -3
- package/lib/types/config/config.d.ts +4 -12
- package/lib/types/element/element.d.ts +119 -349
- package/lib/types/element/qqbot.d.ts +4 -12
- package/lib/types/event/contact.d.ts +6 -12
- package/lib/types/event/event.d.ts +59 -163
- package/lib/types/event/message.d.ts +11 -31
- package/lib/types/event/message.js +10 -12
- package/lib/types/event/notice.d.ts +118 -325
- package/lib/types/event/notice.js +8 -10
- package/lib/types/event/request.d.ts +29 -66
- package/lib/types/event/request.js +8 -10
- package/lib/types/event/sender.d.ts +7 -21
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.js +1 -0
- package/lib/types/onebot11/api.d.ts +49 -49
- package/lib/types/onebot11/event.d.ts +131 -347
- package/lib/types/onebot11/params.d.ts +184 -456
- package/lib/types/onebot11/response.d.ts +159 -381
- package/lib/types/onebot11/segment.d.ts +25 -75
- package/lib/types/onebot11/sender.d.ts +13 -39
- package/lib/types/plugin/app.d.ts +2 -6
- package/lib/types/plugin/plugin.d.ts +55 -165
- package/lib/types/render/render.d.ts +16 -48
- package/lib/utils/common/common.js +4 -2
- package/lib/utils/config/config.js +1 -1
- package/lib/utils/core/logger.js +3 -3
- package/lib/utils/core/segment.d.ts +28 -59
- package/lib/utils/core/segment.js +26 -30
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +1 -0
- package/lib/utils/tools/restart.d.ts +3 -3
- package/lib/utils/tools/restart.js +5 -5
- package/lib/utils/tools/yaml.d.ts +15 -0
- package/lib/utils/tools/yaml.js +43 -0
- package/package.json +1 -1
|
@@ -5,7 +5,7 @@ import { config, common, YamlEditor, logger } from '../../utils/index.js';
|
|
|
5
5
|
import { KarinMessage } from '../../types/index.js';
|
|
6
6
|
const { enable, msgToFile, token: oldToken, ip } = config.Config.AdapterInput;
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* 标准输入输出适配器
|
|
9
9
|
*/
|
|
10
10
|
export class AdapterInput {
|
|
11
11
|
token;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { karin } from '../../../core/index.js';
|
|
2
2
|
import { KarinMessage, KarinNotice, KarinRequest } from '../../../types/index.js';
|
|
3
3
|
export class OB11Event {
|
|
4
4
|
adapter;
|
|
@@ -41,8 +41,8 @@ export class OB11Event {
|
|
|
41
41
|
disable: 'OneBot停用',
|
|
42
42
|
connect: 'WebSocket连接成功',
|
|
43
43
|
};
|
|
44
|
-
const
|
|
45
|
-
this.adapter.logger('debug', `[生命周期]:${typeMap[
|
|
44
|
+
const subType = data.sub_type;
|
|
45
|
+
this.adapter.logger('debug', `[生命周期]:${typeMap[subType]}`);
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
/**
|
|
@@ -77,25 +77,22 @@ export class OB11Event {
|
|
|
77
77
|
};
|
|
78
78
|
const e = new KarinMessage(message);
|
|
79
79
|
e.bot = this.adapter;
|
|
80
|
-
/**
|
|
81
|
-
* 快速回复 开发者不应该使用这个方法,应该使用由karin封装过后的reply方法
|
|
82
|
-
*/
|
|
83
80
|
e.replyCallback = async (elements) => await this.adapter.SendMessage(e.contact, elements);
|
|
84
|
-
|
|
81
|
+
karin.emit('adapter.message', e);
|
|
85
82
|
}
|
|
86
83
|
/**
|
|
87
84
|
* 通知事件
|
|
88
85
|
*/
|
|
89
86
|
noticeEvent(data) {
|
|
90
87
|
const time = data.time;
|
|
91
|
-
const
|
|
88
|
+
const selfId = data.self_id + '';
|
|
92
89
|
let notice = {};
|
|
93
90
|
/** 别问为啥any... 我是any糕手~ */
|
|
94
|
-
const
|
|
95
|
-
const
|
|
91
|
+
const userId = (data.user_id || data.operator_id) + '';
|
|
92
|
+
const eventId = `notice.${time}`;
|
|
96
93
|
const sender = {
|
|
97
|
-
uid:
|
|
98
|
-
uin:
|
|
94
|
+
uid: userId,
|
|
95
|
+
uin: userId,
|
|
99
96
|
nick: '',
|
|
100
97
|
role: "unknown" /* Role.Unknown */,
|
|
101
98
|
};
|
|
@@ -107,9 +104,9 @@ export class OB11Event {
|
|
|
107
104
|
switch (data.notice_type) {
|
|
108
105
|
// 群文件上传
|
|
109
106
|
case 'group_upload': {
|
|
110
|
-
const
|
|
107
|
+
const groupId = data.group_id + '';
|
|
111
108
|
const content = {
|
|
112
|
-
group_id,
|
|
109
|
+
group_id: groupId,
|
|
113
110
|
operator_uid: data.user_id + '',
|
|
114
111
|
operator_uin: data.user_id + '',
|
|
115
112
|
file_id: data.file.id,
|
|
@@ -122,13 +119,13 @@ export class OB11Event {
|
|
|
122
119
|
const options = {
|
|
123
120
|
raw_event: data,
|
|
124
121
|
time,
|
|
125
|
-
self_id,
|
|
126
|
-
user_id,
|
|
127
|
-
event_id,
|
|
122
|
+
self_id: selfId,
|
|
123
|
+
user_id: userId,
|
|
124
|
+
event_id: eventId,
|
|
128
125
|
content,
|
|
129
126
|
sender,
|
|
130
127
|
contact,
|
|
131
|
-
group_id,
|
|
128
|
+
group_id: groupId,
|
|
132
129
|
sub_event: "group_file_uploaded" /* NoticeSubType.GroupFileUploaded */,
|
|
133
130
|
};
|
|
134
131
|
notice = new KarinNotice(options);
|
|
@@ -136,9 +133,9 @@ export class OB11Event {
|
|
|
136
133
|
}
|
|
137
134
|
// 群管理员变动
|
|
138
135
|
case 'group_admin': {
|
|
139
|
-
const
|
|
136
|
+
const groupId = data.group_id + '';
|
|
140
137
|
const content = {
|
|
141
|
-
group_id,
|
|
138
|
+
group_id: groupId,
|
|
142
139
|
target_uid: data.user_id + '',
|
|
143
140
|
target_uin: data.user_id + '',
|
|
144
141
|
is_admin: data.sub_type === 'set',
|
|
@@ -146,13 +143,13 @@ export class OB11Event {
|
|
|
146
143
|
const options = {
|
|
147
144
|
raw_event: data,
|
|
148
145
|
time,
|
|
149
|
-
self_id,
|
|
150
|
-
user_id,
|
|
151
|
-
event_id,
|
|
146
|
+
self_id: selfId,
|
|
147
|
+
user_id: userId,
|
|
148
|
+
event_id: eventId,
|
|
152
149
|
sender,
|
|
153
150
|
contact,
|
|
154
151
|
content,
|
|
155
|
-
group_id,
|
|
152
|
+
group_id: groupId,
|
|
156
153
|
sub_event: "group_admin_changed" /* NoticeSubType.GroupAdminChanged */,
|
|
157
154
|
};
|
|
158
155
|
notice = new KarinNotice(options);
|
|
@@ -160,9 +157,9 @@ export class OB11Event {
|
|
|
160
157
|
}
|
|
161
158
|
// 群成员减少
|
|
162
159
|
case 'group_decrease': {
|
|
163
|
-
const
|
|
160
|
+
const groupId = data.group_id + '';
|
|
164
161
|
const content = {
|
|
165
|
-
group_id,
|
|
162
|
+
group_id: groupId,
|
|
166
163
|
operator_uid: (data.operator_id + '') || '',
|
|
167
164
|
operator_uin: (data.operator_id + '') || '',
|
|
168
165
|
target_uid: data.user_id || '',
|
|
@@ -172,13 +169,13 @@ export class OB11Event {
|
|
|
172
169
|
const options = {
|
|
173
170
|
raw_event: data,
|
|
174
171
|
time,
|
|
175
|
-
self_id,
|
|
176
|
-
user_id,
|
|
177
|
-
event_id,
|
|
172
|
+
self_id: selfId,
|
|
173
|
+
user_id: userId,
|
|
174
|
+
event_id: eventId,
|
|
178
175
|
sender,
|
|
179
176
|
contact,
|
|
180
177
|
content,
|
|
181
|
-
group_id,
|
|
178
|
+
group_id: groupId,
|
|
182
179
|
sub_event: "group_member_decrease" /* NoticeSubType.GroupMemberDecrease */,
|
|
183
180
|
};
|
|
184
181
|
notice = new KarinNotice(options);
|
|
@@ -186,9 +183,9 @@ export class OB11Event {
|
|
|
186
183
|
}
|
|
187
184
|
// 群成员增加
|
|
188
185
|
case 'group_increase': {
|
|
189
|
-
const
|
|
186
|
+
const groupId = data.group_id + '';
|
|
190
187
|
const content = {
|
|
191
|
-
group_id,
|
|
188
|
+
group_id: groupId,
|
|
192
189
|
operator_uid: (data.operator_id || '') + '',
|
|
193
190
|
operator_uin: (data.operator_id || '') + '',
|
|
194
191
|
target_uid: (data.user_id || '') + '',
|
|
@@ -198,13 +195,13 @@ export class OB11Event {
|
|
|
198
195
|
const options = {
|
|
199
196
|
raw_event: data,
|
|
200
197
|
time,
|
|
201
|
-
self_id,
|
|
202
|
-
user_id,
|
|
203
|
-
event_id,
|
|
198
|
+
self_id: selfId,
|
|
199
|
+
user_id: userId,
|
|
200
|
+
event_id: eventId,
|
|
204
201
|
sender,
|
|
205
202
|
contact,
|
|
206
203
|
content,
|
|
207
|
-
group_id,
|
|
204
|
+
group_id: groupId,
|
|
208
205
|
sub_event: "group_member_increase" /* NoticeSubType.GroupMemberIncrease */,
|
|
209
206
|
};
|
|
210
207
|
notice = new KarinNotice(options);
|
|
@@ -212,9 +209,9 @@ export class OB11Event {
|
|
|
212
209
|
}
|
|
213
210
|
// 群禁言事件
|
|
214
211
|
case 'group_ban': {
|
|
215
|
-
const
|
|
212
|
+
const groupId = data.group_id + '';
|
|
216
213
|
const content = {
|
|
217
|
-
group_id,
|
|
214
|
+
group_id: groupId,
|
|
218
215
|
operator_uid: (data.operator_id + '') || '',
|
|
219
216
|
operator_uin: (data.operator_id + '') || '',
|
|
220
217
|
target_uid: data.user_id || '',
|
|
@@ -225,26 +222,42 @@ export class OB11Event {
|
|
|
225
222
|
const options = {
|
|
226
223
|
raw_event: data,
|
|
227
224
|
time,
|
|
228
|
-
self_id,
|
|
229
|
-
user_id,
|
|
230
|
-
event_id,
|
|
225
|
+
self_id: selfId,
|
|
226
|
+
user_id: userId,
|
|
227
|
+
event_id: eventId,
|
|
231
228
|
sender,
|
|
232
229
|
contact,
|
|
233
230
|
content,
|
|
234
|
-
group_id,
|
|
231
|
+
group_id: groupId,
|
|
235
232
|
sub_event: "group_member_ban" /* NoticeSubType.GroupMemberBan */,
|
|
236
233
|
};
|
|
237
234
|
notice = new KarinNotice(options);
|
|
238
235
|
break;
|
|
239
236
|
}
|
|
240
|
-
case 'friend_add':
|
|
241
|
-
|
|
242
|
-
|
|
237
|
+
case 'friend_add': {
|
|
238
|
+
const content = {
|
|
239
|
+
target_uid: userId,
|
|
240
|
+
target_uin: userId,
|
|
241
|
+
};
|
|
242
|
+
const options = {
|
|
243
|
+
raw_event: data,
|
|
244
|
+
time,
|
|
245
|
+
self_id: selfId,
|
|
246
|
+
user_id: userId,
|
|
247
|
+
event_id: eventId,
|
|
248
|
+
sender,
|
|
249
|
+
contact,
|
|
250
|
+
content,
|
|
251
|
+
group_id: '',
|
|
252
|
+
sub_event: "friend_increase" /* NoticeSubType.FriendIncrease */,
|
|
253
|
+
};
|
|
254
|
+
notice = new KarinNotice(options);
|
|
243
255
|
break;
|
|
256
|
+
}
|
|
244
257
|
case 'group_recall': {
|
|
245
|
-
const
|
|
258
|
+
const groupId = data.group_id + '';
|
|
246
259
|
const content = {
|
|
247
|
-
group_id,
|
|
260
|
+
group_id: groupId,
|
|
248
261
|
operator_uid: (data.operator_id + '') || '',
|
|
249
262
|
operator_uin: (data.operator_id + '') || '',
|
|
250
263
|
target_uid: data.user_id || '',
|
|
@@ -255,13 +268,13 @@ export class OB11Event {
|
|
|
255
268
|
const options = {
|
|
256
269
|
raw_event: data,
|
|
257
270
|
time,
|
|
258
|
-
self_id,
|
|
259
|
-
user_id,
|
|
260
|
-
event_id,
|
|
271
|
+
self_id: selfId,
|
|
272
|
+
user_id: userId,
|
|
273
|
+
event_id: eventId,
|
|
261
274
|
sender,
|
|
262
275
|
contact,
|
|
263
276
|
content,
|
|
264
|
-
group_id,
|
|
277
|
+
group_id: groupId,
|
|
265
278
|
sub_event: "group_recall" /* NoticeSubType.GroupRecall */,
|
|
266
279
|
};
|
|
267
280
|
notice = new KarinNotice(options);
|
|
@@ -277,9 +290,9 @@ export class OB11Event {
|
|
|
277
290
|
const options = {
|
|
278
291
|
raw_event: data,
|
|
279
292
|
time,
|
|
280
|
-
self_id,
|
|
281
|
-
user_id,
|
|
282
|
-
event_id,
|
|
293
|
+
self_id: selfId,
|
|
294
|
+
user_id: userId,
|
|
295
|
+
event_id: eventId,
|
|
283
296
|
sender,
|
|
284
297
|
contact,
|
|
285
298
|
content,
|
|
@@ -291,9 +304,9 @@ export class OB11Event {
|
|
|
291
304
|
case 'notify':
|
|
292
305
|
switch (data.sub_type) {
|
|
293
306
|
case 'poke': {
|
|
294
|
-
const
|
|
307
|
+
const groupId = 'group_id' in data ? data.group_id + '' : '';
|
|
295
308
|
const content = {
|
|
296
|
-
group_id,
|
|
309
|
+
group_id: groupId,
|
|
297
310
|
operator_uid: data.user_id + '',
|
|
298
311
|
operator_uin: data.user_id + '',
|
|
299
312
|
target_uid: data.target_id + '',
|
|
@@ -305,13 +318,13 @@ export class OB11Event {
|
|
|
305
318
|
const options = {
|
|
306
319
|
raw_event: data,
|
|
307
320
|
time,
|
|
308
|
-
self_id,
|
|
309
|
-
user_id,
|
|
310
|
-
event_id,
|
|
321
|
+
self_id: selfId,
|
|
322
|
+
user_id: userId,
|
|
323
|
+
event_id: eventId,
|
|
311
324
|
sender,
|
|
312
325
|
contact,
|
|
313
326
|
content,
|
|
314
|
-
group_id,
|
|
327
|
+
group_id: groupId,
|
|
315
328
|
sub_event: data.group_id ? "group_poke" /* NoticeSubType.GroupPoke */ : "private_poke" /* NoticeSubType.PrivatePoke */,
|
|
316
329
|
};
|
|
317
330
|
notice = new KarinNotice(options);
|
|
@@ -330,9 +343,9 @@ export class OB11Event {
|
|
|
330
343
|
}
|
|
331
344
|
break;
|
|
332
345
|
case 'group_msg_emoji_like': {
|
|
333
|
-
const
|
|
346
|
+
const groupId = data.group_id + '';
|
|
334
347
|
const content = {
|
|
335
|
-
group_id,
|
|
348
|
+
group_id: groupId,
|
|
336
349
|
message_id: data.message_id,
|
|
337
350
|
face_id: data.likes[0].emoji_id,
|
|
338
351
|
is_set: true,
|
|
@@ -340,13 +353,13 @@ export class OB11Event {
|
|
|
340
353
|
const options = {
|
|
341
354
|
raw_event: data,
|
|
342
355
|
time,
|
|
343
|
-
self_id,
|
|
344
|
-
user_id,
|
|
345
|
-
event_id,
|
|
356
|
+
self_id: selfId,
|
|
357
|
+
user_id: userId,
|
|
358
|
+
event_id: eventId,
|
|
346
359
|
sender,
|
|
347
360
|
contact,
|
|
348
361
|
content,
|
|
349
|
-
group_id,
|
|
362
|
+
group_id: groupId,
|
|
350
363
|
sub_event: "group_message_reaction" /* NoticeSubType.GroupMessageReaction */,
|
|
351
364
|
};
|
|
352
365
|
notice = new KarinNotice(options);
|
|
@@ -354,9 +367,9 @@ export class OB11Event {
|
|
|
354
367
|
}
|
|
355
368
|
// Language表情动态上报
|
|
356
369
|
case 'reaction': {
|
|
357
|
-
const
|
|
370
|
+
const groupId = data.group_id + '';
|
|
358
371
|
const content = {
|
|
359
|
-
group_id,
|
|
372
|
+
group_id: groupId,
|
|
360
373
|
message_id: data.message_id,
|
|
361
374
|
face_id: Number(data.code),
|
|
362
375
|
is_set: data.sub_type === 'add',
|
|
@@ -364,13 +377,13 @@ export class OB11Event {
|
|
|
364
377
|
const options = {
|
|
365
378
|
raw_event: data,
|
|
366
379
|
time,
|
|
367
|
-
self_id,
|
|
368
|
-
user_id,
|
|
369
|
-
event_id,
|
|
380
|
+
self_id: selfId,
|
|
381
|
+
user_id: userId,
|
|
382
|
+
event_id: eventId,
|
|
370
383
|
sender,
|
|
371
384
|
contact,
|
|
372
385
|
content,
|
|
373
|
-
group_id,
|
|
386
|
+
group_id: groupId,
|
|
374
387
|
sub_event: "group_message_reaction" /* NoticeSubType.GroupMessageReaction */,
|
|
375
388
|
};
|
|
376
389
|
notice = new KarinNotice(options);
|
|
@@ -381,11 +394,8 @@ export class OB11Event {
|
|
|
381
394
|
}
|
|
382
395
|
}
|
|
383
396
|
notice.bot = this.adapter;
|
|
384
|
-
/**
|
|
385
|
-
* 快速回复 开发者不应该使用这个方法,应该使用由karin封装过后的reply方法
|
|
386
|
-
*/
|
|
387
397
|
notice.replyCallback = async (elements) => await this.adapter.SendMessage(notice.contact, elements);
|
|
388
|
-
|
|
398
|
+
karin.emit('adapter.notice', notice);
|
|
389
399
|
}
|
|
390
400
|
/** 请求事件 */
|
|
391
401
|
requestEvent(data) {
|
|
@@ -413,14 +423,12 @@ export class OB11Event {
|
|
|
413
423
|
applier_uid: data.user_id + '',
|
|
414
424
|
applier_uin: data.user_id + '',
|
|
415
425
|
message: data.comment,
|
|
426
|
+
flag: data.flag,
|
|
416
427
|
},
|
|
417
428
|
});
|
|
418
429
|
request.bot = this.adapter;
|
|
419
|
-
/**
|
|
420
|
-
* 快速回复 开发者不应该使用这个方法,应该使用由karin封装过后的reply方法
|
|
421
|
-
*/
|
|
422
430
|
request.replyCallback = async (elements) => await this.adapter.SendMessage(request.contact, elements);
|
|
423
|
-
|
|
431
|
+
karin.emit('adapter.request', request);
|
|
424
432
|
return;
|
|
425
433
|
}
|
|
426
434
|
case 'group': {
|
|
@@ -449,14 +457,12 @@ export class OB11Event {
|
|
|
449
457
|
inviter_uid: data.user_id + '',
|
|
450
458
|
inviter_uin: data.user_id + '',
|
|
451
459
|
message: data.comment,
|
|
460
|
+
flag: data.flag,
|
|
452
461
|
},
|
|
453
462
|
});
|
|
454
463
|
request.bot = this.adapter;
|
|
455
|
-
/**
|
|
456
|
-
* 快速回复 开发者不应该使用这个方法,应该使用由karin封装过后的reply方法
|
|
457
|
-
*/
|
|
458
464
|
request.replyCallback = async (elements) => await this.adapter.SendMessage(request.contact, elements);
|
|
459
|
-
|
|
465
|
+
karin.emit('adapter.request', request);
|
|
460
466
|
return;
|
|
461
467
|
}
|
|
462
468
|
default: {
|