node-karin 0.6.21 → 0.6.23
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.js +5 -5
- package/lib/adapter/kritor/grpc.js +59 -59
- package/lib/adapter/onebot/11/convert.js +17 -18
- package/lib/adapter/onebot/11/event.js +21 -21
- package/lib/adapter/onebot/11/index.js +50 -52
- package/lib/cli/init.js +1 -20
- package/lib/cli/restart.js +10 -0
- package/lib/cli/start.d.ts +2 -0
- package/lib/cli/start.js +10 -0
- package/lib/cli/stop.d.ts +2 -0
- package/lib/cli/stop.js +10 -0
- package/lib/cli/up.d.ts +0 -0
- package/lib/cli/up.js +1 -0
- package/lib/core/init.js +8 -0
- package/lib/core/karin.js +2 -3
- package/lib/core/plugin.app.js +1 -2
- package/lib/core/plugin.js +1 -2
- package/lib/core/plugin.loader.d.ts +7 -16
- package/lib/core/plugin.loader.js +100 -146
- package/lib/core/process.js +3 -3
- package/lib/core/server.js +2 -5
- package/lib/event/notice.handler.js +16 -17
- package/lib/event/request.handler.js +3 -4
- package/lib/types/event/contact.d.ts +1 -1
- package/lib/types/event/contact.js +1 -13
- package/lib/types/event/event.d.ts +5 -5
- package/lib/types/event/event.js +1 -234
- package/lib/types/event/notice.js +1 -2
- package/lib/types/event/request.js +1 -2
- package/lib/types/event/sender.d.ts +2 -2
- package/lib/types/event/sender.js +1 -22
- package/lib/types/onebot11/api.d.ts +1 -1
- package/lib/types/onebot11/api.js +1 -54
- package/lib/types/onebot11/event.d.ts +5 -5
- package/lib/types/onebot11/event.js +1 -55
- package/lib/types/onebot11/params.d.ts +1 -1
- package/lib/types/onebot11/params.js +1 -7
- package/lib/types/onebot11/response.js +1 -1
- package/lib/types/onebot11/segment.d.ts +1 -1
- package/lib/types/onebot11/segment.js +1 -30
- package/lib/utils/common.d.ts +2 -3
- package/lib/utils/common.js +6 -6
- package/lib/utils/init.d.ts +1 -1
- package/lib/utils/init.js +25 -20
- package/lib/utils/segment.d.ts +3 -3
- package/lib/utils/segment.js +2 -2
- package/package.json +11 -22
- package/lib/cli/postinstall.js +0 -25
- package/pnpm-workspace.yaml +0 -2
- /package/lib/cli/{postinstall.d.ts → restart.d.ts} +0 -0
package/lib/core/plugin.app.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { EventType } from '../types/index.js'
|
|
2
1
|
export default function PluginApp (options) {
|
|
3
2
|
return {
|
|
4
3
|
file: {
|
|
@@ -8,7 +7,7 @@ export default function PluginApp (options) {
|
|
|
8
7
|
Fnc: options?.file?.fnc || '',
|
|
9
8
|
},
|
|
10
9
|
name: options.name || '',
|
|
11
|
-
event: options.event || EventType.Message
|
|
10
|
+
event: options.event || 'message' /* EventType.Message */,
|
|
12
11
|
priority: options.priority || 10000,
|
|
13
12
|
accept: options.accept ?? false,
|
|
14
13
|
rule: options.rule || [],
|
package/lib/core/plugin.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { EventType } from '../types/index.js'
|
|
2
1
|
/**
|
|
3
2
|
* 插件基类
|
|
4
3
|
*/
|
|
@@ -48,7 +47,7 @@ export class Plugin {
|
|
|
48
47
|
* @param timeout - 上下文超时
|
|
49
48
|
*/
|
|
50
49
|
timeout
|
|
51
|
-
constructor ({ name, dsc = name, desc = name, event = EventType.Message
|
|
50
|
+
constructor ({ name, dsc = name, desc = name, event = 'message' /* EventType.Message */, priority = 10000, task = [], rule = [], handler = [], button = [] }) {
|
|
52
51
|
this.name = name
|
|
53
52
|
this.dsc = dsc
|
|
54
53
|
this.desc = desc
|
|
@@ -71,6 +71,12 @@ declare class PluginLoader {
|
|
|
71
71
|
dir: dirName;
|
|
72
72
|
name?: fileName;
|
|
73
73
|
}>;
|
|
74
|
+
/**
|
|
75
|
+
* - 所有插件包package.json
|
|
76
|
+
*/
|
|
77
|
+
pkgJson: {
|
|
78
|
+
[key: string]: any;
|
|
79
|
+
};
|
|
74
80
|
constructor();
|
|
75
81
|
/**
|
|
76
82
|
* 插件初始化
|
|
@@ -79,16 +85,7 @@ declare class PluginLoader {
|
|
|
79
85
|
/**
|
|
80
86
|
* 获取所有插件
|
|
81
87
|
*/
|
|
82
|
-
getPlugins():
|
|
83
|
-
/**
|
|
84
|
-
* 传入路径 语言环境 返回加载index.ts 还是 index.js
|
|
85
|
-
* @param path - 插件路径
|
|
86
|
-
* @param lang - 语言环境
|
|
87
|
-
*/
|
|
88
|
-
getIndex(path: string, dir: dirName, lang: 'js' | 'ts'): {
|
|
89
|
-
dir: dirName;
|
|
90
|
-
name: fileName;
|
|
91
|
-
} | false;
|
|
88
|
+
getPlugins(): `karin-plugin-${string}`[];
|
|
92
89
|
/**
|
|
93
90
|
* 获取指定文件夹下的所有插件
|
|
94
91
|
* @param dir - 插件包名称
|
|
@@ -143,12 +140,6 @@ declare class PluginLoader {
|
|
|
143
140
|
* 监听文件夹更新
|
|
144
141
|
*/
|
|
145
142
|
watchDir(dir: dirName): Promise<true | undefined>;
|
|
146
|
-
watcAdd(dir: dirName, name: fileName): Promise<boolean | undefined>;
|
|
147
|
-
/**
|
|
148
|
-
* 传入文件名称 返回是否符合当前环境规则
|
|
149
|
-
* @param name - 文件名称
|
|
150
|
-
*/
|
|
151
|
-
isApp(name: fileName): boolean;
|
|
152
143
|
}
|
|
153
144
|
/**
|
|
154
145
|
* 加载插件
|
|
@@ -7,7 +7,6 @@ import { listener } from './listener.js'
|
|
|
7
7
|
import PluginApp from './plugin.app.js'
|
|
8
8
|
import { render } from '../render/index.js'
|
|
9
9
|
import { common, handler, logger } from '../utils/index.js'
|
|
10
|
-
import { Permission } from '../types/index.js'
|
|
11
10
|
class PluginLoader {
|
|
12
11
|
dir
|
|
13
12
|
dirPath
|
|
@@ -59,6 +58,10 @@ class PluginLoader {
|
|
|
59
58
|
* - 热更新列表
|
|
60
59
|
*/
|
|
61
60
|
watchList
|
|
61
|
+
/**
|
|
62
|
+
* - 所有插件包package.json
|
|
63
|
+
*/
|
|
64
|
+
pkgJson
|
|
62
65
|
constructor () {
|
|
63
66
|
this.index = 0
|
|
64
67
|
this.dir = './plugins'
|
|
@@ -74,6 +77,7 @@ class PluginLoader {
|
|
|
74
77
|
this.acceptIds = []
|
|
75
78
|
this.buttonIds = []
|
|
76
79
|
this.handlerIds = {}
|
|
80
|
+
this.pkgJson = {}
|
|
77
81
|
}
|
|
78
82
|
|
|
79
83
|
/**
|
|
@@ -125,67 +129,63 @@ class PluginLoader {
|
|
|
125
129
|
continue
|
|
126
130
|
}
|
|
127
131
|
/** package */
|
|
128
|
-
const
|
|
129
|
-
/**
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
135
|
-
/** 新版本入口 */
|
|
136
|
-
if (pack.main) {
|
|
137
|
-
const { dir: dirName, pop } = common.splitPath(pack.main)
|
|
132
|
+
const pkg = common.readJson(`${PluginPath}/package.json`)
|
|
133
|
+
/** 缓存package.json */
|
|
134
|
+
this.pkgJson[dir] = pkg
|
|
135
|
+
/** 入口文件 */
|
|
136
|
+
if (pkg.main) {
|
|
137
|
+
const { dir: dirName, pop } = common.splitPath(pkg.main)
|
|
138
138
|
const dirPath = `${dir}/${dirName}`
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
this.getApps((`${dir}/${apps}`), this.isTs)
|
|
151
|
-
})
|
|
139
|
+
if (common.exists(`${this.dir}/${dirPath}/${pop}`)) {
|
|
140
|
+
this.FileList.push({ dir: dirPath, name: pop })
|
|
141
|
+
this.isDev && this.watchList.push({ dir: dirPath, name: pop })
|
|
142
|
+
} else {
|
|
143
|
+
logger.debug(`[插件收集][${pkg.main}] 入口文件不存在,已忽略`)
|
|
144
|
+
}
|
|
145
|
+
} else {
|
|
146
|
+
/** 没有配置入口默认为index.js */
|
|
147
|
+
if (common.exists(`${PluginPath}/index.js`)) {
|
|
148
|
+
this.FileList.push({ dir, name: 'index.js' })
|
|
149
|
+
this.isDev && this.watchList.push({ dir, name: 'index.js' })
|
|
152
150
|
}
|
|
153
151
|
}
|
|
154
|
-
/**
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
152
|
+
/** 全部apps路径 */
|
|
153
|
+
const apps = ['apps']
|
|
154
|
+
if (pkg?.karin?.apps && Array.isArray(pkg.karin.apps)) { apps.push(...pkg.karin.apps) }
|
|
155
|
+
/** js环境 或 ts环境、js插件 */
|
|
156
|
+
if (!this.isTs || !common.exists(`${PluginPath}/tsconfig.json`)) {
|
|
157
|
+
apps.forEach((apps) => {
|
|
158
|
+
/** 路径存在才加载 */
|
|
159
|
+
if (common.isDir(`${PluginPath}/${apps}`)) {
|
|
160
|
+
this.getApps((`${dir}/${apps}`), false, this.isDev)
|
|
161
|
+
} else {
|
|
162
|
+
logger.debug(`[插件收集][${dir}/${apps}] 路径不存在,已忽略`)
|
|
163
|
+
}
|
|
164
|
+
})
|
|
165
|
+
continue
|
|
166
|
+
}
|
|
167
|
+
/** ts环境 ts插件 */
|
|
168
|
+
const outDir = pkg?.karin?.outDir || 'lib'
|
|
169
|
+
const rootDir = pkg?.karin?.rootDir || 'src'
|
|
170
|
+
/** 编译产物存在 */
|
|
171
|
+
if (common.exists(`${PluginPath}/${outDir}/apps`)) {
|
|
172
|
+
this.getApps((`${dir}/${outDir}/apps`), true, this.isDev)
|
|
173
|
+
continue
|
|
174
|
+
} else {
|
|
175
|
+
/** 入口文件 */
|
|
176
|
+
if (common.exists(`${PluginPath}/${rootDir}/index.ts`)) {
|
|
177
|
+
this.FileList.push({ dir, name: 'index.ts' })
|
|
178
|
+
this.isDev && this.watchList.push({ dir, name: 'index.ts' })
|
|
159
179
|
continue
|
|
160
180
|
}
|
|
161
|
-
/** ts */
|
|
162
|
-
if (common.exists(`${PluginPath}/
|
|
163
|
-
this.getApps((`${dir}/
|
|
181
|
+
/** ts源码 */
|
|
182
|
+
if (common.exists(`${PluginPath}/${rootDir}/apps`)) {
|
|
183
|
+
this.getApps((`${dir}/${rootDir}/apps`), true, this.isDev)
|
|
164
184
|
continue
|
|
165
185
|
}
|
|
166
186
|
}
|
|
167
|
-
/** js环境 */
|
|
168
|
-
if (common.isDir(`${PluginPath}/apps`)) { this.getApps(`${dir}/apps`, false) }
|
|
169
|
-
/** 这里需要判断下 不然ts环境下会重复加载 */
|
|
170
|
-
if (!this.isTs && common.isDir(`${PluginPath}/${outDir}/apps`)) { this.getApps(`${dir}/${outDir}/apps`, false) }
|
|
171
187
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* 传入路径 语言环境 返回加载index.ts 还是 index.js
|
|
176
|
-
* @param path - 插件路径
|
|
177
|
-
* @param lang - 语言环境
|
|
178
|
-
*/
|
|
179
|
-
getIndex (path, dir, lang) {
|
|
180
|
-
const isJS = common.exists(`${path}/index.js`)
|
|
181
|
-
if (isJS && lang === 'js') {
|
|
182
|
-
return { dir, name: 'index.js' }
|
|
183
|
-
}
|
|
184
|
-
const isTS = common.exists(`${path}/src/index.ts`)
|
|
185
|
-
if (isTS && lang === 'ts') {
|
|
186
|
-
return { dir: `${dir}/src`, name: 'index.ts' }
|
|
187
|
-
}
|
|
188
|
-
return false
|
|
188
|
+
return plugins
|
|
189
189
|
}
|
|
190
190
|
|
|
191
191
|
/**
|
|
@@ -258,7 +258,10 @@ class PluginLoader {
|
|
|
258
258
|
const index = this.index
|
|
259
259
|
this.index++
|
|
260
260
|
if (typeof App === 'object' && App?.file?.type === 'function') {
|
|
261
|
-
if (!App?.name) {
|
|
261
|
+
if (!App?.name) {
|
|
262
|
+
logger.error(`[${dir}][${name}] 插件名称错误`)
|
|
263
|
+
return false
|
|
264
|
+
}
|
|
262
265
|
App.file.dir = dir
|
|
263
266
|
App.file.name = name
|
|
264
267
|
App.rule.forEach((v, index) => {
|
|
@@ -271,9 +274,12 @@ class PluginLoader {
|
|
|
271
274
|
if (App.accept) { this.acceptIds.push(index) }
|
|
272
275
|
return true
|
|
273
276
|
}
|
|
274
|
-
if (typeof App !== 'function' || !App?.prototype?.constructor) { return }
|
|
277
|
+
if (typeof App !== 'function' || !App?.prototype?.constructor) { return false }
|
|
275
278
|
const Class = new App()
|
|
276
|
-
if (!Class.name) {
|
|
279
|
+
if (!Class.name) {
|
|
280
|
+
logger.error(`[${dir}][${name}] 插件名称错误`)
|
|
281
|
+
return false
|
|
282
|
+
}
|
|
277
283
|
logger.debug(`载入插件 [${name}][${Class.name}]`)
|
|
278
284
|
this.PluginList[index] = PluginApp({
|
|
279
285
|
file: { dir, name, type: 'class', fnc: App },
|
|
@@ -291,7 +297,7 @@ class PluginLoader {
|
|
|
291
297
|
return true
|
|
292
298
|
})
|
|
293
299
|
await Promise.all(list)
|
|
294
|
-
|
|
300
|
+
/** 建立对应的规则索引并排序 */
|
|
295
301
|
if (isOrderBy) { this.orderBy() }
|
|
296
302
|
return true
|
|
297
303
|
} catch (error) {
|
|
@@ -322,7 +328,7 @@ class PluginLoader {
|
|
|
322
328
|
reg: val.reg instanceof RegExp ? val.reg : new RegExp(val.reg),
|
|
323
329
|
fnc: val.fnc,
|
|
324
330
|
event: val.event,
|
|
325
|
-
permission: val.permission || Permission.All
|
|
331
|
+
permission: val.permission || 'all' /* Permission.All */,
|
|
326
332
|
log: val.log === false ? (id, log) => logger.debug('mark', id, log) : (id, log) => logger.bot('mark', id, log),
|
|
327
333
|
})
|
|
328
334
|
})
|
|
@@ -450,8 +456,7 @@ class PluginLoader {
|
|
|
450
456
|
/** 卸载 */
|
|
451
457
|
this.uninstallApp(dir, name)
|
|
452
458
|
/** 载入插件 */
|
|
453
|
-
|
|
454
|
-
if (!res) { return }
|
|
459
|
+
await this.createdApp(dir, name, true)
|
|
455
460
|
logger.mark(`[修改插件][${dir}][${name}]`)
|
|
456
461
|
})
|
|
457
462
|
/** 监听删除 */
|
|
@@ -460,6 +465,8 @@ class PluginLoader {
|
|
|
460
465
|
this.uninstallApp(dir, name)
|
|
461
466
|
this.watcher.delete(`${dir}.${name}`)
|
|
462
467
|
logger.mark(`[卸载插件][${dir}][${name}]`)
|
|
468
|
+
/** 卸载之后停止监听 */
|
|
469
|
+
watcher.close()
|
|
463
470
|
})
|
|
464
471
|
this.watcher.set(`${dir}.${name}`, watcher)
|
|
465
472
|
}
|
|
@@ -471,60 +478,40 @@ class PluginLoader {
|
|
|
471
478
|
if (this.watcher.get(dir)) { return }
|
|
472
479
|
const file = `${this.dir}/${dir}/`
|
|
473
480
|
const watcher = chokidar.watch(file)
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
/**
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
/**
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
if (!res) { return }
|
|
507
|
-
logger.mark(`[修改插件][${dir}][${name}]`)
|
|
508
|
-
})
|
|
509
|
-
/** 监听删除 */
|
|
510
|
-
watcher.on('unlink', async (PluPath) => {
|
|
511
|
-
const name = path.basename(PluPath)
|
|
512
|
-
if (!name.endsWith('')) { return }
|
|
513
|
-
/** 卸载 */
|
|
514
|
-
this.uninstallApp(dir, name)
|
|
515
|
-
/** 停止监听 */
|
|
516
|
-
watcher.close()
|
|
517
|
-
/** 重新监听文件夹 */
|
|
518
|
-
this.watcher.delete(dir)
|
|
519
|
-
this.watchDir(dir)
|
|
520
|
-
logger.mark(`[卸载插件][${dir}][${name}]`)
|
|
521
|
-
})
|
|
522
|
-
}, 500)
|
|
523
|
-
/** 生成随机数0.5-2秒 */
|
|
524
|
-
const random = Math.floor(Math.random() * 1000) + 500
|
|
525
|
-
await common.sleep(random)
|
|
526
|
-
const isExist = this.watcher.get(dir)
|
|
481
|
+
await common.sleep(1000)
|
|
482
|
+
watcher.on('add', async (_path) => {
|
|
483
|
+
/** 排除掉不符合规则文件新增 */
|
|
484
|
+
const ext = this.isTs ? ['.js', '.ts'] : ['.js']
|
|
485
|
+
if (!ext.some(ext => _path.endsWith(ext))) { return }
|
|
486
|
+
const name = path.basename(_path)
|
|
487
|
+
await this.createdApp(dir, name, true)
|
|
488
|
+
logger.mark(`[新增插件][${dir}][${name}]`)
|
|
489
|
+
return true
|
|
490
|
+
})
|
|
491
|
+
watcher.on('change', async (_path) => {
|
|
492
|
+
/** 排除掉不符合规则文件新增 */
|
|
493
|
+
const ext = this.isTs ? ['.js', '.ts'] : ['.js']
|
|
494
|
+
if (!ext.some(ext => _path.endsWith(ext))) { return }
|
|
495
|
+
const name = path.basename(_path)
|
|
496
|
+
/** 卸载 */
|
|
497
|
+
this.uninstallApp(dir, name)
|
|
498
|
+
/** 载入插件 */
|
|
499
|
+
await this.createdApp(dir, name, true)
|
|
500
|
+
logger.mark(`[修改插件][${dir}][${name}]`)
|
|
501
|
+
return true
|
|
502
|
+
})
|
|
503
|
+
watcher.on('unlink', async (_path) => {
|
|
504
|
+
/** 排除掉不符合规则文件新增 */
|
|
505
|
+
const ext = this.isTs ? ['.js', '.ts'] : ['.js']
|
|
506
|
+
if (!ext.some(ext => _path.endsWith(ext))) { return }
|
|
507
|
+
const name = path.basename(_path)
|
|
508
|
+
/** 卸载 */
|
|
509
|
+
this.uninstallApp(dir, name)
|
|
510
|
+
logger.mark(`[卸载插件][${dir}][${name}]`)
|
|
511
|
+
return true
|
|
512
|
+
})
|
|
527
513
|
/** 这里需要检查一下是否已经存在,已经存在就关掉之前的监听 */
|
|
514
|
+
const isExist = this.watcher.get(dir)
|
|
528
515
|
if (isExist) {
|
|
529
516
|
isExist.close()
|
|
530
517
|
this.watcher.delete(dir)
|
|
@@ -532,39 +519,6 @@ class PluginLoader {
|
|
|
532
519
|
this.watcher.set(dir, watcher)
|
|
533
520
|
return true
|
|
534
521
|
}
|
|
535
|
-
|
|
536
|
-
async watcAdd (dir, name) {
|
|
537
|
-
const file = `${this.dir}/${dir}/`
|
|
538
|
-
const filePath = `${file}/${name}`
|
|
539
|
-
logger.debug(`[热更新][新增插件] ${filePath}`)
|
|
540
|
-
if (!this.isApp(name)) {
|
|
541
|
-
logger.debug(`[热更新][新增插件] ${filePath} 文件类型错误 不符合当前环境规则 已忽略`)
|
|
542
|
-
return false
|
|
543
|
-
}
|
|
544
|
-
/** 载入插件 */
|
|
545
|
-
const res = await this.createdApp(dir, name, true)
|
|
546
|
-
if (!res) { return }
|
|
547
|
-
/** 延迟1秒 等待卸载完成 */
|
|
548
|
-
await common.sleep(1000)
|
|
549
|
-
/** 新增插件之后重新监听文件夹 */
|
|
550
|
-
this.watcher.delete(dir)
|
|
551
|
-
this.watchDir(dir)
|
|
552
|
-
logger.mark(`[新增插件][${dir}][${name}]`)
|
|
553
|
-
return true
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
/**
|
|
557
|
-
* 传入文件名称 返回是否符合当前环境规则
|
|
558
|
-
* @param name - 文件名称
|
|
559
|
-
*/
|
|
560
|
-
isApp (name) {
|
|
561
|
-
/** 任何环境都支持js */
|
|
562
|
-
if (name.endsWith('.js')) { return true }
|
|
563
|
-
/** ts环境支持ts */
|
|
564
|
-
if (name.endsWith('.ts') && this.isTs) { return true }
|
|
565
|
-
/** 其他情况返回false */
|
|
566
|
-
return false
|
|
567
|
-
}
|
|
568
522
|
}
|
|
569
523
|
/**
|
|
570
524
|
* 加载插件
|
package/lib/core/process.js
CHANGED
|
@@ -51,17 +51,17 @@ export default class Process {
|
|
|
51
51
|
* 检查后台进程
|
|
52
52
|
*/
|
|
53
53
|
static async check () {
|
|
54
|
-
const host = `http://
|
|
54
|
+
const host = `http://127.0.0.1:${config.Server.http.port}/api`
|
|
55
55
|
/**
|
|
56
56
|
* 使用api来检查后台
|
|
57
57
|
*/
|
|
58
|
-
const res = await common.axios(host + '/
|
|
58
|
+
const res = await common.axios(host + '/pm2', 'get', { timeout: 100 })
|
|
59
59
|
if (!res) { return this }
|
|
60
60
|
logger.mark(logger.red('检测到后台进程 正在关闭'))
|
|
61
61
|
/** 发退出信号 */
|
|
62
62
|
await common.axios(host + '/exit', 'get', { timeout: 10 })
|
|
63
63
|
for (let i = 0; i < 50; i++) {
|
|
64
|
-
const res = await common.axios(host + '/
|
|
64
|
+
const res = await common.axios(host + '/pm2', 'get', { timeout: 100 })
|
|
65
65
|
/** 请求成功继续循环 */
|
|
66
66
|
if (res) { continue }
|
|
67
67
|
/** 请求异常即代表后台进程已关闭 */
|
package/lib/core/server.js
CHANGED
|
@@ -53,14 +53,11 @@ export const server = new (class Server {
|
|
|
53
53
|
}
|
|
54
54
|
})
|
|
55
55
|
/** GET接口 - 获取当前启动信息 */
|
|
56
|
-
this.app.get('/api/
|
|
56
|
+
this.app.get('/api/pm2', (req, res) => {
|
|
57
57
|
/** 只允许本机ip访问 */
|
|
58
58
|
if (req.hostname === 'localhost' || req.hostname === '127.0.0.1') {
|
|
59
59
|
const data = {
|
|
60
|
-
|
|
61
|
-
start_time: process.uptime().toFixed(2),
|
|
62
|
-
memory: (process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2),
|
|
63
|
-
time: Date.now(),
|
|
60
|
+
pm2_id: process.env.pm_id || '',
|
|
64
61
|
}
|
|
65
62
|
res.json(data)
|
|
66
63
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { review } from './review.handler.js'
|
|
2
2
|
import EventHandler from './event.handler.js'
|
|
3
3
|
import { logger, config } from '../utils/index.js'
|
|
4
|
-
import { NoticeSubType } from '../types/index.js'
|
|
5
4
|
import { pluginLoader } from '../core/index.js'
|
|
6
5
|
/**
|
|
7
6
|
* 通知事件
|
|
@@ -85,48 +84,48 @@ export default class NoticeHandler extends EventHandler {
|
|
|
85
84
|
raw_message () {
|
|
86
85
|
switch (this.e.sub_event) {
|
|
87
86
|
/** 好友头像戳一戳 */
|
|
88
|
-
case NoticeSubType.PrivatePoke
|
|
87
|
+
case 'private_poke' /* NoticeSubType.PrivatePoke */: {
|
|
89
88
|
this.e.raw_message = '[好友戳一戳]: 戳了你一下'
|
|
90
89
|
break
|
|
91
90
|
}
|
|
92
91
|
/** 好友消息撤回 */
|
|
93
|
-
case NoticeSubType.PrivateRecall
|
|
92
|
+
case 'private_recall' /* NoticeSubType.PrivateRecall */: {
|
|
94
93
|
this.e.raw_message = `[好友消息撤回]: ${this.e.content.message_id}`
|
|
95
94
|
break
|
|
96
95
|
}
|
|
97
96
|
/** 私聊文件上传 */
|
|
98
|
-
case NoticeSubType.PrivateFileUploaded
|
|
97
|
+
case 'private_file_uploaded' /* NoticeSubType.PrivateFileUploaded */: {
|
|
99
98
|
const content = this.e.content
|
|
100
99
|
const { file_url } = content
|
|
101
100
|
this.e.raw_message = `[私聊文件上传]: ${file_url}`
|
|
102
101
|
break
|
|
103
102
|
}
|
|
104
103
|
/** 群头像戳一戳 */
|
|
105
|
-
case NoticeSubType.GroupPoke
|
|
104
|
+
case 'group_poke' /* NoticeSubType.GroupPoke */: {
|
|
106
105
|
const { operator_uid, operator_uin, target_uid, target_uin } = this.e.content
|
|
107
106
|
this.e.raw_message = `[群戳一戳]: ${operator_uid || operator_uin} 戳了戳 ${target_uid || target_uin}`
|
|
108
107
|
break
|
|
109
108
|
}
|
|
110
109
|
/** 群消息撤回 */
|
|
111
|
-
case NoticeSubType.GroupRecall
|
|
110
|
+
case 'group_recall' /* NoticeSubType.GroupRecall */: {
|
|
112
111
|
const { operator_uid, operator_uin, message_id } = this.e.content
|
|
113
112
|
this.e.raw_message = `[群消息撤回]: ${operator_uid || operator_uin} 撤回了一条消息 ${message_id}`
|
|
114
113
|
break
|
|
115
114
|
}
|
|
116
115
|
/** 群文件上传 */
|
|
117
|
-
case NoticeSubType.GroupFileUploaded
|
|
116
|
+
case 'group_file_uploaded' /* NoticeSubType.GroupFileUploaded */: {
|
|
118
117
|
const { file_url, operator_uid, operator_uin } = this.e.content
|
|
119
118
|
this.e.raw_message = `[群文件上传]: ${operator_uid || operator_uin} 上传了 ${file_url}`
|
|
120
119
|
break
|
|
121
120
|
}
|
|
122
121
|
/** 群成员增加 */
|
|
123
|
-
case NoticeSubType.GroupMemberIncrease
|
|
122
|
+
case 'group_member_increase' /* NoticeSubType.GroupMemberIncrease */: {
|
|
124
123
|
const { operator_uid, operator_uin, target_uid, target_uin, type } = this.e.content
|
|
125
124
|
this.e.raw_message = `[群成员新增]: ${operator_uid || operator_uin} ${type === 'invite' ? '邀请' : '同意'} ${target_uid || target_uin} 加入群聊`
|
|
126
125
|
break
|
|
127
126
|
}
|
|
128
127
|
/** 群成员减少 */
|
|
129
|
-
case NoticeSubType.GroupMemberDecrease
|
|
128
|
+
case 'group_member_decrease' /* NoticeSubType.GroupMemberDecrease */: {
|
|
130
129
|
switch (this.e.content.type) {
|
|
131
130
|
case 'leave': {
|
|
132
131
|
const { target_uid, target_uin } = this.e.content
|
|
@@ -149,49 +148,49 @@ export default class NoticeHandler extends EventHandler {
|
|
|
149
148
|
break
|
|
150
149
|
}
|
|
151
150
|
/** 群管理员变动 */
|
|
152
|
-
case NoticeSubType.GroupAdminChanged
|
|
151
|
+
case 'group_admin_changed' /* NoticeSubType.GroupAdminChanged */: {
|
|
153
152
|
const { target_uid, target_uin, is_admin } = this.e.content
|
|
154
153
|
this.e.raw_message = `[群管理员变动]: ${target_uid || target_uin} 被${is_admin ? '设置' : '取消'}群管理员`
|
|
155
154
|
break
|
|
156
155
|
}
|
|
157
156
|
/** 群成员被禁言 */
|
|
158
|
-
case NoticeSubType.GroupMemberBan
|
|
157
|
+
case 'group_member_ban' /* NoticeSubType.GroupMemberBan */: {
|
|
159
158
|
const { operator_uid, operator_uin, target_uid, target_uin, type } = this.e.content
|
|
160
159
|
this.e.raw_message = `[群成员禁言]: ${operator_uid || operator_uin} ${type === 'ban' ? '禁言' : '解禁'}了 ${target_uid || target_uin}`
|
|
161
160
|
break
|
|
162
161
|
}
|
|
163
162
|
/** 群签到 */
|
|
164
|
-
case NoticeSubType.GroupSignIn
|
|
163
|
+
case 'group_sign_in' /* NoticeSubType.GroupSignIn */: {
|
|
165
164
|
const { target_uid, target_uin } = this.e.content
|
|
166
165
|
this.e.raw_message = `[群签到]: ${target_uid || target_uin}`
|
|
167
166
|
break
|
|
168
167
|
}
|
|
169
168
|
/** 群全员禁言 */
|
|
170
|
-
case NoticeSubType.GroupWholeBan
|
|
169
|
+
case 'group_whole_ban' /* NoticeSubType.GroupWholeBan */: {
|
|
171
170
|
const { operator_uid, operator_uin, is_ban } = this.e.content
|
|
172
171
|
this.e.raw_message = `[群全员禁言]: ${operator_uid || operator_uin} ${is_ban ? '开启全员禁言' : '解除全员禁言'}`
|
|
173
172
|
break
|
|
174
173
|
}
|
|
175
174
|
/** 群名片改变 */
|
|
176
|
-
case NoticeSubType.GroupCardChanged
|
|
175
|
+
case 'group_card_changed' /* NoticeSubType.GroupCardChanged */: {
|
|
177
176
|
const { operator_uid, operator_uin, target_uid, target_uin, new_card } = this.e.content
|
|
178
177
|
this.e.raw_message = `[群名片改变]: ${operator_uid || operator_uin} 修改了 ${target_uid || target_uin} 的名片为 ${new_card}`
|
|
179
178
|
break
|
|
180
179
|
}
|
|
181
180
|
/** 群成员专属头衔改变 */
|
|
182
|
-
case NoticeSubType.GroupMemberUniqueTitleChanged
|
|
181
|
+
case 'group_member_unique_title_changed' /* NoticeSubType.GroupMemberUniqueTitleChanged */: {
|
|
183
182
|
const { target_uid, target_uin, title } = this.e.content
|
|
184
183
|
this.e.raw_message = `[群头衔更改]: ${target_uid || target_uin} 的专属头衔改变为 ${title}`
|
|
185
184
|
break
|
|
186
185
|
}
|
|
187
186
|
/** 群精华消息改变 */
|
|
188
|
-
case NoticeSubType.GroupEssenceChanged
|
|
187
|
+
case 'group_essence_changed' /* NoticeSubType.GroupEssenceChanged */: {
|
|
189
188
|
const { operator_uid, operator_uin, target_uid, target_uin, message_id, is_set } = this.e.content
|
|
190
189
|
this.e.raw_message = `[群精华消息]: ${operator_uid || operator_uin} ${is_set ? `将${target_uid || target_uin}的消息${message_id}设置为精华消息` : `取消了${target_uid || target_uin}精华消息 ${message_id}`}`
|
|
191
190
|
break
|
|
192
191
|
}
|
|
193
192
|
/** 群表情回应 */
|
|
194
|
-
case NoticeSubType.GroupMessageReaction
|
|
193
|
+
case 'group_message_reaction' /* NoticeSubType.GroupMessageReaction */: {
|
|
195
194
|
const { message_id, face_id } = this.e.content
|
|
196
195
|
this.e.raw_message = `[群表情回应]: ${this.e.user_id} 给消息 ${message_id} 回应了一个${face_id}的表情`
|
|
197
196
|
break
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { review } from './review.handler.js'
|
|
2
2
|
import EventHandler from './event.handler.js'
|
|
3
3
|
import { logger, config } from '../utils/index.js'
|
|
4
|
-
import { RequestSubType } from '../types/index.js'
|
|
5
4
|
import { pluginLoader } from '../core/index.js'
|
|
6
5
|
/**
|
|
7
6
|
* 请求事件
|
|
@@ -85,19 +84,19 @@ export default class RequestHandler extends EventHandler {
|
|
|
85
84
|
raw_message () {
|
|
86
85
|
switch (this.e.sub_event) {
|
|
87
86
|
/** 好友申请 */
|
|
88
|
-
case RequestSubType.PrivateApply
|
|
87
|
+
case 'private_apply' /* RequestSubType.PrivateApply */: {
|
|
89
88
|
const { applier_uid, applier_uin, message } = this.e.content
|
|
90
89
|
this.e.raw_message = `[好友申请]: ${applier_uid || applier_uin} 申请理由: ${message}`
|
|
91
90
|
break
|
|
92
91
|
}
|
|
93
92
|
/** 群申请 */
|
|
94
|
-
case RequestSubType.GroupApply
|
|
93
|
+
case 'group_apply' /* RequestSubType.GroupApply */: {
|
|
95
94
|
const { group_id, applier_uid, applier_uin, inviter_uid, inviter_uin, reason } = this.e.content
|
|
96
95
|
this.e.raw_message = `[群申请]: ${group_id} 申请人: ${applier_uid || applier_uin} 邀请人: ${inviter_uid || inviter_uin} 理由: ${reason}`
|
|
97
96
|
break
|
|
98
97
|
}
|
|
99
98
|
/** 邀请入群 */
|
|
100
|
-
case RequestSubType.InvitedGroup
|
|
99
|
+
case 'invited_group' /* RequestSubType.InvitedGroup */: {
|
|
101
100
|
const { group_id, inviter_uid, inviter_uin } = this.e.content
|
|
102
101
|
this.e.raw_message = `[邀请入群]: ${group_id} 邀请人: ${inviter_uid || inviter_uin}`
|
|
103
102
|
break
|
|
@@ -1,13 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* - 事件来源枚举
|
|
4
|
-
*/
|
|
5
|
-
export var Scene;
|
|
6
|
-
(function (Scene) {
|
|
7
|
-
Scene["Group"] = "group";
|
|
8
|
-
Scene["Private"] = "friend";
|
|
9
|
-
Scene["Guild"] = "guild";
|
|
10
|
-
Scene["Nearby"] = "nearby";
|
|
11
|
-
Scene["Stranger"] = "stranger";
|
|
12
|
-
Scene["StrangerFromGroup"] = "stranger_from_group";
|
|
13
|
-
})(Scene || (Scene = {}));
|
|
1
|
+
export {};
|