node-karin 0.6.12 → 0.6.14
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 +2 -1
- package/lib/adapter/input/index.js +9 -12
- package/lib/adapter/onebot/onebot11.d.ts +18 -13
- package/lib/adapter/onebot/onebot11.js +55 -30
- package/lib/core/karin.d.ts +4 -4
- package/lib/core/karin.js +0 -1
- package/lib/core/listener.js +1 -1
- package/lib/core/plugin.loader.js +17 -5
- package/lib/core/server.d.ts +1 -1
- package/lib/core/server.js +19 -4
- package/lib/event/event.handler.js +1 -1
- package/lib/event/message.handler.js +18 -18
- package/lib/event/request.d.ts +2 -2
- package/lib/event/request.js +0 -1
- package/lib/index.d.ts +5 -4
- package/lib/render/client.js +2 -2
- package/lib/types/adapter.d.ts +9 -7
- package/lib/types/element.d.ts +13 -27
- package/lib/types/onebots11.d.ts +39 -1
- package/lib/utils/common.d.ts +26 -3
- package/lib/utils/common.js +72 -18
- package/lib/utils/config.d.ts +17 -4
- package/lib/utils/config.js +41 -25
- package/lib/utils/segment.d.ts +17 -14
- package/lib/utils/segment.js +37 -17
- package/package.json +1 -2
|
@@ -12,7 +12,8 @@ export declare class AdapterInput implements KarinAdapter {
|
|
|
12
12
|
version: KarinAdapter['version'];
|
|
13
13
|
constructor();
|
|
14
14
|
get self_id(): string;
|
|
15
|
-
stdin():
|
|
15
|
+
stdin(): this;
|
|
16
|
+
init(): void;
|
|
16
17
|
logger(level: 'info' | 'error' | 'trace' | 'debug' | 'mark' | 'warn' | 'fatal', ...args: any[]): void;
|
|
17
18
|
GetVersion(): Promise<{
|
|
18
19
|
name: string;
|
|
@@ -2,20 +2,18 @@ import fs from 'fs';
|
|
|
2
2
|
import { randomUUID } from 'crypto';
|
|
3
3
|
import { listener } from '../../core/index.js';
|
|
4
4
|
import { KarinMessage } from '../../event/index.js';
|
|
5
|
-
import { config, common, YamlEditor } from '../../utils/index.js';
|
|
5
|
+
import { config, common, YamlEditor, logger } from '../../utils/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;
|
|
12
|
-
#stdin;
|
|
13
12
|
socket;
|
|
14
13
|
account;
|
|
15
14
|
adapter;
|
|
16
15
|
version;
|
|
17
16
|
constructor() {
|
|
18
|
-
this.#stdin = false;
|
|
19
17
|
this.token = oldToken;
|
|
20
18
|
this.account = { uid: 'input', uin: 'input', name: 'input' };
|
|
21
19
|
this.adapter = { id: 'shell', name: 'input', type: 'internal', sub_type: 'internal', start_time: Date.now(), connect: '', index: 0 };
|
|
@@ -25,9 +23,6 @@ export class AdapterInput {
|
|
|
25
23
|
return this.account.uid;
|
|
26
24
|
}
|
|
27
25
|
stdin() {
|
|
28
|
-
if (this.#stdin)
|
|
29
|
-
return;
|
|
30
|
-
this.#stdin = true;
|
|
31
26
|
if (oldToken === 'AdapterInput') {
|
|
32
27
|
try {
|
|
33
28
|
this.token = randomUUID();
|
|
@@ -57,8 +52,14 @@ export class AdapterInput {
|
|
|
57
52
|
const index = listener.addBot({ bot: this, type: this.adapter.type });
|
|
58
53
|
if (index)
|
|
59
54
|
this.adapter.index = index;
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
57
|
+
init() {
|
|
60
58
|
process.stdin.on('data', data => this.#input(data.toString()));
|
|
61
|
-
process.once('stdin.close', () =>
|
|
59
|
+
process.once('stdin.close', () => {
|
|
60
|
+
process.stdin.removeAllListeners('data');
|
|
61
|
+
process.stdin.once('stdin.open', () => this.init());
|
|
62
|
+
});
|
|
62
63
|
}
|
|
63
64
|
logger(level, ...args) {
|
|
64
65
|
logger.bot(level, this.account.uid || this.account.uin, ...args);
|
|
@@ -89,9 +90,6 @@ export class AdapterInput {
|
|
|
89
90
|
};
|
|
90
91
|
const e = new KarinMessage(message);
|
|
91
92
|
e.bot = this;
|
|
92
|
-
/**
|
|
93
|
-
* 快速回复 开发者不应该使用这个方法,应该使用由karin封装过后的reply方法
|
|
94
|
-
*/
|
|
95
93
|
e.replyCallback = async (elements) => {
|
|
96
94
|
this.SendMessage(e.contact, elements);
|
|
97
95
|
return { message_id: e.message_id };
|
|
@@ -111,7 +109,6 @@ export class AdapterInput {
|
|
|
111
109
|
const buffer = await common.buffer(file);
|
|
112
110
|
// 生成文件名 根据type生成不同的文件后缀
|
|
113
111
|
const name = `${Date.now()}.${type === 'image' ? 'jpg' : type === 'voice' ? 'mp3' : 'file'}`;
|
|
114
|
-
// 写入文件
|
|
115
112
|
fs.writeFileSync(`./temp/input/${name}`, buffer);
|
|
116
113
|
return `[${type === 'image' ? '图片' : '语音'}: http://${ip}:${config.Server.http.port}/api/input?name=${name}&token=${this.token} ]`;
|
|
117
114
|
}
|
|
@@ -187,4 +184,4 @@ export class AdapterInput {
|
|
|
187
184
|
async GetGroupHonor() { throw new Error('Method not implemented.'); }
|
|
188
185
|
}
|
|
189
186
|
if (enable)
|
|
190
|
-
new AdapterInput().stdin();
|
|
187
|
+
new AdapterInput().stdin().init();
|
|
@@ -153,17 +153,9 @@ export declare class AdapterOneBot11 implements KarinAdapter {
|
|
|
153
153
|
SetGroupWholeBan(group_id: string, is_ban?: boolean): Promise<void>;
|
|
154
154
|
/**
|
|
155
155
|
* 设置群管理员
|
|
156
|
-
* @param
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
* target_uin?:string,
|
|
160
|
-
* is_admin:boolean
|
|
161
|
-
* }} options - 设置管理员选项
|
|
162
|
-
* @param options.group_id - 群组ID
|
|
163
|
-
* @param options.target_uid - 要设置为管理员的用户uid
|
|
164
|
-
* @param options.target_uin - 要设置为管理员的用户uin
|
|
165
|
-
* @param options.is_admin - 是否设置为管理员
|
|
166
|
-
* @returns {Promise<SetGroupAdminResponse>} - 设置群管理员操作的响应
|
|
156
|
+
* @param group_id - 群号
|
|
157
|
+
* @param target_uid_or_uin - 目标用户ID
|
|
158
|
+
* @param is_admin - 是否设置为管理员
|
|
167
159
|
*/
|
|
168
160
|
SetGroupAdmin(group_id: string, target_uid_or_uin: string, is_admin: boolean): Promise<void>;
|
|
169
161
|
/**
|
|
@@ -278,13 +270,26 @@ export declare class AdapterOneBot11 implements KarinAdapter {
|
|
|
278
270
|
GetVersion(): Promise<any>;
|
|
279
271
|
DownloadForwardMessage(): Promise<void>;
|
|
280
272
|
GetEssenceMessageList(): Promise<void>;
|
|
273
|
+
/**
|
|
274
|
+
* 上传群文件
|
|
275
|
+
* @param group_id - 群号
|
|
276
|
+
* @param file - 本地文件绝对路径
|
|
277
|
+
* @param name - 文件名称 必须提供
|
|
278
|
+
* @param folder - 父目录ID 不提供则上传到根目录
|
|
279
|
+
*/
|
|
280
|
+
UploadPrivateFile(group_id: string, file: string, name: string, folder?: string): Promise<any>;
|
|
281
|
+
/**
|
|
282
|
+
* 上传私聊文件
|
|
283
|
+
* @param user_id - 用户ID
|
|
284
|
+
* @param file - 本地文件绝对路径
|
|
285
|
+
* @param name - 文件名称 必须提供
|
|
286
|
+
*/
|
|
287
|
+
UploadGroupFile(user_id: string, file: string, name: string): Promise<any>;
|
|
281
288
|
SetEssenceMessage(): Promise<void>;
|
|
282
289
|
DeleteEssenceMessage(): Promise<void>;
|
|
283
290
|
SetFriendApplyResult(): Promise<void>;
|
|
284
291
|
SetGroupApplyResult(): Promise<void>;
|
|
285
292
|
SetInvitedJoinGroupResult(): Promise<void>;
|
|
286
|
-
UploadPrivateFile(): Promise<void>;
|
|
287
|
-
UploadGroupFile(): Promise<void>;
|
|
288
293
|
sendForwardMessage(contact: contact, elements: KarinNodeElement[]): Promise<{
|
|
289
294
|
message_id: any;
|
|
290
295
|
}>;
|
|
@@ -213,7 +213,7 @@ export class AdapterOneBot11 {
|
|
|
213
213
|
uid: data.user_id + '',
|
|
214
214
|
uin: data.user_id + '',
|
|
215
215
|
nick: '',
|
|
216
|
-
role: '',
|
|
216
|
+
role: 'unknown',
|
|
217
217
|
};
|
|
218
218
|
const contact = {
|
|
219
219
|
scene: ('group_id' in data ? 'group' : 'friend'),
|
|
@@ -223,8 +223,9 @@ export class AdapterOneBot11 {
|
|
|
223
223
|
switch (data.notice_type) {
|
|
224
224
|
// 群文件上传
|
|
225
225
|
case 'group_upload': {
|
|
226
|
+
const group_id = data.group_id + '';
|
|
226
227
|
const content = {
|
|
227
|
-
group_id
|
|
228
|
+
group_id,
|
|
228
229
|
operator_uid: data.user_id + '',
|
|
229
230
|
operator_uin: data.user_id + '',
|
|
230
231
|
file_id: data.file.id,
|
|
@@ -242,6 +243,7 @@ export class AdapterOneBot11 {
|
|
|
242
243
|
content,
|
|
243
244
|
sender,
|
|
244
245
|
contact,
|
|
246
|
+
group_id,
|
|
245
247
|
sub_event: 'group_file_uploaded',
|
|
246
248
|
};
|
|
247
249
|
notice = new KarinNotice(options);
|
|
@@ -249,8 +251,9 @@ export class AdapterOneBot11 {
|
|
|
249
251
|
}
|
|
250
252
|
// 群管理员变动
|
|
251
253
|
case 'group_admin': {
|
|
254
|
+
const group_id = data.group_id + '';
|
|
252
255
|
const content = {
|
|
253
|
-
group_id
|
|
256
|
+
group_id,
|
|
254
257
|
target_uid: data.user_id + '',
|
|
255
258
|
target_uin: data.user_id + '',
|
|
256
259
|
is_admin: data.sub_type === 'set',
|
|
@@ -263,6 +266,7 @@ export class AdapterOneBot11 {
|
|
|
263
266
|
sender,
|
|
264
267
|
contact,
|
|
265
268
|
content,
|
|
269
|
+
group_id,
|
|
266
270
|
sub_event: 'group_admin_changed',
|
|
267
271
|
};
|
|
268
272
|
notice = new KarinNotice(options);
|
|
@@ -270,10 +274,11 @@ export class AdapterOneBot11 {
|
|
|
270
274
|
}
|
|
271
275
|
// 群成员减少
|
|
272
276
|
case 'group_decrease': {
|
|
277
|
+
const group_id = data.group_id + '';
|
|
273
278
|
const content = {
|
|
274
|
-
group_id
|
|
275
|
-
operator_uid: data.operator_id || '',
|
|
276
|
-
operator_uin: data.operator_id || '',
|
|
279
|
+
group_id,
|
|
280
|
+
operator_uid: (data.operator_id + '') || '',
|
|
281
|
+
operator_uin: (data.operator_id + '') || '',
|
|
277
282
|
target_uid: data.user_id || '',
|
|
278
283
|
target_uin: data.user_id || '',
|
|
279
284
|
type: data.sub_type,
|
|
@@ -286,6 +291,7 @@ export class AdapterOneBot11 {
|
|
|
286
291
|
sender,
|
|
287
292
|
contact,
|
|
288
293
|
content,
|
|
294
|
+
group_id,
|
|
289
295
|
sub_event: 'group_member_decrease',
|
|
290
296
|
};
|
|
291
297
|
notice = new KarinNotice(options);
|
|
@@ -293,8 +299,9 @@ export class AdapterOneBot11 {
|
|
|
293
299
|
}
|
|
294
300
|
// 群成员增加
|
|
295
301
|
case 'group_increase': {
|
|
302
|
+
const group_id = data.group_id + '';
|
|
296
303
|
const content = {
|
|
297
|
-
group_id
|
|
304
|
+
group_id,
|
|
298
305
|
operator_uid: (data.operator_id || '') + '',
|
|
299
306
|
operator_uin: (data.operator_id || '') + '',
|
|
300
307
|
target_uid: (data.user_id || '') + '',
|
|
@@ -309,6 +316,7 @@ export class AdapterOneBot11 {
|
|
|
309
316
|
sender,
|
|
310
317
|
contact,
|
|
311
318
|
content,
|
|
319
|
+
group_id,
|
|
312
320
|
sub_event: 'group_member_increase',
|
|
313
321
|
};
|
|
314
322
|
notice = new KarinNotice(options);
|
|
@@ -316,10 +324,11 @@ export class AdapterOneBot11 {
|
|
|
316
324
|
}
|
|
317
325
|
// 群禁言事件
|
|
318
326
|
case 'group_ban': {
|
|
327
|
+
const group_id = data.group_id + '';
|
|
319
328
|
const content = {
|
|
320
|
-
group_id
|
|
321
|
-
operator_uid: data.operator_id || '',
|
|
322
|
-
operator_uin: data.operator_id || '',
|
|
329
|
+
group_id,
|
|
330
|
+
operator_uid: (data.operator_id + '') || '',
|
|
331
|
+
operator_uin: (data.operator_id + '') || '',
|
|
323
332
|
target_uid: data.user_id || '',
|
|
324
333
|
target_uin: data.user_id || '',
|
|
325
334
|
duration: data.duration,
|
|
@@ -333,6 +342,7 @@ export class AdapterOneBot11 {
|
|
|
333
342
|
sender,
|
|
334
343
|
contact,
|
|
335
344
|
content,
|
|
345
|
+
group_id,
|
|
336
346
|
sub_event: 'group_member_ban',
|
|
337
347
|
};
|
|
338
348
|
notice = new KarinNotice(options);
|
|
@@ -343,10 +353,11 @@ export class AdapterOneBot11 {
|
|
|
343
353
|
this.logger('info', `[好友添加]:${JSON.stringify(data)}`);
|
|
344
354
|
break;
|
|
345
355
|
case 'group_recall': {
|
|
356
|
+
const group_id = data.group_id + '';
|
|
346
357
|
const content = {
|
|
347
|
-
group_id
|
|
348
|
-
operator_uid: data.operator_id || '',
|
|
349
|
-
operator_uin: data.operator_id || '',
|
|
358
|
+
group_id,
|
|
359
|
+
operator_uid: (data.operator_id + '') || '',
|
|
360
|
+
operator_uin: (data.operator_id + '') || '',
|
|
350
361
|
target_uid: data.user_id || '',
|
|
351
362
|
target_uin: data.user_id || '',
|
|
352
363
|
message_id: data.message_id,
|
|
@@ -360,6 +371,7 @@ export class AdapterOneBot11 {
|
|
|
360
371
|
sender,
|
|
361
372
|
contact,
|
|
362
373
|
content,
|
|
374
|
+
group_id,
|
|
363
375
|
sub_event: 'group_recall',
|
|
364
376
|
};
|
|
365
377
|
notice = new KarinNotice(options);
|
|
@@ -388,8 +400,9 @@ export class AdapterOneBot11 {
|
|
|
388
400
|
case 'notify':
|
|
389
401
|
switch (data.sub_type) {
|
|
390
402
|
case 'poke': {
|
|
403
|
+
const group_id = 'group_id' in data ? data.group_id + '' : '';
|
|
391
404
|
const content = {
|
|
392
|
-
group_id
|
|
405
|
+
group_id,
|
|
393
406
|
operator_uid: data.user_id + '',
|
|
394
407
|
operator_uin: data.user_id + '',
|
|
395
408
|
target_uid: data.target_id + '',
|
|
@@ -406,6 +419,7 @@ export class AdapterOneBot11 {
|
|
|
406
419
|
sender,
|
|
407
420
|
contact,
|
|
408
421
|
content,
|
|
422
|
+
group_id,
|
|
409
423
|
sub_event: data.group_id ? 'group_poke' : 'private_poke',
|
|
410
424
|
};
|
|
411
425
|
notice = new KarinNotice(options);
|
|
@@ -422,8 +436,9 @@ export class AdapterOneBot11 {
|
|
|
422
436
|
}
|
|
423
437
|
break;
|
|
424
438
|
case 'group_msg_emoji_like': {
|
|
439
|
+
const group_id = data.group_id + '';
|
|
425
440
|
const content = {
|
|
426
|
-
group_id
|
|
441
|
+
group_id,
|
|
427
442
|
message_id: data.message_id,
|
|
428
443
|
face_id: data.likes[0].emoji_id,
|
|
429
444
|
is_set: true,
|
|
@@ -436,6 +451,7 @@ export class AdapterOneBot11 {
|
|
|
436
451
|
sender,
|
|
437
452
|
contact,
|
|
438
453
|
content,
|
|
454
|
+
group_id,
|
|
439
455
|
sub_event: 'group_message_reaction',
|
|
440
456
|
};
|
|
441
457
|
notice = new KarinNotice(options);
|
|
@@ -465,7 +481,7 @@ export class AdapterOneBot11 {
|
|
|
465
481
|
uid: data.user_id + '',
|
|
466
482
|
uin: data.user_id + '',
|
|
467
483
|
nick: '',
|
|
468
|
-
role: '',
|
|
484
|
+
role: 'unknown',
|
|
469
485
|
},
|
|
470
486
|
sub_event: 'private_apply',
|
|
471
487
|
content: {
|
|
@@ -492,7 +508,7 @@ export class AdapterOneBot11 {
|
|
|
492
508
|
uid: data.user_id + '',
|
|
493
509
|
uin: data.user_id + '',
|
|
494
510
|
nick: '',
|
|
495
|
-
role: '',
|
|
511
|
+
role: 'unknown',
|
|
496
512
|
},
|
|
497
513
|
sub_event: data.sub_type === 'add' ? 'group_apply' : 'invited_group',
|
|
498
514
|
content: {
|
|
@@ -871,17 +887,9 @@ export class AdapterOneBot11 {
|
|
|
871
887
|
}
|
|
872
888
|
/**
|
|
873
889
|
* 设置群管理员
|
|
874
|
-
* @param
|
|
875
|
-
*
|
|
876
|
-
*
|
|
877
|
-
* target_uin?:string,
|
|
878
|
-
* is_admin:boolean
|
|
879
|
-
* }} options - 设置管理员选项
|
|
880
|
-
* @param options.group_id - 群组ID
|
|
881
|
-
* @param options.target_uid - 要设置为管理员的用户uid
|
|
882
|
-
* @param options.target_uin - 要设置为管理员的用户uin
|
|
883
|
-
* @param options.is_admin - 是否设置为管理员
|
|
884
|
-
* @returns {Promise<SetGroupAdminResponse>} - 设置群管理员操作的响应
|
|
890
|
+
* @param group_id - 群号
|
|
891
|
+
* @param target_uid_or_uin - 目标用户ID
|
|
892
|
+
* @param is_admin - 是否设置为管理员
|
|
885
893
|
*/
|
|
886
894
|
async SetGroupAdmin(group_id, target_uid_or_uin, is_admin) {
|
|
887
895
|
const user_id = Number(target_uid_or_uin);
|
|
@@ -1208,13 +1216,30 @@ export class AdapterOneBot11 {
|
|
|
1208
1216
|
async GetEssenceMessageList() {
|
|
1209
1217
|
throw new Error('Method not implemented.');
|
|
1210
1218
|
}
|
|
1219
|
+
/**
|
|
1220
|
+
* 上传群文件
|
|
1221
|
+
* @param group_id - 群号
|
|
1222
|
+
* @param file - 本地文件绝对路径
|
|
1223
|
+
* @param name - 文件名称 必须提供
|
|
1224
|
+
* @param folder - 父目录ID 不提供则上传到根目录
|
|
1225
|
+
*/
|
|
1226
|
+
async UploadPrivateFile(group_id, file, name, folder) {
|
|
1227
|
+
return await this.SendApi('upload_group_file', { group_id, file, name, folder });
|
|
1228
|
+
}
|
|
1229
|
+
/**
|
|
1230
|
+
* 上传私聊文件
|
|
1231
|
+
* @param user_id - 用户ID
|
|
1232
|
+
* @param file - 本地文件绝对路径
|
|
1233
|
+
* @param name - 文件名称 必须提供
|
|
1234
|
+
*/
|
|
1235
|
+
async UploadGroupFile(user_id, file, name) {
|
|
1236
|
+
return await this.SendApi('upload_private_file', { user_id, file, name });
|
|
1237
|
+
}
|
|
1211
1238
|
async SetEssenceMessage() { }
|
|
1212
1239
|
async DeleteEssenceMessage() { }
|
|
1213
1240
|
async SetFriendApplyResult() { }
|
|
1214
1241
|
async SetGroupApplyResult() { }
|
|
1215
1242
|
async SetInvitedJoinGroupResult() { }
|
|
1216
|
-
async UploadPrivateFile() { }
|
|
1217
|
-
async UploadGroupFile() { }
|
|
1218
1243
|
async sendForwardMessage(contact, elements) {
|
|
1219
1244
|
let message_id = await this.UploadForwardMessage(contact, elements);
|
|
1220
1245
|
if (this.version.name === 'Lagrange.OneBot') {
|
package/lib/core/karin.d.ts
CHANGED
|
@@ -51,10 +51,10 @@ export interface OptionsElement extends OptionsCommand {
|
|
|
51
51
|
}
|
|
52
52
|
export declare class Karin {
|
|
53
53
|
/**
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
* @param reg - 正则表达式
|
|
55
|
+
* @param fnc - 函数
|
|
56
|
+
* @param options - 选项
|
|
57
|
+
*/
|
|
58
58
|
command(reg: string | RegExp, fnc: FncFunction, options?: OptionsCommand): PluginApps;
|
|
59
59
|
/**
|
|
60
60
|
* @param reg - 正则表达式
|
package/lib/core/karin.js
CHANGED
package/lib/core/listener.js
CHANGED
|
@@ -163,7 +163,7 @@ class Listeners extends EventEmitter {
|
|
|
163
163
|
/** 标准化 */
|
|
164
164
|
const NewElements = common.makeMessage(elements)
|
|
165
165
|
/** 结果 */
|
|
166
|
-
let result = {
|
|
166
|
+
let result = {}
|
|
167
167
|
const reply_log = common.makeMessageLog(NewElements)
|
|
168
168
|
const self_id = bot.account.uid || bot.account.uin
|
|
169
169
|
if (contact.scene === 'group') {
|
|
@@ -123,14 +123,23 @@ class PluginLoader {
|
|
|
123
123
|
this.getApps(dir, this.isTs, true)
|
|
124
124
|
continue
|
|
125
125
|
}
|
|
126
|
-
/**
|
|
126
|
+
/** package */
|
|
127
|
+
const pack = common.readJson(`${PluginPath}/package.json`)
|
|
128
|
+
/** 旧版本入口文件 */
|
|
127
129
|
const index = this.getIndex(PluginPath, process.env.karin_app_lang)
|
|
128
130
|
if (index) {
|
|
129
131
|
this.FileList.push({ dir, name: index })
|
|
130
132
|
this.isDev && this.watchList.push({ dir, name: index })
|
|
131
133
|
}
|
|
134
|
+
/** 新版本入口 */
|
|
135
|
+
if (pack.main) {
|
|
136
|
+
const { dir: dirName, pop } = common.splitPath(pack.main)
|
|
137
|
+
const dirPath = `${dir}/${dirName}`
|
|
138
|
+
this.FileList.push({ dir: dirPath, name: pop })
|
|
139
|
+
this.isDev && this.watchList.push({ dir: dirPath, name: pop })
|
|
140
|
+
}
|
|
132
141
|
/** 检查是否存在karin.apps */
|
|
133
|
-
const
|
|
142
|
+
const outDir = (pack?.karin?.outDir || 'dist')
|
|
134
143
|
if (pack && pack?.karin?.apps) {
|
|
135
144
|
const cfg = pack.karin.apps
|
|
136
145
|
if (Array.isArray(cfg)) {
|
|
@@ -144,8 +153,8 @@ class PluginLoader {
|
|
|
144
153
|
/** ts环境 全部加载 如果存在编译产物 则不加载ts */
|
|
145
154
|
if (this.isTs) {
|
|
146
155
|
/** 编译产物 存在不加载ts */
|
|
147
|
-
if (common.exists(`${PluginPath}/
|
|
148
|
-
this.getApps((`${dir}/
|
|
156
|
+
if (common.exists(`${PluginPath}/${outDir}/apps`)) {
|
|
157
|
+
this.getApps((`${dir}/${outDir}/apps`), false)
|
|
149
158
|
continue
|
|
150
159
|
}
|
|
151
160
|
/** ts */
|
|
@@ -157,7 +166,7 @@ class PluginLoader {
|
|
|
157
166
|
/** js环境 */
|
|
158
167
|
if (common.isDir(`${PluginPath}/apps`)) { this.getApps(`${dir}/apps`, false) }
|
|
159
168
|
/** 这里需要判断下 不然ts环境下会重复加载 */
|
|
160
|
-
if (!this.isTs && common.isDir(`${PluginPath}/
|
|
169
|
+
if (!this.isTs && common.isDir(`${PluginPath}/${outDir}/apps`)) { this.getApps(`${dir}/${outDir}/apps`, false) }
|
|
161
170
|
}
|
|
162
171
|
}
|
|
163
172
|
|
|
@@ -247,6 +256,9 @@ class PluginLoader {
|
|
|
247
256
|
if (!App?.name) { return logger.error(`[${dir}][${name}] 插件名称错误`) }
|
|
248
257
|
App.file.dir = dir
|
|
249
258
|
App.file.name = name
|
|
259
|
+
App.rule.forEach((v, index) => {
|
|
260
|
+
App.rule[index].log = v.log === false ? (id, log) => logger.bot('debug', id, log) : (id, log) => logger.bot('mark', id, log)
|
|
261
|
+
})
|
|
250
262
|
/** handler */
|
|
251
263
|
App.task = this.addTaskFnc(dir, App)
|
|
252
264
|
this.PluginList[index] = App
|
package/lib/core/server.d.ts
CHANGED
package/lib/core/server.js
CHANGED
|
@@ -201,7 +201,7 @@ export const server = new (class Server {
|
|
|
201
201
|
/**
|
|
202
202
|
* 构建静态资源路径
|
|
203
203
|
*/
|
|
204
|
-
staticPath () {
|
|
204
|
+
async staticPath () {
|
|
205
205
|
this.list = []
|
|
206
206
|
/** 读取./resources文件夹 */
|
|
207
207
|
const resDir = './resources'
|
|
@@ -217,17 +217,32 @@ export const server = new (class Server {
|
|
|
217
217
|
const file = `${htmlDir}/${dir}`
|
|
218
218
|
if (common.isDir(file)) { this.list.push(file.replace('.', '')) }
|
|
219
219
|
}
|
|
220
|
-
/** 读取./plugins/
|
|
220
|
+
/** 读取./plugins/xxx/resources下所有文件夹 */
|
|
221
221
|
const pluginsDir = './plugins'
|
|
222
222
|
const plugins = fs.readdirSync(pluginsDir)
|
|
223
223
|
for (const dir of plugins) {
|
|
224
|
+
/** 忽略不是karin-plugin-开头 */
|
|
225
|
+
if (!dir.startsWith('karin-plugin-')) { continue }
|
|
224
226
|
const file = `${pluginsDir}/${dir}`
|
|
225
227
|
const resFile = `${file}/resources`
|
|
226
228
|
/** 包含resources文件夹 */
|
|
227
229
|
if (common.isDir(file) && common.isDir(resFile)) { this.list.push(resFile.replace('.', '')) }
|
|
228
|
-
const componentsFile = `${file}/components`
|
|
229
|
-
/** 包含components文件夹 兼容mys */
|
|
230
|
+
const componentsFile = `${file}/lib/components`
|
|
231
|
+
/** 包含lib/components文件夹 兼容mys */
|
|
230
232
|
if (common.isDir(file) && common.isDir(componentsFile)) { this.list.push(componentsFile.replace('.', '')) }
|
|
233
|
+
/** 读取package.json 查找是否存在自定义资源文件入口 */
|
|
234
|
+
const pkgFile = `${file}/package.json`
|
|
235
|
+
if (!common.exists(pkgFile)) { continue }
|
|
236
|
+
const pkg = common.readJson(pkgFile)
|
|
237
|
+
if (!pkg?.karin?.static || !Array.isArray(pkg.karin.static)) { continue }
|
|
238
|
+
/** 标准格式为 lib/test/xxxx */
|
|
239
|
+
for (let staticFile of pkg.karin.static) {
|
|
240
|
+
/** 不允许向上级目录 ../开头等 */
|
|
241
|
+
if (staticFile.startsWith('../')) { continue }
|
|
242
|
+
/** ./开头去掉./ */
|
|
243
|
+
if (staticFile.startsWith('./')) { staticFile = staticFile.slice(2) }
|
|
244
|
+
this.list.push(`${file}/${staticFile}`)
|
|
245
|
+
}
|
|
231
246
|
}
|
|
232
247
|
this.reg = new RegExp(`(${this.list.join('|')})`, 'g')
|
|
233
248
|
}
|
|
@@ -16,7 +16,7 @@ export default class EventHandler {
|
|
|
16
16
|
this.config = {}
|
|
17
17
|
this.GroupMsgPrint = false
|
|
18
18
|
/** 加入e.bot */
|
|
19
|
-
Object.defineProperty(this.e, 'bot', { value: listener.getBot(this.e.self_id) })
|
|
19
|
+
!this.e.bot && Object.defineProperty(this.e, 'bot', { value: listener.getBot(this.e.self_id) })
|
|
20
20
|
if (this.e.group_id) { this.config = config.group(this.e.group_id) }
|
|
21
21
|
}
|
|
22
22
|
|
|
@@ -25,7 +25,6 @@ export class MessageHandler extends EventHandler {
|
|
|
25
25
|
logger.debug('[消息拦截] 响应模式不匹配')
|
|
26
26
|
return
|
|
27
27
|
}
|
|
28
|
-
this.GroupMsgPrint = false
|
|
29
28
|
/** 处理回复 */
|
|
30
29
|
this.reply()
|
|
31
30
|
/** 处理消息 */
|
|
@@ -51,8 +50,9 @@ export class MessageHandler extends EventHandler {
|
|
|
51
50
|
if ('GroupCD' in this.config && !review.PluginEnable(app, this.config)) { continue }
|
|
52
51
|
/** 判断子事件 */
|
|
53
52
|
if (v.event && !this.filtEvent(v.event)) { continue }
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
const fncName = app.file.type === 'function' ? 'default' : v.fnc
|
|
54
|
+
this.e.logFnc = `[${app.file.dir}][${app.name}][${fncName}]`
|
|
55
|
+
const logFnc = logger.fnc(`[${app.name}][${fncName}]`)
|
|
56
56
|
this.GroupMsgPrint && typeof v.log === 'function' && v.log(this.e.self_id, `${logFnc}${this.e.logText} ${lodash.truncate(this.e.msg, { length: 80 })}`)
|
|
57
57
|
/** 判断权限 */
|
|
58
58
|
if (!this.filterPermission(v.permission)) { break a }
|
|
@@ -88,10 +88,7 @@ export class MessageHandler extends EventHandler {
|
|
|
88
88
|
for (const val of this.e.elements) {
|
|
89
89
|
switch (val.type) {
|
|
90
90
|
case 'text': {
|
|
91
|
-
const msg = (val.text || '')
|
|
92
|
-
.replace(/^\s*[#井#]+\s*/, '#')
|
|
93
|
-
.replace(/^\s*[\\*※*]+\s*/, '*')
|
|
94
|
-
.trim()
|
|
91
|
+
const msg = (val.text || '').replace(/^\s*[#井#]+\s*/, '#').replace(/^\s*[\\*※*]+\s*/, '*').trim()
|
|
95
92
|
this.e.msg += msg
|
|
96
93
|
/** 美观一点... */
|
|
97
94
|
logs.push(msg)
|
|
@@ -114,11 +111,9 @@ export class MessageHandler extends EventHandler {
|
|
|
114
111
|
break
|
|
115
112
|
case 'at':
|
|
116
113
|
/** atBot不计入e.at */
|
|
117
|
-
|
|
118
|
-
if (val.uid && val.uid == this.e.bot.account.uid) {
|
|
114
|
+
if (val.uid && val.uid === this.e.bot.account.uid) {
|
|
119
115
|
this.e.atBot = true
|
|
120
|
-
|
|
121
|
-
} else if (val.uin == this.e.bot.account.uin) {
|
|
116
|
+
} else if (val.uin === this.e.bot.account.uin) {
|
|
122
117
|
this.e.atBot = true
|
|
123
118
|
} else if (val.uid && val.uid === 'all') {
|
|
124
119
|
this.e.atAll = true
|
|
@@ -165,13 +160,15 @@ export class MessageHandler extends EventHandler {
|
|
|
165
160
|
logs.push(`[json:${JSON.stringify(val.data)}]`)
|
|
166
161
|
break
|
|
167
162
|
case 'markdown': {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}
|
|
163
|
+
logs.push(`[markdown:${val.content}]`)
|
|
164
|
+
break
|
|
165
|
+
}
|
|
166
|
+
case 'markdown_tpl': {
|
|
167
|
+
const params = val.params
|
|
168
|
+
if (!params) { break }
|
|
169
|
+
const content = { id: val.custom_template_id }
|
|
170
|
+
for (const v of params) { content[v.key] = v.values[0] }
|
|
171
|
+
logs.push(`[markdown_tpl:${JSON.stringify(content)}]`)
|
|
175
172
|
break
|
|
176
173
|
}
|
|
177
174
|
case 'rows': {
|
|
@@ -183,6 +180,9 @@ export class MessageHandler extends EventHandler {
|
|
|
183
180
|
case 'button':
|
|
184
181
|
logs.push(`[button:${JSON.stringify(val.data)}]`)
|
|
185
182
|
break
|
|
183
|
+
case 'long_msg':
|
|
184
|
+
logs.push(`[long_msg:${val.id}]`)
|
|
185
|
+
break
|
|
186
186
|
default:
|
|
187
187
|
logs.push(`[未知:${JSON.stringify(val)}]`)
|
|
188
188
|
}
|
package/lib/event/request.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { KarinEvent } from './event.js';
|
|
2
|
-
import { contact, Sender, EventToSubEvent, RequestType
|
|
2
|
+
import { contact, Sender, EventToSubEvent, RequestType } from '../types/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* - 请求事件基类
|
|
5
5
|
*/
|
|
@@ -45,5 +45,5 @@ export declare class KarinRequest extends KarinEvent {
|
|
|
45
45
|
/**
|
|
46
46
|
* - 事件对应的内容参数
|
|
47
47
|
*/
|
|
48
|
-
content:
|
|
48
|
+
content: RequestType[EventToSubEvent['request']];
|
|
49
49
|
}
|
package/lib/event/request.js
CHANGED
|
@@ -5,7 +5,6 @@ import { KarinEvent } from './event.js'
|
|
|
5
5
|
export class KarinRequest extends KarinEvent {
|
|
6
6
|
constructor ({ self_id, event_id, user_id, time, contact, sender, sub_event, content, group_id = '' }) {
|
|
7
7
|
super({ event: 'request', event_id, self_id, user_id, group_id, time, contact, sender, sub_event })
|
|
8
|
-
// ...
|
|
9
8
|
this.content = content
|
|
10
9
|
}
|
|
11
10
|
|
package/lib/index.d.ts
CHANGED
|
@@ -28,9 +28,10 @@ export declare const Renderer: {
|
|
|
28
28
|
renderHtml(data: string): Promise<string | string[]>;
|
|
29
29
|
};
|
|
30
30
|
export declare const Cfg: {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
projPath: string;
|
|
32
|
+
projConfigPath: string;
|
|
33
|
+
pkgPath: string;
|
|
34
|
+
pkgConfigPath: string;
|
|
34
35
|
change: Map<string, any>;
|
|
35
36
|
watcher: Map<string, any>;
|
|
36
37
|
review: boolean;
|
|
@@ -38,7 +39,7 @@ export declare const Cfg: {
|
|
|
38
39
|
initCfg(): Promise<void>;
|
|
39
40
|
getPlugins(): string[];
|
|
40
41
|
mkdir(dirname: string): boolean;
|
|
41
|
-
dirPath(
|
|
42
|
+
dirPath(_path: string, plugins: string[]): Promise<void>;
|
|
42
43
|
timeout(type?: "ws" | "grpc"): number;
|
|
43
44
|
readonly redis: import("./types/index.js").Redis;
|
|
44
45
|
readonly master: string[];
|