node-karin 0.12.0 → 0.12.2-5.pr.206.027f2f2
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/CHANGELOG.md +1029 -0
- package/default/comment/config.json +34 -0
- package/default/comment/friendDirect.json +10 -0
- package/default/comment/groupGuild.json +11 -0
- package/default/comment/server.json +17 -0
- package/default/config/adapter.json +28 -0
- package/default/config/config.json +47 -0
- package/default/config/groups.json +47 -0
- package/default/config/groups.yaml +70 -0
- package/default/config/pm2.json +16 -0
- package/default/config/privates.json +23 -0
- package/default/config/privates.yaml +31 -0
- package/default/config/redis.json +10 -0
- package/default/config/render.json +19 -0
- package/default/view/group.yaml +73 -0
- package/dist/index.d.ts +9869 -0
- package/dist/index.js +12643 -0
- package/dist/module/art-template.cjs +11 -0
- package/dist/module/art-template.d.ts +1 -0
- package/dist/module/axios.cjs +22 -0
- package/dist/module/axios.d.ts +2 -0
- package/dist/module/chalk.cjs +22 -0
- package/dist/module/chalk.d.ts +2 -0
- package/dist/module/chokidar.cjs +22 -0
- package/dist/module/chokidar.d.ts +2 -0
- package/dist/module/commander.cjs +35 -0
- package/dist/module/commander.d.ts +3 -0
- package/dist/module/commander.js +3 -0
- package/dist/module/dotenv.cjs +22 -0
- package/dist/module/dotenv.d.ts +2 -0
- package/dist/module/dotenv.js +2 -0
- package/dist/module/express.cjs +112 -0
- package/dist/module/express.d.ts +1 -0
- package/dist/module/express.js +1 -0
- package/dist/module/level.cjs +22 -0
- package/dist/module/level.d.ts +2 -0
- package/dist/module/lodash.cjs +11 -0
- package/dist/module/lodash.d.ts +1 -0
- package/dist/module/log4js.cjs +22 -0
- package/dist/module/log4js.d.ts +2 -0
- package/dist/module/moment.cjs +11 -0
- package/dist/module/moment.d.ts +1 -0
- package/dist/module/node-schedule.cjs +22 -0
- package/dist/module/node-schedule.d.ts +2 -0
- package/dist/module/redis.cjs +22 -0
- package/dist/module/redis.d.ts +2 -0
- package/dist/module/ws.cjs +28 -0
- package/dist/module/ws.d.ts +1 -0
- package/dist/module/ws.js +1 -0
- package/dist/module/yaml.cjs +22 -0
- package/dist/module/yaml.d.ts +2 -0
- package/dist/root.d.ts +40 -0
- package/dist/root.js +44 -0
- package/package.json +142 -128
- package/LICENSE +0 -674
- package/README.md +0 -56
- package/config/defSet/App.yaml +0 -42
- package/config/defSet/config.yaml +0 -65
- package/config/defSet/group.yaml +0 -56
- package/config/defSet/pm2.yaml +0 -21
- package/config/defSet/redis.yaml +0 -18
- package/config/defSet/server.yaml +0 -42
- package/config/view/group.yaml +0 -92
- package/lib/adapter/index.d.ts +0 -2
- package/lib/adapter/index.js +0 -2
- package/lib/adapter/input/index.d.ts +0 -78
- package/lib/adapter/input/index.js +0 -205
- package/lib/adapter/onebot/11/convert.d.ts +0 -12
- package/lib/adapter/onebot/11/convert.js +0 -167
- package/lib/adapter/onebot/11/event.d.ts +0 -25
- package/lib/adapter/onebot/11/event.js +0 -442
- package/lib/adapter/onebot/11/index.d.ts +0 -508
- package/lib/adapter/onebot/11/index.js +0 -1047
- package/lib/cli/index.d.ts +0 -92
- package/lib/cli/index.js +0 -307
- package/lib/cli/init.d.ts +0 -2
- package/lib/cli/init.js +0 -22
- package/lib/cli/karin.d.ts +0 -2
- package/lib/cli/karin.js +0 -16
- package/lib/cli/pkg.d.ts +0 -4
- package/lib/cli/pkg.js +0 -14
- package/lib/cli/start.d.ts +0 -1
- package/lib/cli/start.js +0 -8
- package/lib/core/index.d.ts +0 -10
- package/lib/core/index.js +0 -10
- package/lib/core/init/config.d.ts +0 -43
- package/lib/core/init/config.js +0 -201
- package/lib/core/init/dir.d.ts +0 -4
- package/lib/core/init/dir.js +0 -7
- package/lib/core/init/init.d.ts +0 -1
- package/lib/core/init/init.js +0 -47
- package/lib/core/karin/karin.d.ts +0 -198
- package/lib/core/karin/karin.js +0 -226
- package/lib/core/listener/listener.d.ts +0 -145
- package/lib/core/listener/listener.js +0 -235
- package/lib/core/plugin/base.d.ts +0 -156
- package/lib/core/plugin/base.js +0 -131
- package/lib/core/plugin/loader.d.ts +0 -141
- package/lib/core/plugin/loader.js +0 -618
- package/lib/core/process/process.d.ts +0 -18
- package/lib/core/process/process.js +0 -96
- package/lib/core/server/server.d.ts +0 -25
- package/lib/core/server/server.js +0 -295
- package/lib/db/index.d.ts +0 -2
- package/lib/db/index.js +0 -2
- package/lib/db/level/level.d.ts +0 -19
- package/lib/db/level/level.js +0 -36
- package/lib/db/redis/redis.d.ts +0 -2
- package/lib/db/redis/redis.js +0 -135
- package/lib/db/redis/redis_level.d.ts +0 -112
- package/lib/db/redis/redis_level.js +0 -281
- package/lib/event/handler/base.d.ts +0 -42
- package/lib/event/handler/base.js +0 -200
- package/lib/event/handler/message.d.ts +0 -29
- package/lib/event/handler/message.js +0 -307
- package/lib/event/handler/notice.d.ts +0 -18
- package/lib/event/handler/notice.js +0 -214
- package/lib/event/handler/request.d.ts +0 -18
- package/lib/event/handler/request.js +0 -115
- package/lib/event/handler/review.d.ts +0 -55
- package/lib/event/handler/review.js +0 -386
- package/lib/event/index.d.ts +0 -5
- package/lib/event/index.js +0 -5
- package/lib/index.d.ts +0 -8
- package/lib/index.js +0 -8
- package/lib/modules/art-template.d.ts +0 -1
- package/lib/modules/axios.d.ts +0 -2
- package/lib/modules/chalk.d.ts +0 -2
- package/lib/modules/chokidar.d.ts +0 -2
- package/lib/modules/commander.d.ts +0 -2
- package/lib/modules/commander.js +0 -2
- package/lib/modules/express.d.ts +0 -3
- package/lib/modules/express.js +0 -3
- package/lib/modules/level.d.ts +0 -2
- package/lib/modules/lodash.d.ts +0 -1
- package/lib/modules/log4js.d.ts +0 -2
- package/lib/modules/moment.d.ts +0 -1
- package/lib/modules/node-schedule.d.ts +0 -2
- package/lib/modules/redis.d.ts +0 -2
- package/lib/modules/ws.d.ts +0 -3
- package/lib/modules/ws.js +0 -3
- package/lib/modules/yaml.d.ts +0 -2
- package/lib/modules.d.ts +0 -15
- package/lib/modules.js +0 -15
- package/lib/render/app.d.ts +0 -56
- package/lib/render/app.js +0 -120
- package/lib/render/base.d.ts +0 -30
- package/lib/render/base.js +0 -69
- package/lib/render/client.d.ts +0 -41
- package/lib/render/client.js +0 -238
- package/lib/render/http.d.ts +0 -19
- package/lib/render/http.js +0 -50
- package/lib/render/index.d.ts +0 -6
- package/lib/render/index.js +0 -6
- package/lib/render/server.d.ts +0 -25
- package/lib/render/server.js +0 -101
- package/lib/render/wormhole.d.ts +0 -1
- package/lib/render/wormhole.js +0 -156
- package/lib/types/adapter/api.d.ts +0 -399
- package/lib/types/adapter/api.js +0 -1
- package/lib/types/adapter/base.d.ts +0 -560
- package/lib/types/adapter/base.js +0 -1
- package/lib/types/config/config.d.ts +0 -379
- package/lib/types/config/config.js +0 -1
- package/lib/types/element/element.d.ts +0 -565
- package/lib/types/element/element.js +0 -1
- package/lib/types/element/qqbot.d.ts +0 -123
- package/lib/types/element/qqbot.js +0 -1
- package/lib/types/event/contact.d.ts +0 -28
- package/lib/types/event/contact.js +0 -1
- package/lib/types/event/event.d.ts +0 -305
- package/lib/types/event/event.js +0 -1
- package/lib/types/event/index.d.ts +0 -12
- package/lib/types/event/index.js +0 -7
- package/lib/types/event/message.d.ts +0 -109
- package/lib/types/event/message.js +0 -74
- package/lib/types/event/notice.d.ts +0 -513
- package/lib/types/event/notice.js +0 -52
- package/lib/types/event/reply.d.ts +0 -50
- package/lib/types/event/reply.js +0 -1
- package/lib/types/event/request.d.ts +0 -126
- package/lib/types/event/request.js +0 -52
- package/lib/types/event/sender.d.ts +0 -44
- package/lib/types/event/sender.js +0 -1
- package/lib/types/index.d.ts +0 -13
- package/lib/types/index.js +0 -13
- package/lib/types/logger/logger.d.ts +0 -110
- package/lib/types/logger/logger.js +0 -1
- package/lib/types/onebot11/api.d.ts +0 -53
- package/lib/types/onebot11/api.js +0 -1
- package/lib/types/onebot11/event.d.ts +0 -619
- package/lib/types/onebot11/event.js +0 -2
- package/lib/types/onebot11/index.d.ts +0 -6
- package/lib/types/onebot11/index.js +0 -6
- package/lib/types/onebot11/params.d.ts +0 -609
- package/lib/types/onebot11/params.js +0 -1
- package/lib/types/onebot11/response.d.ts +0 -516
- package/lib/types/onebot11/response.js +0 -1
- package/lib/types/onebot11/segment.d.ts +0 -269
- package/lib/types/onebot11/segment.js +0 -1
- package/lib/types/onebot11/sender.d.ts +0 -59
- package/lib/types/onebot11/sender.js +0 -1
- package/lib/types/plugin/app.d.ts +0 -71
- package/lib/types/plugin/app.js +0 -1
- package/lib/types/plugin/plugin.d.ts +0 -473
- package/lib/types/plugin/plugin.js +0 -1
- package/lib/types/render/render.d.ts +0 -118
- package/lib/types/render/render.js +0 -1
- package/lib/types/type/global.d.ts +0 -25
- package/lib/types/type/global.js +0 -1
- package/lib/utils/common/common.d.ts +0 -236
- package/lib/utils/common/common.js +0 -708
- package/lib/utils/config/config.d.ts +0 -193
- package/lib/utils/config/config.js +0 -328
- package/lib/utils/config/updateVersion.d.ts +0 -33
- package/lib/utils/config/updateVersion.js +0 -145
- package/lib/utils/config/yamlEditor.d.ts +0 -101
- package/lib/utils/config/yamlEditor.js +0 -330
- package/lib/utils/core/handler.d.ts +0 -18
- package/lib/utils/core/handler.js +0 -46
- package/lib/utils/core/logger.d.ts +0 -3
- package/lib/utils/core/logger.js +0 -105
- package/lib/utils/core/segment.d.ts +0 -279
- package/lib/utils/core/segment.js +0 -451
- package/lib/utils/index.d.ts +0 -13
- package/lib/utils/index.js +0 -13
- package/lib/utils/tools/button.d.ts +0 -2
- package/lib/utils/tools/button.js +0 -27
- package/lib/utils/tools/exec.d.ts +0 -20
- package/lib/utils/tools/exec.js +0 -54
- package/lib/utils/tools/ffmpeg.d.ts +0 -12
- package/lib/utils/tools/ffmpeg.js +0 -25
- package/lib/utils/tools/restart.d.ts +0 -15
- package/lib/utils/tools/restart.js +0 -39
- package/lib/utils/tools/stop.d.ts +0 -7
- package/lib/utils/tools/stop.js +0 -13
- package/lib/utils/tools/update.d.ts +0 -67
- package/lib/utils/tools/update.js +0 -151
- /package/{config → default}/view/App.yaml +0 -0
- /package/{config → default}/view/config.yaml +0 -0
- /package/{config → default}/view/pm2.yaml +0 -0
- /package/{config → default}/view/redis.yaml +0 -0
- /package/{config → default}/view/server.yaml +0 -0
- /package/{lib/modules → dist/module}/art-template.js +0 -0
- /package/{lib/modules → dist/module}/axios.js +0 -0
- /package/{lib/modules → dist/module}/chalk.js +0 -0
- /package/{lib/modules → dist/module}/chokidar.js +0 -0
- /package/{lib/modules → dist/module}/level.js +0 -0
- /package/{lib/modules → dist/module}/lodash.js +0 -0
- /package/{lib/modules → dist/module}/log4js.js +0 -0
- /package/{lib/modules → dist/module}/moment.js +0 -0
- /package/{lib/modules → dist/module}/node-schedule.js +0 -0
- /package/{lib/modules → dist/module}/redis.js +0 -0
- /package/{lib/modules → dist/module}/yaml.js +0 -0
package/lib/utils/index.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export * from './tools/button.js';
|
|
2
|
-
export * from './common/common.js';
|
|
3
|
-
export * from './config/config.js';
|
|
4
|
-
export * from './tools/ffmpeg.js';
|
|
5
|
-
export * from './core/handler.js';
|
|
6
|
-
export * from './tools/exec.js';
|
|
7
|
-
export * from './core/segment.js';
|
|
8
|
-
export * from './tools/update.js';
|
|
9
|
-
export * from './config/yamlEditor.js';
|
|
10
|
-
export * from './core/logger.js';
|
|
11
|
-
export * from './config/updateVersion.js';
|
|
12
|
-
export * from './tools/restart.js';
|
|
13
|
-
export * from './tools/stop.js';
|
package/lib/utils/index.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export * from './tools/button.js';
|
|
2
|
-
export * from './common/common.js';
|
|
3
|
-
export * from './config/config.js';
|
|
4
|
-
export * from './tools/ffmpeg.js';
|
|
5
|
-
export * from './core/handler.js';
|
|
6
|
-
export * from './tools/exec.js';
|
|
7
|
-
export * from './core/segment.js';
|
|
8
|
-
export * from './tools/update.js';
|
|
9
|
-
export * from './config/yamlEditor.js';
|
|
10
|
-
export * from './core/logger.js';
|
|
11
|
-
export * from './config/updateVersion.js';
|
|
12
|
-
export * from './tools/restart.js';
|
|
13
|
-
export * from './tools/stop.js';
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import logger from '../core/logger.js';
|
|
2
|
-
import { pluginLoader as loader } from '../../core/index.js';
|
|
3
|
-
export const button = async (msg, e) => {
|
|
4
|
-
const button = [];
|
|
5
|
-
for (const info of loader.button) {
|
|
6
|
-
const reg = info.reg;
|
|
7
|
-
if (reg.test(msg)) {
|
|
8
|
-
try {
|
|
9
|
-
let done = true;
|
|
10
|
-
/**
|
|
11
|
-
* 标记函数 如果调用则继续执行 循环下一个按钮插件处理
|
|
12
|
-
*/
|
|
13
|
-
const reject = () => { done = false; };
|
|
14
|
-
const res = await info.fn(reject, e);
|
|
15
|
-
if (res)
|
|
16
|
-
button.push(res);
|
|
17
|
-
if (done)
|
|
18
|
-
return res;
|
|
19
|
-
}
|
|
20
|
-
catch (error) {
|
|
21
|
-
logger.error(error);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
/** 理论上不会走到这里,但是还是要稳一手,不排除有所有插件都false... */
|
|
26
|
-
return button;
|
|
27
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { ExecOptions } from 'child_process';
|
|
2
|
-
/**
|
|
3
|
-
* 执行 shell 命令
|
|
4
|
-
* @param cmd 命令
|
|
5
|
-
* @param log 是否打印日志
|
|
6
|
-
* @param options 选项
|
|
7
|
-
*/
|
|
8
|
-
export declare const exec: (cmd: string, log?: boolean, options?: ExecOptions) => Promise<{
|
|
9
|
-
status: "ok" | "failed";
|
|
10
|
-
error: Error | null;
|
|
11
|
-
stdout: string;
|
|
12
|
-
stderr: string;
|
|
13
|
-
}>;
|
|
14
|
-
/**
|
|
15
|
-
* 执行 shell 命令
|
|
16
|
-
* @param cmd 命令
|
|
17
|
-
* @param options 选项
|
|
18
|
-
*/
|
|
19
|
-
export declare const execs: (cmd: string, options?: ExecOptions) => Promise<string>;
|
|
20
|
-
export default exec;
|
package/lib/utils/tools/exec.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import logger from '../core/logger.js';
|
|
2
|
-
import { exec as execCmd } from 'child_process';
|
|
3
|
-
/**
|
|
4
|
-
* 执行 shell 命令
|
|
5
|
-
* @param cmd 命令
|
|
6
|
-
* @param log 是否打印日志
|
|
7
|
-
* @param options 选项
|
|
8
|
-
*/
|
|
9
|
-
export const exec = async (cmd, log = true, options = { cwd: process.cwd() }) => {
|
|
10
|
-
const logType = (status) => ({
|
|
11
|
-
start: '[exec][开始执行]',
|
|
12
|
-
ok: '[exec][执行成功]',
|
|
13
|
-
failed: '[exec][执行失败]',
|
|
14
|
-
})[status];
|
|
15
|
-
const logMessage = (status, details = '') => {
|
|
16
|
-
if (log) {
|
|
17
|
-
const colorFunc = {
|
|
18
|
-
start: logger.yellow,
|
|
19
|
-
ok: logger.green,
|
|
20
|
-
failed: logger.red,
|
|
21
|
-
}[status];
|
|
22
|
-
logger.info([
|
|
23
|
-
colorFunc(logType(status)),
|
|
24
|
-
`cmd: ${cmd}`,
|
|
25
|
-
`cwd: ${options.cwd}`,
|
|
26
|
-
details,
|
|
27
|
-
'--------',
|
|
28
|
-
].join('\n'));
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
logMessage('start');
|
|
32
|
-
return new Promise(resolve => {
|
|
33
|
-
execCmd(cmd, options, (error, stdout = '', stderr = '') => {
|
|
34
|
-
const status = error ? 'failed' : 'ok';
|
|
35
|
-
logMessage(status, error ? `Error: ${error.message}` : `stdout: ${stdout}\nstderr: ${stderr}`);
|
|
36
|
-
resolve({ status, error, stdout, stderr });
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
/**
|
|
41
|
-
* 执行 shell 命令
|
|
42
|
-
* @param cmd 命令
|
|
43
|
-
* @param options 选项
|
|
44
|
-
*/
|
|
45
|
-
export const execs = (cmd, options = { cwd: process.cwd() }) => {
|
|
46
|
-
return new Promise((resolve, reject) => {
|
|
47
|
-
execCmd(cmd, options, (error, stdout) => {
|
|
48
|
-
if (error)
|
|
49
|
-
return reject(error);
|
|
50
|
-
resolve(stdout.trim());
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
};
|
|
54
|
-
export default exec;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 执行 ffmpeg 命令
|
|
3
|
-
*/
|
|
4
|
-
export declare function ffmpeg(): Promise<false | ((cmd: string, log?: boolean, options?: {
|
|
5
|
-
cwd: string;
|
|
6
|
-
encoding: string;
|
|
7
|
-
}) => Promise<{
|
|
8
|
-
status: "ok" | "failed";
|
|
9
|
-
error: Error | null;
|
|
10
|
-
stdout: string;
|
|
11
|
-
stderr: string;
|
|
12
|
-
}>)>;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import exec from './exec.js';
|
|
2
|
-
import logger from '../core/logger.js';
|
|
3
|
-
import { config } from '../config/config.js';
|
|
4
|
-
/**
|
|
5
|
-
* 执行 ffmpeg 命令
|
|
6
|
-
*/
|
|
7
|
-
export async function ffmpeg() {
|
|
8
|
-
let ffmpeg = 'ffmpeg';
|
|
9
|
-
const { status } = await exec('ffmpeg -version', false);
|
|
10
|
-
if (status !== 'ok') {
|
|
11
|
-
logger.debug('ffmpeg 未安装,开始尝试读取配置文件是否存在ffmpeg路径');
|
|
12
|
-
const ffmpegPath = config.Config.ffmpeg_path;
|
|
13
|
-
if (!ffmpegPath) {
|
|
14
|
-
logger.warn('ffmpeg 未安装,请安装 ffmpeg 或手动配置 ffmpeg 路径后重启');
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
ffmpeg = `"${ffmpegPath}"`;
|
|
18
|
-
}
|
|
19
|
-
// 返回函数
|
|
20
|
-
return async (cmd, log = true, options = { cwd: process.cwd(), encoding: 'utf-8' }) => {
|
|
21
|
-
cmd = cmd.replace(/^ffmpeg/, '').trim();
|
|
22
|
-
cmd = `${ffmpeg} ${cmd}`;
|
|
23
|
-
return await exec(cmd, log, options);
|
|
24
|
-
};
|
|
25
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Contact } from '../../types/index.js';
|
|
2
|
-
/**
|
|
3
|
-
* 重启Bot
|
|
4
|
-
* @param self_id - 机器人的id 传e.self_id
|
|
5
|
-
* @param contact - 事件联系人信息 也就是从哪来的这条消息 传e.contact即可
|
|
6
|
-
* @param message_id - 消息id 传e.message_id
|
|
7
|
-
* @param isFront - 是否为前台重启 默认是
|
|
8
|
-
*/
|
|
9
|
-
export declare const restart: (self_id: string, contact: Contact, message_id: string, isFront?: boolean) => Promise<{
|
|
10
|
-
status: string;
|
|
11
|
-
data: string;
|
|
12
|
-
} | {
|
|
13
|
-
status: string;
|
|
14
|
-
data: Error | null;
|
|
15
|
-
}>;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import exec from './exec.js';
|
|
2
|
-
import { level } from '../../db/index.js';
|
|
3
|
-
import { config } from '../config/config.js';
|
|
4
|
-
/**
|
|
5
|
-
* 重启Bot
|
|
6
|
-
* @param self_id - 机器人的id 传e.self_id
|
|
7
|
-
* @param contact - 事件联系人信息 也就是从哪来的这条消息 传e.contact即可
|
|
8
|
-
* @param message_id - 消息id 传e.message_id
|
|
9
|
-
* @param isFront - 是否为前台重启 默认是
|
|
10
|
-
*/
|
|
11
|
-
export const restart = async (self_id, contact, message_id, isFront = true) => {
|
|
12
|
-
const options = {
|
|
13
|
-
id: self_id,
|
|
14
|
-
contact,
|
|
15
|
-
message_id,
|
|
16
|
-
time: Date.now(),
|
|
17
|
-
};
|
|
18
|
-
const key = `karin:restart:${options.id}`;
|
|
19
|
-
await level.set(key, options);
|
|
20
|
-
if (isFront) {
|
|
21
|
-
if (!process.send)
|
|
22
|
-
return { status: 'failed', data: '前台重启失败,当前环境不支持,仅支持【npx karin start】启动的环境' };
|
|
23
|
-
process.send({ action: 'result', env: process.env });
|
|
24
|
-
process.exit();
|
|
25
|
-
}
|
|
26
|
-
if (!config.Config.pm2Restart)
|
|
27
|
-
process.exit();
|
|
28
|
-
if (process.env.pm_id) {
|
|
29
|
-
const pm2 = await exec('npx karin rs');
|
|
30
|
-
if (pm2.status === 'ok')
|
|
31
|
-
process.exit();
|
|
32
|
-
return { status: 'failed', data: pm2.error };
|
|
33
|
-
}
|
|
34
|
-
/** 调用pm2启动 */
|
|
35
|
-
const pm2 = await exec('npx karin pm2');
|
|
36
|
-
if (pm2.status === 'ok')
|
|
37
|
-
process.exit();
|
|
38
|
-
return { status: 'failed', data: pm2.error };
|
|
39
|
-
};
|
package/lib/utils/tools/stop.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import exec from './exec.js';
|
|
2
|
-
/**
|
|
3
|
-
* 停止Bot
|
|
4
|
-
*/
|
|
5
|
-
export const stop = async () => {
|
|
6
|
-
if (process.env.pm_id) {
|
|
7
|
-
const pm2 = await exec('pm2 delete ' + process.env.pm_id);
|
|
8
|
-
if (pm2.status === 'ok')
|
|
9
|
-
process.exit();
|
|
10
|
-
return { status: 'failed', data: pm2.error };
|
|
11
|
-
}
|
|
12
|
-
process.exit();
|
|
13
|
-
};
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
export declare class Updates {
|
|
2
|
-
dir: string;
|
|
3
|
-
constructor();
|
|
4
|
-
/**
|
|
5
|
-
* 更新npm包
|
|
6
|
-
* @param name - 包名
|
|
7
|
-
* @param timeout - 超时时间 默认120s
|
|
8
|
-
*/
|
|
9
|
-
updatePkg(name: string, timeout?: number): Promise<{
|
|
10
|
-
status: boolean;
|
|
11
|
-
data: string;
|
|
12
|
-
}>;
|
|
13
|
-
/**
|
|
14
|
-
* 更新框架或插件
|
|
15
|
-
* @param path - 插件相对路径
|
|
16
|
-
* @param cmd - 更新命令 默认git pull
|
|
17
|
-
* @param timeout - 超时时间 默认120s
|
|
18
|
-
*/
|
|
19
|
-
update(path: string, cmd?: string, timeout?: number): Promise<{
|
|
20
|
-
status: string;
|
|
21
|
-
data: string;
|
|
22
|
-
}>;
|
|
23
|
-
/**
|
|
24
|
-
* 获取指定仓库最后一次提交时间日期
|
|
25
|
-
* @param path - 插件相对路径
|
|
26
|
-
*/
|
|
27
|
-
getTime(path: string): Promise<string>;
|
|
28
|
-
/**
|
|
29
|
-
* 获取指定仓库最后一次提交哈希值
|
|
30
|
-
* @param path - 插件相对路径
|
|
31
|
-
* @param short - 是否获取短哈希 默认true
|
|
32
|
-
*/
|
|
33
|
-
getHash(path: string, short?: boolean): Promise<string>;
|
|
34
|
-
/**
|
|
35
|
-
* 获取指定仓库的提交记录
|
|
36
|
-
*/
|
|
37
|
-
getCommit(options: {
|
|
38
|
-
/** 指令命令路径 */
|
|
39
|
-
path: string;
|
|
40
|
-
/** 获取几次提交 默认1次 */
|
|
41
|
-
count?: number;
|
|
42
|
-
/** 指定哈希 */
|
|
43
|
-
hash?: string;
|
|
44
|
-
/** 指定分支 */
|
|
45
|
-
branch?: string;
|
|
46
|
-
}): Promise<string>;
|
|
47
|
-
/**
|
|
48
|
-
* 检查插件是否有更新
|
|
49
|
-
* @param path - 插件相对路径
|
|
50
|
-
* @param time - 超时时间 默认120s
|
|
51
|
-
*/
|
|
52
|
-
checkUpdate(path: string, time?: number): Promise<{
|
|
53
|
-
status: string;
|
|
54
|
-
data: string | undefined;
|
|
55
|
-
count?: undefined;
|
|
56
|
-
} | {
|
|
57
|
-
status: string;
|
|
58
|
-
data: boolean;
|
|
59
|
-
count?: undefined;
|
|
60
|
-
} | {
|
|
61
|
-
status: string;
|
|
62
|
-
data: string;
|
|
63
|
-
count: number;
|
|
64
|
-
}>;
|
|
65
|
-
}
|
|
66
|
-
export declare const update: Updates;
|
|
67
|
-
export declare const Update: Updates;
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import exec from './exec.js';
|
|
3
|
-
import { KarinCli } from '../../cli/index.js';
|
|
4
|
-
import { getRegistry } from '../../cli/pkg.js';
|
|
5
|
-
export class Updates {
|
|
6
|
-
dir;
|
|
7
|
-
constructor() {
|
|
8
|
-
this.dir = './plugins';
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* 更新npm包
|
|
12
|
-
* @param name - 包名
|
|
13
|
-
* @param timeout - 超时时间 默认120s
|
|
14
|
-
*/
|
|
15
|
-
async updatePkg(name, timeout = 120) {
|
|
16
|
-
const pkg = getRegistry();
|
|
17
|
-
const cmd = (pkg === 'yarn' ? 'yarn upgrade' : `${pkg} update`) + `${name}@latest`;
|
|
18
|
-
/** 检查是否已经是最新版本 */
|
|
19
|
-
const tools = new KarinCli();
|
|
20
|
-
const local = await tools.getLocalVersion(name, pkg);
|
|
21
|
-
const remote = await tools.getRemoteVersion(name, pkg);
|
|
22
|
-
logger.info(`[依赖更新] ${name} 当前版本: ${local} 最新版本: ${remote}`);
|
|
23
|
-
if (local === remote)
|
|
24
|
-
return { status: true, data: `${name} 已经是最新版本~` };
|
|
25
|
-
const npm = await exec(cmd, true, { cwd: process.cwd(), timeout: timeout * 1000 });
|
|
26
|
-
if (npm.status === 'ok')
|
|
27
|
-
return { status: true, data: `${name} 更新完成~` };
|
|
28
|
-
return { status: false, data: `${name} 更新失败: ${npm.error?.message}` };
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* 更新框架或插件
|
|
32
|
-
* @param path - 插件相对路径
|
|
33
|
-
* @param cmd - 更新命令 默认git pull
|
|
34
|
-
* @param timeout - 超时时间 默认120s
|
|
35
|
-
*/
|
|
36
|
-
async update(path, cmd = 'git pull', timeout = 120) {
|
|
37
|
-
/** 检查一下路径是否存在 */
|
|
38
|
-
if (!fs.existsSync(path))
|
|
39
|
-
return { status: 'failed', data: '路径不存在' };
|
|
40
|
-
/** 检查是否有.git文件夹 */
|
|
41
|
-
if (!fs.existsSync(`${path}/.git`))
|
|
42
|
-
return { status: 'failed', data: '该路径不是一个git仓库' };
|
|
43
|
-
/** 设置超时时间 */
|
|
44
|
-
const timer = setTimeout(() => {
|
|
45
|
-
return { status: 'failed', data: '执行超时' };
|
|
46
|
-
}, timeout * 1000);
|
|
47
|
-
const options = { env: process.env, cwd: path, encoding: 'utf-8' };
|
|
48
|
-
/** 记录当前短哈希 */
|
|
49
|
-
const hash = await this.getHash(path);
|
|
50
|
-
/** 执行更新 */
|
|
51
|
-
const { status, error } = await exec(cmd, true, options);
|
|
52
|
-
/** 执行成功 */
|
|
53
|
-
if (status === 'ok') {
|
|
54
|
-
clearTimeout(timer);
|
|
55
|
-
/** 再次获取短哈希 查看是否有更新 */
|
|
56
|
-
const newHash = await this.getHash(path);
|
|
57
|
-
if (hash === newHash) {
|
|
58
|
-
const time = await this.getTime(path);
|
|
59
|
-
return {
|
|
60
|
-
status: 'ok',
|
|
61
|
-
data: `\n当前版本已是最新版本\n最后更新时间:${time}\n更新详情:${await this.getCommit({ path, count: 1 })}`,
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
const Commit = await this.getCommit({ path, hash });
|
|
65
|
-
return {
|
|
66
|
-
status: 'ok',
|
|
67
|
-
data: `\n更新成功\n更新日志:\n${Commit}`,
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
const data = `\n更新失败\n错误信息:${error?.stack?.toString() || error?.message?.toString() || error?.toString() || error}\n请解决错误后重试或执行【#强制更新】`;
|
|
71
|
-
return { status: 'failed', data };
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* 获取指定仓库最后一次提交时间日期
|
|
75
|
-
* @param path - 插件相对路径
|
|
76
|
-
*/
|
|
77
|
-
async getTime(path) {
|
|
78
|
-
const cmd = 'git log -1 --format=%cd --date=format:"%Y-%m-%d %H:%M:%S"';
|
|
79
|
-
const data = await exec(cmd, false, { cwd: path });
|
|
80
|
-
if (data.status === 'failed')
|
|
81
|
-
return '获取时间失败,请重试或更新Git~';
|
|
82
|
-
return data.stdout.trim();
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* 获取指定仓库最后一次提交哈希值
|
|
86
|
-
* @param path - 插件相对路径
|
|
87
|
-
* @param short - 是否获取短哈希 默认true
|
|
88
|
-
*/
|
|
89
|
-
async getHash(path, short = true) {
|
|
90
|
-
const cmd = short ? 'git rev-parse --short HEAD' : 'git rev-parse HEAD';
|
|
91
|
-
const data = await exec(cmd, false, { cwd: path });
|
|
92
|
-
if (data.status === 'failed') {
|
|
93
|
-
const text = data.error;
|
|
94
|
-
throw new Error(text);
|
|
95
|
-
}
|
|
96
|
-
return data.stdout.trim();
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* 获取指定仓库的提交记录
|
|
100
|
-
*/
|
|
101
|
-
async getCommit(options) {
|
|
102
|
-
const { path, count = 1, hash, branch } = options;
|
|
103
|
-
let cmd = `git log -${count} --format="[%ad]%s %n" --date="format:%m-%d %H:%M"`;
|
|
104
|
-
/** 键入HEAD */
|
|
105
|
-
if (hash)
|
|
106
|
-
cmd = `git log ${hash}..HEAD --format="[%ad] %s %n" --date="format:%m-%d %H:%M"`;
|
|
107
|
-
/** 指定分支 */
|
|
108
|
-
if (branch)
|
|
109
|
-
cmd = `git log -${count} ${branch} --format="[%ad] %s %n" --date="format:%m-%d %H:%M"`;
|
|
110
|
-
const data = await exec(cmd, false, { cwd: path });
|
|
111
|
-
if (data.status === 'failed') {
|
|
112
|
-
const text = data.error;
|
|
113
|
-
throw new Error(text);
|
|
114
|
-
}
|
|
115
|
-
return data.stdout.trim();
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* 检查插件是否有更新
|
|
119
|
-
* @param path - 插件相对路径
|
|
120
|
-
* @param time - 超时时间 默认120s
|
|
121
|
-
*/
|
|
122
|
-
async checkUpdate(path, time = 120) {
|
|
123
|
-
/** 检查一下路径是否存在 */
|
|
124
|
-
if (!fs.existsSync(path))
|
|
125
|
-
return { status: 'failed', data: '路径不存在' };
|
|
126
|
-
/** 检查是否有.git文件夹 */
|
|
127
|
-
if (!fs.existsSync(`${path}/.git`))
|
|
128
|
-
return { status: 'failed', data: '该路径不是一个git仓库' };
|
|
129
|
-
/** 设置超时时间 */
|
|
130
|
-
const timer = setTimeout(() => {
|
|
131
|
-
return { status: 'failed', data: '执行超时' };
|
|
132
|
-
}, time * 1000);
|
|
133
|
-
const options = { env: process.env, cwd: path, encoding: 'utf-8' };
|
|
134
|
-
/** git fetch origin */
|
|
135
|
-
const { status, error } = await exec('git fetch origin', false, options);
|
|
136
|
-
if (status === 'failed')
|
|
137
|
-
return { status: 'failed', data: error?.message };
|
|
138
|
-
/** git status -uno */
|
|
139
|
-
const { stdout } = await exec('git status -uno', false, options);
|
|
140
|
-
clearTimeout(timer);
|
|
141
|
-
/** 检查是否有更新 没更新直接返回 */
|
|
142
|
-
if (stdout.includes('Your branch is up to date with'))
|
|
143
|
-
return { status: 'ok', data: false };
|
|
144
|
-
/** 获取落后几次更新 */
|
|
145
|
-
const count = Number(stdout.match(/Your branch is behind '.*' by (\d+) commits/)?.[1]) || 1;
|
|
146
|
-
const data = await this.getCommit({ path, count, branch: 'origin' });
|
|
147
|
-
return { status: 'ok', data, count };
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
export const update = new Updates();
|
|
151
|
-
export const Update = update;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|