node-karin 0.11.0 → 0.11.2
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.
|
@@ -208,19 +208,19 @@ class PluginLoader {
|
|
|
208
208
|
* @param isNpm - 是否为npm插件
|
|
209
209
|
*/
|
|
210
210
|
async loadMain(root, main, isNpm) {
|
|
211
|
-
const _path =
|
|
212
|
-
if (!common.exists(_path)) {
|
|
211
|
+
const _path = path.resolve(root, main || '');
|
|
212
|
+
if (!common.exists(_path) || !main) {
|
|
213
213
|
if (isNpm)
|
|
214
214
|
return false;
|
|
215
|
-
const defRoot =
|
|
215
|
+
const defRoot = path.resolve(root, 'index.js');
|
|
216
216
|
if (common.exists(defRoot)) {
|
|
217
|
-
await import(defRoot);
|
|
217
|
+
await import(`file://${defRoot}`);
|
|
218
218
|
return true;
|
|
219
219
|
}
|
|
220
220
|
logger.debug(`[插件收集][${main}] 入口文件不存在,已忽略`);
|
|
221
221
|
return false;
|
|
222
222
|
}
|
|
223
|
-
await import(_path);
|
|
223
|
+
await import(`file://${_path}`);
|
|
224
224
|
return true;
|
|
225
225
|
}
|
|
226
226
|
/**
|
|
@@ -337,7 +337,7 @@ class PluginLoader {
|
|
|
337
337
|
logger.debug(`载入插件 [${plugin}]${_path ? `${common.getRelPath(_path)}` : ''}[${file}][${Class.name}]`);
|
|
338
338
|
if (Class.rule.length) {
|
|
339
339
|
for (const val of Class.rule) {
|
|
340
|
-
|
|
340
|
+
const fnc = async () => {
|
|
341
341
|
const log = val.log === false
|
|
342
342
|
? (id, log) => logger.debug('mark', id, log)
|
|
343
343
|
: (id, log) => logger.bot('mark', id, log);
|
|
@@ -354,12 +354,13 @@ class PluginLoader {
|
|
|
354
354
|
rank: val.priority || Class.priority || 10000,
|
|
355
355
|
reg: val.reg instanceof RegExp ? val.reg : new RegExp(val.reg),
|
|
356
356
|
}, Fn);
|
|
357
|
-
}
|
|
357
|
+
};
|
|
358
|
+
list.push(fnc());
|
|
358
359
|
}
|
|
359
360
|
}
|
|
360
361
|
if (Class.task.length) {
|
|
361
362
|
for (const val of Class.task) {
|
|
362
|
-
|
|
363
|
+
const fnc = async () => {
|
|
363
364
|
if (!val.name)
|
|
364
365
|
throw TypeError(`[${plugin}][${file}] 定时任务name错误`);
|
|
365
366
|
if (!val.cron)
|
|
@@ -373,13 +374,12 @@ class PluginLoader {
|
|
|
373
374
|
log,
|
|
374
375
|
cron: val.cron,
|
|
375
376
|
}, Fn);
|
|
376
|
-
}
|
|
377
|
+
};
|
|
378
|
+
list.push(fnc());
|
|
377
379
|
}
|
|
378
380
|
}
|
|
379
381
|
/** init */
|
|
380
|
-
list.push(
|
|
381
|
-
'init' in Class && typeof Class.init === 'function' && await Class.init();
|
|
382
|
-
});
|
|
382
|
+
list.push('init' in Class && typeof Class.init === 'function' ? Class.init() : Promise.resolve());
|
|
383
383
|
return true;
|
|
384
384
|
});
|
|
385
385
|
await Promise.all(list);
|
|
@@ -461,7 +461,7 @@ class PluginLoader {
|
|
|
461
461
|
perm: info.perm,
|
|
462
462
|
rank: info.rank,
|
|
463
463
|
reg: info.reg,
|
|
464
|
-
type: 'function',
|
|
464
|
+
type: App ? 'class' : 'function',
|
|
465
465
|
});
|
|
466
466
|
return true;
|
|
467
467
|
}
|
|
@@ -11,12 +11,11 @@ export class MessageHandler extends EventBaseHandler {
|
|
|
11
11
|
constructor(e) {
|
|
12
12
|
super(e);
|
|
13
13
|
this.e = e;
|
|
14
|
-
const cd = this.getCd();
|
|
15
14
|
this.init();
|
|
16
|
-
if (!cd)
|
|
17
|
-
return;
|
|
18
15
|
// todo: emit event
|
|
19
16
|
if (this.e.group_id) {
|
|
17
|
+
if (!this.getCd())
|
|
18
|
+
return;
|
|
20
19
|
if (!this.getMode())
|
|
21
20
|
return;
|
|
22
21
|
if (!this.getGroupEnable())
|
|
@@ -10,11 +10,10 @@ export class NoticeHandler extends EventBaseHandler {
|
|
|
10
10
|
constructor(e) {
|
|
11
11
|
super(e);
|
|
12
12
|
this.e = e;
|
|
13
|
-
const cd = this.getCd();
|
|
14
13
|
this.init();
|
|
15
|
-
if (!cd)
|
|
16
|
-
return;
|
|
17
14
|
if (this.e.group_id) {
|
|
15
|
+
if (!this.getCd())
|
|
16
|
+
return;
|
|
18
17
|
if (!this.getGroupEnable())
|
|
19
18
|
return;
|
|
20
19
|
if (!this.getUserEnable())
|
|
@@ -10,11 +10,10 @@ export class RequestHandler extends EventBaseHandler {
|
|
|
10
10
|
constructor(e) {
|
|
11
11
|
super(e);
|
|
12
12
|
this.e = e;
|
|
13
|
-
const cd = this.getCd();
|
|
14
13
|
this.init();
|
|
15
|
-
if (!cd)
|
|
16
|
-
return;
|
|
17
14
|
if (this.e.group_id) {
|
|
15
|
+
if (!this.getCd())
|
|
16
|
+
return;
|
|
18
17
|
if (!this.getGroupEnable())
|
|
19
18
|
return;
|
|
20
19
|
if (!this.getUserEnable())
|