node-karin 0.2.0 → 0.2.1
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/config/defSet/config.yaml +3 -0
- package/lib/adapter/onebot/onebot11.d.ts +4 -6
- package/lib/adapter/onebot/onebot11.js +3 -8
- package/lib/core/index.d.ts +9 -0
- package/lib/core/index.js +9 -0
- package/lib/core/init.d.ts +1 -0
- package/lib/core/init.js +20 -2
- package/lib/core/karin.d.ts +2 -4
- package/lib/core/karin.js +2 -2
- package/lib/core/listener.d.ts +2 -5
- package/lib/core/listener.js +9 -11
- package/lib/core/plugin.app.d.ts +1 -1
- package/lib/core/plugin.d.ts +2 -4
- package/lib/core/plugin.js +1 -1
- package/lib/core/plugin.loader.d.ts +6 -7
- package/lib/core/plugin.loader.js +13 -16
- package/lib/core/process.d.ts +18 -0
- package/lib/core/process.js +98 -0
- package/lib/core/server.d.ts +4 -5
- package/lib/core/server.js +11 -13
- package/lib/db/index.d.ts +4 -0
- package/lib/db/index.js +4 -0
- package/lib/db/level.d.ts +1 -3
- package/lib/db/level.js +1 -3
- package/lib/db/redis.js +1 -2
- package/lib/event/event.d.ts +1 -3
- package/lib/event/event.handler.d.ts +1 -2
- package/lib/event/event.handler.js +13 -16
- package/lib/event/index.d.ts +7 -0
- package/lib/event/index.js +9 -0
- package/lib/event/message.d.ts +1 -2
- package/lib/event/message.handler.d.ts +1 -1
- package/lib/event/message.handler.js +12 -15
- package/lib/event/notice.d.ts +1 -1
- package/lib/event/request.d.ts +1 -1
- package/lib/event/review.handler.d.ts +12 -15
- package/lib/event/review.handler.js +6 -7
- package/lib/index.d.ts +152 -26
- package/lib/index.js +24 -37
- package/lib/modules.d.ts +14 -0
- package/lib/modules.js +14 -0
- package/lib/renderer/app.d.ts +14 -21
- package/lib/renderer/app.js +12 -11
- package/lib/renderer/base.d.ts +1 -1
- package/lib/renderer/base.js +2 -3
- package/lib/renderer/client.d.ts +2 -2
- package/lib/renderer/client.js +7 -8
- package/lib/renderer/http.d.ts +2 -2
- package/lib/renderer/http.js +2 -2
- package/lib/renderer/index.d.ts +6 -0
- package/lib/renderer/index.js +6 -0
- package/lib/renderer/server.d.ts +4 -4
- package/lib/renderer/server.js +7 -7
- package/lib/renderer/wormhole.d.ts +1 -1
- package/lib/renderer/wormhole.js +7 -7
- package/lib/types/adapter.d.ts +1 -1
- package/lib/types/config.d.ts +9 -3
- package/lib/types/{types.d.ts → event.d.ts} +1 -3
- package/lib/types/index.d.ts +3 -2
- package/lib/types/index.js +3 -2
- package/lib/types/plugin.d.ts +6 -6
- package/lib/utils/button.d.ts +8 -9
- package/lib/utils/button.js +1 -1
- package/lib/utils/common.d.ts +10 -5
- package/lib/utils/common.js +20 -8
- package/lib/utils/config.d.ts +6 -5
- package/lib/utils/config.js +6 -6
- package/lib/utils/ffmpeg.js +2 -2
- package/lib/utils/handler.d.ts +3 -4
- package/lib/utils/handler.js +1 -1
- package/lib/utils/index.d.ts +11 -0
- package/lib/utils/index.js +11 -0
- package/lib/utils/logger.d.ts +1 -1
- package/lib/utils/logger.js +4 -4
- package/lib/utils/segment.d.ts +2 -3
- package/lib/utils/segment.js +1 -1
- package/lib/utils/update.d.ts +1 -2
- package/lib/utils/update.js +1 -1
- package/package.json +2 -2
- /package/lib/types/{types.js → event.js} +0 -0
- /package/lib/utils/{YamlEditor.d.ts → yamlEditor.d.ts} +0 -0
- /package/lib/utils/{YamlEditor.js → yamlEditor.js} +0 -0
package/lib/renderer/app.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import logger from '../utils/
|
|
2
|
-
|
|
3
|
-
* 渲染器管理器
|
|
4
|
-
*/
|
|
5
|
-
export default new (class Renderer {
|
|
1
|
+
import { logger } from '../utils/index.js'
|
|
2
|
+
class Renderer {
|
|
6
3
|
index
|
|
7
4
|
Apps
|
|
8
5
|
constructor () {
|
|
@@ -17,11 +14,11 @@ export default new (class Renderer {
|
|
|
17
14
|
|
|
18
15
|
/**
|
|
19
16
|
* 注册渲染器
|
|
20
|
-
* @param
|
|
21
|
-
* @param
|
|
22
|
-
* @param
|
|
23
|
-
* @param
|
|
24
|
-
* @returns
|
|
17
|
+
* @param data 渲染器数据
|
|
18
|
+
* @param data.id 渲染器ID
|
|
19
|
+
* @param data.type 渲染器类型
|
|
20
|
+
* @param ata.render 渲染器标准方法
|
|
21
|
+
* @returns 渲染器索引
|
|
25
22
|
*/
|
|
26
23
|
app (data) {
|
|
27
24
|
this.index++
|
|
@@ -90,4 +87,8 @@ export default new (class Renderer {
|
|
|
90
87
|
},
|
|
91
88
|
})
|
|
92
89
|
}
|
|
93
|
-
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* 渲染器管理器
|
|
93
|
+
*/
|
|
94
|
+
export const render = new Renderer()
|
package/lib/renderer/base.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { KarinRender, KarinRenderType } from '../types/render.js';
|
|
|
3
3
|
/**
|
|
4
4
|
* 渲染器基类 所有渲染器都应该继承这个类
|
|
5
5
|
*/
|
|
6
|
-
export
|
|
6
|
+
export declare class RenderBase implements KarinRender {
|
|
7
7
|
dir: './temp/html';
|
|
8
8
|
html: {
|
|
9
9
|
[key: string]: string;
|
package/lib/renderer/base.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import fs from 'fs'
|
|
2
2
|
import chokidar from 'chokidar'
|
|
3
3
|
import template from 'art-template'
|
|
4
|
-
import common from '../utils/
|
|
5
|
-
import logger from '../utils/logger.js'
|
|
4
|
+
import { common, logger } from '../utils/index.js'
|
|
6
5
|
/**
|
|
7
6
|
* 渲染器基类 所有渲染器都应该继承这个类
|
|
8
7
|
*/
|
|
9
|
-
export
|
|
8
|
+
export class RenderBase {
|
|
10
9
|
dir
|
|
11
10
|
html
|
|
12
11
|
watcher
|
package/lib/renderer/client.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import WebSocket from 'ws';
|
|
2
|
-
import RenderBase from './base.js';
|
|
2
|
+
import { RenderBase } from './base.js';
|
|
3
3
|
import { KarinRenderType } from '../types/render.js';
|
|
4
|
-
export
|
|
4
|
+
export declare class RenderClient extends RenderBase {
|
|
5
5
|
url: string;
|
|
6
6
|
type: string;
|
|
7
7
|
id: string;
|
package/lib/renderer/client.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import fs from 'fs'
|
|
2
2
|
import WebSocket from 'ws'
|
|
3
|
-
import
|
|
4
|
-
import RenderBase from './base.js'
|
|
3
|
+
import { render } from './app.js'
|
|
4
|
+
import { RenderBase } from './base.js'
|
|
5
5
|
import { randomUUID } from 'crypto'
|
|
6
|
-
import
|
|
7
|
-
import logger from '../utils/
|
|
8
|
-
|
|
9
|
-
export default class RenderClient extends RenderBase {
|
|
6
|
+
import { listener } from '../core/index.js'
|
|
7
|
+
import { common, logger } from '../utils/index.js'
|
|
8
|
+
export class RenderClient extends RenderBase {
|
|
10
9
|
url
|
|
11
10
|
type
|
|
12
11
|
id
|
|
@@ -35,7 +34,7 @@ export default class RenderClient extends RenderBase {
|
|
|
35
34
|
logger.mark(`[渲染器:${this.id}][WebSocket] 建立连接:${logger.green(this.url)}`)
|
|
36
35
|
/** 注册渲染器 */
|
|
37
36
|
try {
|
|
38
|
-
this.index =
|
|
37
|
+
this.index = render.app({ id: this.id, type: this.type, render: this.render.bind(this) })
|
|
39
38
|
this.retry = 0
|
|
40
39
|
} catch (error) {
|
|
41
40
|
logger.error(`[渲染器:${this.id}] 注册渲染器失败:`, error)
|
|
@@ -53,7 +52,7 @@ export default class RenderClient extends RenderBase {
|
|
|
53
52
|
/** 停止监听 */
|
|
54
53
|
this.ws.removeAllListeners()
|
|
55
54
|
/** 卸载渲染器 */
|
|
56
|
-
this.index &&
|
|
55
|
+
this.index && render.unapp(this.index) && (this.index = 0)
|
|
57
56
|
logger.warn(`[渲染器:${this.id}][重连次数:${this.retry}] 连接断开,5秒后将尝试重连:${this.url}`)
|
|
58
57
|
await common.sleep(5000)
|
|
59
58
|
await this.start()
|
package/lib/renderer/http.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import RenderBase from './base.js';
|
|
1
|
+
import { RenderBase } from './base.js';
|
|
2
2
|
import { KarinRenderType } from '../types/render.js';
|
|
3
|
-
export
|
|
3
|
+
export declare class HttpRenderer extends RenderBase {
|
|
4
4
|
id: string;
|
|
5
5
|
host: string;
|
|
6
6
|
url: string;
|
package/lib/renderer/http.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import axios from 'axios'
|
|
2
|
-
import RenderBase from './base.js'
|
|
2
|
+
import { RenderBase } from './base.js'
|
|
3
3
|
import logger from '../utils/logger.js'
|
|
4
|
-
export
|
|
4
|
+
export class HttpRenderer extends RenderBase {
|
|
5
5
|
id
|
|
6
6
|
host
|
|
7
7
|
url
|
package/lib/renderer/server.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import RenderBase from './base.js';
|
|
3
2
|
import WebSocket from 'ws';
|
|
3
|
+
import { RenderBase } from './base.js';
|
|
4
4
|
import { IncomingMessage } from 'http';
|
|
5
|
-
import { KarinRenderType } from '../types/
|
|
5
|
+
import { KarinRenderType } from '../types/index.js';
|
|
6
6
|
declare class Puppeteer extends RenderBase {
|
|
7
7
|
socket: WebSocket;
|
|
8
8
|
id: any;
|
|
@@ -34,9 +34,9 @@ declare class Puppeteer extends RenderBase {
|
|
|
34
34
|
*/
|
|
35
35
|
render(options: KarinRenderType): Promise<string | string[]>;
|
|
36
36
|
}
|
|
37
|
-
declare const
|
|
37
|
+
export declare const RenderServer: {
|
|
38
38
|
type: string;
|
|
39
39
|
path: string;
|
|
40
40
|
adapter: typeof Puppeteer;
|
|
41
41
|
};
|
|
42
|
-
export
|
|
42
|
+
export {};
|
package/lib/renderer/server.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import RenderBase from './base.js'
|
|
1
|
+
import { render } from './app.js'
|
|
2
|
+
import { RenderBase } from './base.js'
|
|
3
3
|
import { randomUUID } from 'crypto'
|
|
4
|
-
import logger from '../utils/
|
|
5
|
-
import listener from '../core/listener.js'
|
|
4
|
+
import { logger } from '../utils/index.js'
|
|
5
|
+
import { listener } from '../core/listener.js'
|
|
6
6
|
class Puppeteer extends RenderBase {
|
|
7
7
|
socket
|
|
8
8
|
id
|
|
@@ -42,12 +42,12 @@ class Puppeteer extends RenderBase {
|
|
|
42
42
|
this.socket.on('close', () => {
|
|
43
43
|
logger.warn(`[渲染器:${this.id}] 连接断开:${this.url}`)
|
|
44
44
|
/** 卸载渲染器 */
|
|
45
|
-
this.index &&
|
|
45
|
+
this.index && render.unapp(this.index)
|
|
46
46
|
this.index = 0
|
|
47
47
|
})
|
|
48
48
|
/** 注册渲染器 */
|
|
49
49
|
try {
|
|
50
|
-
const index =
|
|
50
|
+
const index = render.app({
|
|
51
51
|
id: this.id,
|
|
52
52
|
type: this.type,
|
|
53
53
|
render: this.render.bind(this),
|
|
@@ -105,7 +105,7 @@ class Puppeteer extends RenderBase {
|
|
|
105
105
|
})
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
|
-
export
|
|
108
|
+
export const RenderServer = {
|
|
109
109
|
type: 'render',
|
|
110
110
|
path: '/puppeteer',
|
|
111
111
|
adapter: Puppeteer,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export declare function Wormhole(): void;
|
package/lib/renderer/wormhole.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import WebSocket from 'ws'
|
|
2
1
|
import fs from 'fs'
|
|
3
2
|
import path from 'path'
|
|
4
3
|
import { URL } from 'url'
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
4
|
+
import WebSocket from 'ws'
|
|
5
|
+
import { render } from './index.js'
|
|
6
|
+
import { HttpRenderer } from './http.js'
|
|
7
|
+
import { config } from '../utils/index.js'
|
|
8
8
|
let ws
|
|
9
9
|
let reConnect
|
|
10
10
|
const chunkSize = 1024 * 1024 * 3 // 文件分片大小
|
|
11
|
-
export
|
|
11
|
+
export function Wormhole () {
|
|
12
12
|
let heartbeat
|
|
13
13
|
let index = 0
|
|
14
14
|
reConnect = undefined
|
|
@@ -135,7 +135,7 @@ export default function connect () {
|
|
|
135
135
|
}
|
|
136
136
|
logger.warn('连接关闭,10秒后尝试重新连接')
|
|
137
137
|
if (!reConnect) {
|
|
138
|
-
reConnect = setTimeout(
|
|
138
|
+
reConnect = setTimeout(Wormhole, 10000)
|
|
139
139
|
}
|
|
140
140
|
})
|
|
141
141
|
ws.on('error', function error () {
|
|
@@ -148,7 +148,7 @@ export default function connect () {
|
|
|
148
148
|
}
|
|
149
149
|
logger.warn('连接错误,10秒后尝试重新连接')
|
|
150
150
|
if (!reConnect) {
|
|
151
|
-
reConnect = setTimeout(
|
|
151
|
+
reConnect = setTimeout(Wormhole, 10000)
|
|
152
152
|
}
|
|
153
153
|
})
|
|
154
154
|
}
|
package/lib/types/adapter.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { WebSocket } from 'ws';
|
|
3
3
|
import { IncomingMessage } from 'http';
|
|
4
4
|
import { KarinElement, KarinNodeElement } from './element.js';
|
|
5
|
-
import { contact, PushMessageBody, EssenceMessageBody, FriendInfo, GroupInfo, GroupMemberInfo, GroupHonorInfo } from './
|
|
5
|
+
import { contact, PushMessageBody, EssenceMessageBody, FriendInfo, GroupInfo, GroupMemberInfo, GroupHonorInfo } from './event.js';
|
|
6
6
|
export interface KarinAdapter {
|
|
7
7
|
/**
|
|
8
8
|
* - 适配器版本信息
|
package/lib/types/config.d.ts
CHANGED
|
@@ -101,16 +101,22 @@ export interface App {
|
|
|
101
101
|
export interface Config {
|
|
102
102
|
/**
|
|
103
103
|
* 日志等级
|
|
104
|
+
* @description 即将废弃,请使用log4jsCfg.level
|
|
104
105
|
*/
|
|
105
|
-
log_level
|
|
106
|
+
log_level?: string;
|
|
106
107
|
/**
|
|
107
108
|
* 日志保留天数
|
|
109
|
+
* @description 即将废弃,请使用log4jsCfg.daysToKeep
|
|
108
110
|
*/
|
|
109
|
-
log_days_Keep
|
|
111
|
+
log_days_Keep?: number;
|
|
110
112
|
/**
|
|
111
113
|
* 控制台触发插件日志颜色
|
|
112
114
|
*/
|
|
113
115
|
log_color: string;
|
|
116
|
+
/**
|
|
117
|
+
* 关闭后台进程失败后是否继续启动 继续启动会导致多进程
|
|
118
|
+
*/
|
|
119
|
+
multi_progress: boolean;
|
|
114
120
|
/**
|
|
115
121
|
* ffmpeg配置
|
|
116
122
|
*/
|
|
@@ -165,7 +171,7 @@ export interface Config {
|
|
|
165
171
|
/**
|
|
166
172
|
* 日志等级
|
|
167
173
|
*/
|
|
168
|
-
level:
|
|
174
|
+
level: 'trace' | 'debug' | 'info' | 'warn' | 'fatal' | 'mark' | 'error' | 'off';
|
|
169
175
|
/**
|
|
170
176
|
* 日志保留天数
|
|
171
177
|
*/
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { KarinElement } from './element.js';
|
|
2
|
-
import { KarinMessage } from '../event/
|
|
3
|
-
import { KarinNotice } from '../event/notice.js';
|
|
4
|
-
import { KarinRequest } from '../event/request.js';
|
|
2
|
+
import { KarinMessage, KarinNotice, KarinRequest } from '../event/index.js';
|
|
5
3
|
/**
|
|
6
4
|
* - 事件类型
|
|
7
5
|
*/
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export * from './adapter.js';
|
|
2
2
|
export * from './config.js';
|
|
3
|
+
export * from './element.js';
|
|
4
|
+
export * from './event.js';
|
|
3
5
|
export * from './logger.js';
|
|
4
6
|
export * from './onebots11.js';
|
|
5
|
-
export * from './plugin.js';
|
|
6
7
|
export * from './render.js';
|
|
8
|
+
export * from './plugin.js';
|
|
7
9
|
export * from './reply.js';
|
|
8
|
-
export * from './types.js';
|
package/lib/types/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export * from './adapter.js'
|
|
2
2
|
export * from './config.js'
|
|
3
|
+
export * from './element.js'
|
|
4
|
+
export * from './event.js'
|
|
3
5
|
export * from './logger.js'
|
|
4
6
|
export * from './onebots11.js'
|
|
5
|
-
export * from './plugin.js'
|
|
6
7
|
export * from './render.js'
|
|
8
|
+
export * from './plugin.js'
|
|
7
9
|
export * from './reply.js'
|
|
8
|
-
export * from './types.js'
|
package/lib/types/plugin.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import schedule from 'node-schedule';
|
|
3
3
|
import { KarinNodeElement } from './element.js';
|
|
4
4
|
import { Reply, replyCallback } from './reply.js';
|
|
5
|
-
import { E, Event, Permission, SubEvent } from './
|
|
5
|
+
import { E, Event, Permission, SubEvent } from './event.js';
|
|
6
6
|
/**
|
|
7
7
|
* - 插件根目录名称
|
|
8
8
|
* - 例如: karin-plugin-example
|
|
@@ -118,7 +118,7 @@ export interface AppInfo {
|
|
|
118
118
|
/**
|
|
119
119
|
* - 插件基类
|
|
120
120
|
*/
|
|
121
|
-
export interface
|
|
121
|
+
export interface PluginType {
|
|
122
122
|
/**
|
|
123
123
|
* - 插件名称
|
|
124
124
|
*/
|
|
@@ -209,7 +209,7 @@ export interface Plugin {
|
|
|
209
209
|
/**
|
|
210
210
|
* - 插件实例
|
|
211
211
|
*/
|
|
212
|
-
plugin:
|
|
212
|
+
plugin: PluginType;
|
|
213
213
|
/**
|
|
214
214
|
* - 执行方法名称
|
|
215
215
|
*/
|
|
@@ -223,9 +223,9 @@ export interface Plugin {
|
|
|
223
223
|
/**
|
|
224
224
|
* 上下文状态
|
|
225
225
|
*/
|
|
226
|
-
export interface
|
|
226
|
+
export interface stateArrType {
|
|
227
227
|
[key: string]: {
|
|
228
|
-
plugin:
|
|
228
|
+
plugin: PluginType;
|
|
229
229
|
fnc: string;
|
|
230
230
|
};
|
|
231
231
|
}
|
|
@@ -244,7 +244,7 @@ export interface PluginApps {
|
|
|
244
244
|
/**
|
|
245
245
|
* - 插件方法
|
|
246
246
|
*/
|
|
247
|
-
Fnc: '' | (new () =>
|
|
247
|
+
Fnc: '' | (new () => PluginType);
|
|
248
248
|
};
|
|
249
249
|
/**
|
|
250
250
|
* - 插件名称
|
package/lib/utils/button.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Plugin, dirName, fileName } from '../types/plugin.js';
|
|
2
1
|
import { KarinMessage } from '../event/message.js';
|
|
3
|
-
|
|
2
|
+
import { PluginType, dirName, fileName } from '../types/plugin.js';
|
|
3
|
+
export declare const button: {
|
|
4
4
|
Apps: Array<{
|
|
5
|
-
App: new () =>
|
|
5
|
+
App: new () => PluginType;
|
|
6
6
|
name: string;
|
|
7
7
|
priority: number;
|
|
8
8
|
file: {
|
|
@@ -17,8 +17,8 @@ declare const _default: {
|
|
|
17
17
|
add({ name, dir, App, Class }: {
|
|
18
18
|
dir: dirName;
|
|
19
19
|
name: fileName;
|
|
20
|
-
App: new () =>
|
|
21
|
-
Class:
|
|
20
|
+
App: new () => PluginType;
|
|
21
|
+
Class: PluginType;
|
|
22
22
|
}): void;
|
|
23
23
|
/**
|
|
24
24
|
* 卸载按钮
|
|
@@ -26,7 +26,7 @@ declare const _default: {
|
|
|
26
26
|
* @param {string} name 插件文件名称
|
|
27
27
|
*/
|
|
28
28
|
del(dir: dirName, name: fileName): {
|
|
29
|
-
App: new () =>
|
|
29
|
+
App: new () => PluginType;
|
|
30
30
|
name: string;
|
|
31
31
|
priority: number;
|
|
32
32
|
file: {
|
|
@@ -41,9 +41,8 @@ declare const _default: {
|
|
|
41
41
|
update({ dir, name, App, Class }: {
|
|
42
42
|
dir: dirName;
|
|
43
43
|
name: fileName;
|
|
44
|
-
App: new () =>
|
|
45
|
-
Class:
|
|
44
|
+
App: new () => PluginType;
|
|
45
|
+
Class: PluginType;
|
|
46
46
|
}): void;
|
|
47
47
|
get(e: KarinMessage): Promise<any[]>;
|
|
48
48
|
};
|
|
49
|
-
export default _default;
|
package/lib/utils/button.js
CHANGED
package/lib/utils/common.d.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import fs from 'fs';
|
|
3
2
|
import { AxiosRequestConfig } from 'axios';
|
|
4
3
|
import { Readable } from 'stream';
|
|
5
|
-
import {
|
|
6
|
-
import { dirName } from '../types/
|
|
4
|
+
import { fs } from '../modules.js';
|
|
5
|
+
import { dirName, KarinElement, KarinNodeElement } from '../types/index.js';
|
|
7
6
|
/**
|
|
8
7
|
* 常用方法
|
|
9
8
|
*/
|
|
10
|
-
declare const
|
|
9
|
+
export declare const common: {
|
|
11
10
|
streamPipeline: (stream1: Readable, stream2: fs.WriteStream) => Promise<void>;
|
|
12
11
|
/**
|
|
13
12
|
* 休眠函数
|
|
@@ -21,6 +20,13 @@ declare const _default: {
|
|
|
21
20
|
* @param param axios参数
|
|
22
21
|
*/
|
|
23
22
|
downFile(fileUrl: string, savePath: string, param?: AxiosRequestConfig): Promise<boolean>;
|
|
23
|
+
/**
|
|
24
|
+
* 对axios进行简单封装,超时、错误后返回null,不会抛出异常
|
|
25
|
+
* @param url 请求地址
|
|
26
|
+
* @param type 请求类型
|
|
27
|
+
* @param param axios参数
|
|
28
|
+
*/
|
|
29
|
+
axios(url: string, type?: 'get' | 'post', param?: AxiosRequestConfig): Promise<any | null>;
|
|
24
30
|
/**
|
|
25
31
|
* 递归创建目录
|
|
26
32
|
* @param dirname - 要创建的文件夹路径
|
|
@@ -120,4 +126,3 @@ declare const _default: {
|
|
|
120
126
|
*/
|
|
121
127
|
makeMessageLog(message: Array<KarinElement>): string;
|
|
122
128
|
};
|
|
123
|
-
export default _default;
|
package/lib/utils/common.js
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
import fs from 'fs'
|
|
2
|
-
import path from 'path'
|
|
3
|
-
import axios from 'axios'
|
|
4
1
|
import { promisify } from 'util'
|
|
5
|
-
import logger from '../utils/logger.js'
|
|
6
|
-
import segment from '../utils/segment.js'
|
|
7
|
-
import { pipeline, Readable } from 'stream'
|
|
8
|
-
import lodash from 'lodash'
|
|
9
2
|
import { fileURLToPath } from 'url'
|
|
3
|
+
import { pipeline, Readable } from 'stream'
|
|
4
|
+
import { logger, segment } from '../utils/index.js'
|
|
5
|
+
import { fs, path, axios, lodash } from '../modules.js'
|
|
10
6
|
/**
|
|
11
7
|
* 常用方法
|
|
12
8
|
*/
|
|
13
|
-
export
|
|
9
|
+
export const common = new (class Common {
|
|
14
10
|
streamPipeline
|
|
15
11
|
constructor () {
|
|
16
12
|
this.streamPipeline = promisify(pipeline)
|
|
@@ -43,6 +39,22 @@ export default new (class Common {
|
|
|
43
39
|
}
|
|
44
40
|
}
|
|
45
41
|
|
|
42
|
+
/**
|
|
43
|
+
* 对axios进行简单封装,超时、错误后返回null,不会抛出异常
|
|
44
|
+
* @param url 请求地址
|
|
45
|
+
* @param type 请求类型
|
|
46
|
+
* @param param axios参数
|
|
47
|
+
*/
|
|
48
|
+
async axios (url, type = 'get', param = {}) {
|
|
49
|
+
try {
|
|
50
|
+
if (type === 'post') { return await axios.post(url, param.data, param) }
|
|
51
|
+
return await axios.get(url, param)
|
|
52
|
+
} catch (error) {
|
|
53
|
+
logger.debug(error)
|
|
54
|
+
return null
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
46
58
|
/**
|
|
47
59
|
* 递归创建目录
|
|
48
60
|
* @param dirname - 要创建的文件夹路径
|
package/lib/utils/config.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { Redis, App, Config, Server, Package, GroupCfg } from '../types/config.js';
|
|
2
1
|
import { Logger } from 'log4js';
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import { Redis, App, Config, Server, Package, GroupCfg } from '../types/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* 配置文件
|
|
5
|
+
*/
|
|
6
|
+
export declare const config: {
|
|
5
7
|
dir: string;
|
|
6
8
|
_path: string;
|
|
7
9
|
_pathDef: string;
|
|
@@ -67,6 +69,5 @@ declare const _default: {
|
|
|
67
69
|
change_App(): Promise<void>;
|
|
68
70
|
change_config(): Promise<void>;
|
|
69
71
|
change_group(): Promise<void>;
|
|
70
|
-
"__#
|
|
72
|
+
"__#2@#review"(): Promise<void>;
|
|
71
73
|
};
|
|
72
|
-
export default _default;
|
package/lib/utils/config.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import fs from 'fs'
|
|
2
|
-
import Yaml from 'yaml'
|
|
3
|
-
import chokidar from 'chokidar'
|
|
4
1
|
import { karinDir } from '../core/dir.js'
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
import { fs, yaml as Yaml, chokidar } from '../modules.js'
|
|
3
|
+
/**
|
|
4
|
+
* 配置文件
|
|
5
|
+
*/
|
|
6
|
+
export const config = new (class Cfg {
|
|
7
7
|
dir
|
|
8
8
|
_path
|
|
9
9
|
_pathDef
|
|
@@ -236,7 +236,7 @@ export default new (class Cfg {
|
|
|
236
236
|
|
|
237
237
|
async change_config () {
|
|
238
238
|
/** 修改日志等级 */
|
|
239
|
-
this.loggger.level = this.Config.
|
|
239
|
+
this.loggger.level = this.Config.log4jsCfg.level
|
|
240
240
|
await this.#review()
|
|
241
241
|
// if (this.Server.HotUpdate) {
|
|
242
242
|
// const { Bot } = await import('../index.js')
|
package/lib/utils/ffmpeg.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import exec from './exec.js'
|
|
2
2
|
import logger from './logger.js'
|
|
3
|
-
import
|
|
3
|
+
import { config } from './config.js'
|
|
4
4
|
/**
|
|
5
5
|
* 执行 ffmpeg 命令
|
|
6
6
|
*/
|
|
@@ -9,7 +9,7 @@ export default async function ffmpeg () {
|
|
|
9
9
|
const { status } = await exec('ffmpeg -version', false)
|
|
10
10
|
if (status !== 'ok') {
|
|
11
11
|
logger.debug('ffmpeg 未安装,开始尝试读取配置文件是否存在ffmpeg路径')
|
|
12
|
-
const ffmpegPath =
|
|
12
|
+
const ffmpegPath = config.Config.ffmpeg_path
|
|
13
13
|
if (!ffmpegPath) {
|
|
14
14
|
logger.warn('ffmpeg 未安装,请安装 ffmpeg 或手动配置 ffmpeg 路径后重启')
|
|
15
15
|
return false
|
package/lib/utils/handler.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import Plugin from '../core/
|
|
2
|
-
import { dirName, fileName } from '../types/
|
|
1
|
+
import { Plugin } from '../core/index.js';
|
|
2
|
+
import { dirName, fileName } from '../types/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* 事件处理器类
|
|
5
5
|
*/
|
|
6
|
-
declare const
|
|
6
|
+
export declare const handler: {
|
|
7
7
|
events: {
|
|
8
8
|
[key: string]: {
|
|
9
9
|
/**
|
|
@@ -73,4 +73,3 @@ declare const _default: {
|
|
|
73
73
|
*/
|
|
74
74
|
has(key: string): boolean;
|
|
75
75
|
};
|
|
76
|
-
export default _default;
|
package/lib/utils/handler.js
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from './button.js';
|
|
2
|
+
export * from './common.js';
|
|
3
|
+
export * from './config.js';
|
|
4
|
+
export * from './ffmpeg.js';
|
|
5
|
+
export * from './handler.js';
|
|
6
|
+
export * from './exec.js';
|
|
7
|
+
export * from './segment.js';
|
|
8
|
+
export * from './update.js';
|
|
9
|
+
export * from './yamlEditor.js';
|
|
10
|
+
export * from './logger.js';
|
|
11
|
+
export * from './updateVersion.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from './button.js'
|
|
2
|
+
export * from './common.js'
|
|
3
|
+
export * from './config.js'
|
|
4
|
+
export * from './ffmpeg.js'
|
|
5
|
+
export * from './handler.js'
|
|
6
|
+
export * from './exec.js'
|
|
7
|
+
export * from './segment.js'
|
|
8
|
+
export * from './update.js'
|
|
9
|
+
export * from './yamlEditor.js'
|
|
10
|
+
export * from './logger.js'
|
|
11
|
+
export * from './updateVersion.js'
|
package/lib/utils/logger.d.ts
CHANGED