node-karin 0.6.24 → 0.6.26
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.
|
@@ -99,7 +99,7 @@ export class OB11Event {
|
|
|
99
99
|
role: "unknown" /* Role.Unknown */,
|
|
100
100
|
};
|
|
101
101
|
const contact = {
|
|
102
|
-
scene:
|
|
102
|
+
scene: 'group_id' in data ? "group" /* Scene.Group */ : "friend" /* Scene.Private */,
|
|
103
103
|
peer: 'group_id' in data ? data.group_id : data.user_id,
|
|
104
104
|
sub_peer: '',
|
|
105
105
|
};
|
|
@@ -324,6 +324,8 @@ export class OB11Event {
|
|
|
324
324
|
// todo kritor没有这个事件
|
|
325
325
|
this.adapter.logger('info', `[群荣誉变更]:${JSON.stringify(data)}`);
|
|
326
326
|
break;
|
|
327
|
+
default:
|
|
328
|
+
return this.adapter.logger('error', '未知通知事件:', JSON.stringify(data));
|
|
327
329
|
}
|
|
328
330
|
break;
|
|
329
331
|
case 'group_msg_emoji_like': {
|
|
@@ -85,7 +85,7 @@ declare class PluginLoader {
|
|
|
85
85
|
/**
|
|
86
86
|
* 获取所有插件
|
|
87
87
|
*/
|
|
88
|
-
getPlugins():
|
|
88
|
+
getPlugins(): Promise<string[]>;
|
|
89
89
|
/**
|
|
90
90
|
* 获取指定文件夹下的所有插件
|
|
91
91
|
* @param dir - 插件包名称
|
|
@@ -102,8 +102,9 @@ declare class PluginLoader {
|
|
|
102
102
|
* @param dir - 插件包路径
|
|
103
103
|
* @param name - 插件名称
|
|
104
104
|
* @param isOrderBy - 是否为动态导入 默认为静态导入
|
|
105
|
+
* @param isNpm - 是否为npm包
|
|
105
106
|
*/
|
|
106
|
-
createdApp(dir: dirName, name: fileName, isOrderBy?: boolean): Promise<boolean>;
|
|
107
|
+
createdApp(dir: dirName, name: fileName, isOrderBy?: boolean, isNpm?: boolean): Promise<boolean>;
|
|
107
108
|
/**
|
|
108
109
|
* 新增rule
|
|
109
110
|
*/
|
|
@@ -84,7 +84,7 @@ class PluginLoader {
|
|
|
84
84
|
* 插件初始化
|
|
85
85
|
*/
|
|
86
86
|
async load () {
|
|
87
|
-
this.getPlugins()
|
|
87
|
+
await this.getPlugins()
|
|
88
88
|
listener.once('plugin.watch', () => {
|
|
89
89
|
for (const v of this.watchList) {
|
|
90
90
|
v.name ? this.watch(v.dir, v.name) : this.watchDir(v.dir)
|
|
@@ -95,6 +95,10 @@ class PluginLoader {
|
|
|
95
95
|
logger.info('加载插件中..')
|
|
96
96
|
/** 载入插件 */
|
|
97
97
|
const promises = this.FileList.map(async ({ dir, name }) => await this.createdApp(dir, name, false))
|
|
98
|
+
/** 获取npm插件 */
|
|
99
|
+
const npm = await common.getNpmPlugins(true)
|
|
100
|
+
/** 载入npm插件 */
|
|
101
|
+
promises.push(...npm.map(async ({ dir, name }) => await this.createdApp(dir, name, false, true)))
|
|
98
102
|
/** 等待所有插件加载完成 */
|
|
99
103
|
await Promise.all(promises)
|
|
100
104
|
/** 释放缓存 */
|
|
@@ -108,7 +112,7 @@ class PluginLoader {
|
|
|
108
112
|
/**
|
|
109
113
|
* 获取所有插件
|
|
110
114
|
*/
|
|
111
|
-
getPlugins () {
|
|
115
|
+
async getPlugins () {
|
|
112
116
|
/** 获取所有插件包 */
|
|
113
117
|
const plugins = common.getPlugins()
|
|
114
118
|
for (const dir of plugins) {
|
|
@@ -247,11 +251,12 @@ class PluginLoader {
|
|
|
247
251
|
* @param dir - 插件包路径
|
|
248
252
|
* @param name - 插件名称
|
|
249
253
|
* @param isOrderBy - 是否为动态导入 默认为静态导入
|
|
254
|
+
* @param isNpm - 是否为npm包
|
|
250
255
|
*/
|
|
251
|
-
async createdApp (dir, name, isOrderBy = false) {
|
|
256
|
+
async createdApp (dir, name, isOrderBy = false, isNpm = false) {
|
|
252
257
|
try {
|
|
253
258
|
const list = []
|
|
254
|
-
let path = `${this.dirPath}plugins/${dir}/${name}`
|
|
259
|
+
let path = `${this.dirPath}${isNpm ? 'node_modules' : 'plugins'}/${dir}/${name}`
|
|
255
260
|
if (isOrderBy) { path = path + `?${Date.now()}` }
|
|
256
261
|
const tmp = await import(path)
|
|
257
262
|
lodash.forEach(tmp, (App) => {
|
package/lib/index.js
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/// <reference types="@types/express" />
|
|
2
|
-
/// <reference types="@types/lodash" />
|
|
3
|
-
/// <reference types="@types/node" />
|
|
4
|
-
/// <reference types="@types/node-schedule" />
|
|
5
|
-
/// <reference types="@types/ws" />
|
|
6
1
|
// 基本模块
|
|
7
2
|
export * from 'kritor-proto';
|
|
8
3
|
export * from './core/index.js';
|
package/lib/types/plugin.d.ts
CHANGED
|
@@ -6,8 +6,10 @@ import { KarinNoticeType, KarinRequestType, AllListenEvent, KarinEventTypes, Kar
|
|
|
6
6
|
* - 插件根目录名称
|
|
7
7
|
* - 例如: karin-plugin-example
|
|
8
8
|
* - 例如: karin-plugin-example/apps
|
|
9
|
+
* - ### npm包类型: `string`
|
|
10
|
+
* - ### git插件类型: `karin-plugin-${string}`
|
|
9
11
|
*/
|
|
10
|
-
export type dirName = `karin-plugin-${string}
|
|
12
|
+
export type dirName = `karin-plugin-${string}` | string;
|
|
11
13
|
/**
|
|
12
14
|
* - 插件名称
|
|
13
15
|
* - 例如: index.js index.ts
|
package/lib/utils/common.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AxiosRequestConfig } from 'axios';
|
|
2
2
|
import { Readable } from 'stream';
|
|
3
3
|
import { fs } from '../modules.js';
|
|
4
|
-
import { dirName, KarinElement, NodeElement } from '../types/index.js';
|
|
4
|
+
import { dirName, fileName, KarinElement, NodeElement } from '../types/index.js';
|
|
5
5
|
/**
|
|
6
6
|
* 常用方法
|
|
7
7
|
*/
|
|
@@ -136,10 +136,19 @@ export declare const common: {
|
|
|
136
136
|
*/
|
|
137
137
|
makeForward(elements: KarinElement | KarinElement[], fakeUin: string, fakeNick: string): Array<NodeElement>;
|
|
138
138
|
/**
|
|
139
|
-
*
|
|
139
|
+
* 获取git插件列表
|
|
140
140
|
* @param isPack - 是否屏蔽不带package.json的插件,默认为false
|
|
141
141
|
*/
|
|
142
142
|
getPlugins(isPack?: boolean): Array<dirName>;
|
|
143
|
+
/**
|
|
144
|
+
* 获取npm插件列表
|
|
145
|
+
* @param showDetails - 是否返回详细信息,默认为false
|
|
146
|
+
* 默认只返回插件npm包名,为true时返回详细的{dir, name}[]
|
|
147
|
+
*/
|
|
148
|
+
getNpmPlugins<T extends boolean>(showDetails: T): Promise<T extends true ? {
|
|
149
|
+
dir: string;
|
|
150
|
+
name: fileName;
|
|
151
|
+
}[] : string[]>;
|
|
143
152
|
/**
|
|
144
153
|
* 获取运行时间
|
|
145
154
|
*/
|
package/lib/utils/common.js
CHANGED
|
@@ -364,7 +364,7 @@ export const common = new (class Common {
|
|
|
364
364
|
}
|
|
365
365
|
|
|
366
366
|
/**
|
|
367
|
-
*
|
|
367
|
+
* 获取git插件列表
|
|
368
368
|
* @param isPack - 是否屏蔽不带package.json的插件,默认为false
|
|
369
369
|
*/
|
|
370
370
|
getPlugins (isPack = false) {
|
|
@@ -378,6 +378,64 @@ export const common = new (class Common {
|
|
|
378
378
|
return arr
|
|
379
379
|
}
|
|
380
380
|
|
|
381
|
+
/**
|
|
382
|
+
* 获取npm插件列表
|
|
383
|
+
* @param showDetails - 是否返回详细信息,默认为false
|
|
384
|
+
* 默认只返回插件npm包名,为true时返回详细的{dir, name}[]
|
|
385
|
+
*/
|
|
386
|
+
async getNpmPlugins (showDetails) {
|
|
387
|
+
/** 屏蔽的依赖包列表 */
|
|
388
|
+
const pkgdependencies = [
|
|
389
|
+
'@grpc/grpc-js',
|
|
390
|
+
'@grpc/proto-loader',
|
|
391
|
+
'art-template',
|
|
392
|
+
'axios',
|
|
393
|
+
'chalk',
|
|
394
|
+
'chokidar',
|
|
395
|
+
'express',
|
|
396
|
+
'kritor-proto',
|
|
397
|
+
'level',
|
|
398
|
+
'lodash',
|
|
399
|
+
'log4js',
|
|
400
|
+
'moment',
|
|
401
|
+
'node-schedule',
|
|
402
|
+
'redis',
|
|
403
|
+
'ws',
|
|
404
|
+
'yaml',
|
|
405
|
+
]
|
|
406
|
+
const pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8'))
|
|
407
|
+
const dependencies = Object.keys(pkg.dependencies).filter((name) => !pkgdependencies.includes(name))
|
|
408
|
+
if (!showDetails) {
|
|
409
|
+
return dependencies
|
|
410
|
+
} else {
|
|
411
|
+
const list = []
|
|
412
|
+
const readPackageJson = async (name) => {
|
|
413
|
+
try {
|
|
414
|
+
const pkgPath = path.join(process.cwd(), 'node_modules', name, 'package.json')
|
|
415
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'))
|
|
416
|
+
if (pkg?.karin) {
|
|
417
|
+
if (pkg?.main) {
|
|
418
|
+
const dir = `${name}/${path.dirname(pkg.main).replace(/\.\//, '')}`
|
|
419
|
+
list.push({ dir, name: path.basename(pkg.main) })
|
|
420
|
+
}
|
|
421
|
+
if (pkg?.karin?.apps?.length) {
|
|
422
|
+
pkg.karin.apps.forEach((app) => {
|
|
423
|
+
fs.readdirSync(`./node_modules/${name}/${app}`).forEach((name) => {
|
|
424
|
+
/** 忽略非js */
|
|
425
|
+
if (!name.endsWith('.js')) { return }
|
|
426
|
+
const dir = `${name}/${app}`
|
|
427
|
+
list.push({ dir, name })
|
|
428
|
+
})
|
|
429
|
+
})
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
} catch { }
|
|
433
|
+
}
|
|
434
|
+
await Promise.all(dependencies.map(readPackageJson))
|
|
435
|
+
return list
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
|
|
381
439
|
/**
|
|
382
440
|
* 获取运行时间
|
|
383
441
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-karin",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.26",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "基于 Kritor 进行开发的nodejs机器人框架",
|
|
6
6
|
"homepage": "https://github.com/KarinJS/Karin",
|
|
@@ -49,9 +49,8 @@
|
|
|
49
49
|
"sort": "npx sort-package-json"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@grpc/grpc-js": "1.10.
|
|
52
|
+
"@grpc/grpc-js": "1.10.11",
|
|
53
53
|
"@grpc/proto-loader": "0.7.13",
|
|
54
|
-
"@inquirer/prompts": "5.1.2",
|
|
55
54
|
"art-template": "4.13.2",
|
|
56
55
|
"axios": "1.7.2",
|
|
57
56
|
"chalk": "5.3.0",
|
|
@@ -64,8 +63,8 @@
|
|
|
64
63
|
"moment": "2.30.1",
|
|
65
64
|
"node-schedule": "2.1.1",
|
|
66
65
|
"redis": "4.6.14",
|
|
67
|
-
"ws": "8.
|
|
68
|
-
"yaml": "2.4.
|
|
66
|
+
"ws": "8.18.0",
|
|
67
|
+
"yaml": "2.4.5"
|
|
69
68
|
},
|
|
70
69
|
"devDependencies": {
|
|
71
70
|
"@types/express": "latest",
|