node-karin 0.0.3
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/LICENSE +674 -0
- package/README.md +57 -0
- package/config/defSet/App.yaml +37 -0
- package/config/defSet/config.yaml +43 -0
- package/config/defSet/group.yaml +18 -0
- package/config/defSet/pm2.yaml +21 -0
- package/config/defSet/redis.yaml +18 -0
- package/config/defSet/server.yaml +42 -0
- package/config/view/App.yaml +74 -0
- package/config/view/config.yaml +100 -0
- package/config/view/group.yaml +62 -0
- package/config/view/pm2.yaml +41 -0
- package/config/view/redis.yaml +25 -0
- package/config/view/server.yaml +93 -0
- package/lib/adapter/onebot/onebot11.d.ts +430 -0
- package/lib/adapter/onebot/onebot11.js +1302 -0
- package/lib/core/init.d.ts +0 -0
- package/lib/core/init.js +4 -0
- package/lib/core/karin.d.ts +72 -0
- package/lib/core/karin.js +51 -0
- package/lib/core/listener.d.ts +121 -0
- package/lib/core/listener.js +188 -0
- package/lib/core/plugin.app.d.ts +15 -0
- package/lib/core/plugin.app.js +18 -0
- package/lib/core/plugin.d.ts +182 -0
- package/lib/core/plugin.js +138 -0
- package/lib/core/plugin.loader.d.ts +149 -0
- package/lib/core/plugin.loader.js +462 -0
- package/lib/core/server.d.ts +26 -0
- package/lib/core/server.js +213 -0
- package/lib/db/level.d.ts +20 -0
- package/lib/db/level.js +38 -0
- package/lib/db/redis.d.ts +41 -0
- package/lib/db/redis.js +137 -0
- package/lib/db/redis_level.d.ts +113 -0
- package/lib/db/redis_level.js +290 -0
- package/lib/event/event.d.ts +138 -0
- package/lib/event/event.handler.d.ts +29 -0
- package/lib/event/event.handler.js +142 -0
- package/lib/event/event.js +120 -0
- package/lib/event/message.d.ts +102 -0
- package/lib/event/message.handler.d.ts +25 -0
- package/lib/event/message.handler.js +240 -0
- package/lib/event/message.js +70 -0
- package/lib/event/notice.d.ts +49 -0
- package/lib/event/notice.js +15 -0
- package/lib/event/request.d.ts +49 -0
- package/lib/event/request.js +15 -0
- package/lib/event/review.handler.d.ts +54 -0
- package/lib/event/review.handler.js +382 -0
- package/lib/index.d.ts +23 -0
- package/lib/index.js +40 -0
- package/lib/renderer/app.d.ts +53 -0
- package/lib/renderer/app.js +93 -0
- package/lib/renderer/base.d.ts +30 -0
- package/lib/renderer/base.js +71 -0
- package/lib/renderer/client.d.ts +30 -0
- package/lib/renderer/client.js +159 -0
- package/lib/renderer/http.d.ts +19 -0
- package/lib/renderer/http.js +51 -0
- package/lib/renderer/server.d.ts +42 -0
- package/lib/renderer/server.js +112 -0
- package/lib/renderer/wormhole.d.ts +1 -0
- package/lib/renderer/wormhole.js +154 -0
- package/lib/types/adapter.d.ts +575 -0
- package/lib/types/adapter.js +1 -0
- package/lib/types/config.d.ts +327 -0
- package/lib/types/config.js +1 -0
- package/lib/types/element.d.ts +576 -0
- package/lib/types/element.js +1 -0
- package/lib/types/index.d.ts +8 -0
- package/lib/types/index.js +8 -0
- package/lib/types/logger.d.ts +109 -0
- package/lib/types/logger.js +1 -0
- package/lib/types/onebots11.d.ts +1371 -0
- package/lib/types/onebots11.js +1 -0
- package/lib/types/plugin.d.ts +282 -0
- package/lib/types/plugin.js +1 -0
- package/lib/types/render.d.ts +111 -0
- package/lib/types/render.js +1 -0
- package/lib/types/reply.d.ts +40 -0
- package/lib/types/reply.js +1 -0
- package/lib/types/types.d.ts +898 -0
- package/lib/types/types.js +1 -0
- package/lib/utils/YamlEditor.d.ts +62 -0
- package/lib/utils/YamlEditor.js +208 -0
- package/lib/utils/button.d.ts +49 -0
- package/lib/utils/button.js +79 -0
- package/lib/utils/common.d.ts +123 -0
- package/lib/utils/common.js +413 -0
- package/lib/utils/config.d.ts +72 -0
- package/lib/utils/config.js +254 -0
- package/lib/utils/exec.d.ts +22 -0
- package/lib/utils/exec.js +36 -0
- package/lib/utils/ffmpeg.d.ts +12 -0
- package/lib/utils/ffmpeg.js +25 -0
- package/lib/utils/handler.d.ts +76 -0
- package/lib/utils/handler.js +102 -0
- package/lib/utils/logger.d.ts +3 -0
- package/lib/utils/logger.js +104 -0
- package/lib/utils/segment.d.ts +276 -0
- package/lib/utils/segment.js +448 -0
- package/lib/utils/update.d.ts +69 -0
- package/lib/utils/update.js +151 -0
- package/lib/utils/updateVersion.d.ts +33 -0
- package/lib/utils/updateVersion.js +145 -0
- package/package.json +92 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import Yaml from 'yaml';
|
|
2
|
+
export default class YamlEditor {
|
|
3
|
+
filePath: string;
|
|
4
|
+
document: Yaml.Document;
|
|
5
|
+
constructor(filePath: string);
|
|
6
|
+
load(): void;
|
|
7
|
+
/**
|
|
8
|
+
* 获取指定路径的值
|
|
9
|
+
* @param path - 路径,用点号分隔,例如:'a.b.c'
|
|
10
|
+
*/
|
|
11
|
+
get(path: string): any;
|
|
12
|
+
/**
|
|
13
|
+
* 设置指定路径的值
|
|
14
|
+
* @param path - 路径,用点号分隔,例如:'a.b.c'
|
|
15
|
+
* @param value - 要设置的值
|
|
16
|
+
*/
|
|
17
|
+
set(path: string | string[], value: string): null | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* 向指定路径添加新值
|
|
20
|
+
* @param path - 路径,用点号分隔,例如:'a.b.c'
|
|
21
|
+
* @param value - 要添加的值
|
|
22
|
+
*/
|
|
23
|
+
add(path: string | string[], value: string): void;
|
|
24
|
+
/**
|
|
25
|
+
* 删除指定路径
|
|
26
|
+
* @param path - 路径,用点号分隔,例如:'a.b.c'
|
|
27
|
+
* @returns 是否删除成功
|
|
28
|
+
*/
|
|
29
|
+
del(path: string | string[]): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* 向指定路径的数组添加新值,可以选择添加到数组的开始或结束
|
|
32
|
+
* @param path - 路径,用点号分隔,例如:'a.b.c'
|
|
33
|
+
* @param value - 要添加的值
|
|
34
|
+
* @param prepend - 如果为 true,则添加到数组的开头,否则添加到末尾
|
|
35
|
+
*/
|
|
36
|
+
append(path: string | string[], value: string, prepend?: boolean): void;
|
|
37
|
+
/**
|
|
38
|
+
* 检查指定路径的键是否存在
|
|
39
|
+
* @param path - 路径,用点号分隔
|
|
40
|
+
*/
|
|
41
|
+
has(path: string | string[]): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* 查询指定路径中是否包含指定的值
|
|
44
|
+
* @param path - 路径,用点号分隔
|
|
45
|
+
* @param value - 要查询的值
|
|
46
|
+
*/
|
|
47
|
+
hasVal(path: string | string[], value: any): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* 向根节点新增元素,如果根节点不是数组,则将其转换为数组再新增元素
|
|
50
|
+
* @param value - 要新增的元素
|
|
51
|
+
*/
|
|
52
|
+
pusharr(value: any): false | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* 根据索引从根节点数组删除元素
|
|
55
|
+
* @param index - 要删除元素的索引
|
|
56
|
+
*/
|
|
57
|
+
delarr(index: number): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* 保存文件
|
|
60
|
+
*/
|
|
61
|
+
save(): void;
|
|
62
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* YamlEditor - 一个用于编辑 YAML 文件的类
|
|
3
|
+
* 本代码由 ChatGPT4 提供
|
|
4
|
+
* https://github.com/OpenAI
|
|
5
|
+
*/
|
|
6
|
+
import fs from 'fs'
|
|
7
|
+
import Yaml from 'yaml'
|
|
8
|
+
import lodash from 'lodash'
|
|
9
|
+
import logger from './logger.js'
|
|
10
|
+
export default class YamlEditor {
|
|
11
|
+
filePath
|
|
12
|
+
document
|
|
13
|
+
constructor (filePath) {
|
|
14
|
+
this.filePath = filePath
|
|
15
|
+
this.load()
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
load () {
|
|
19
|
+
try {
|
|
20
|
+
const fileContents = fs.readFileSync(this.filePath, 'utf8')
|
|
21
|
+
this.document = Yaml.parseDocument(fileContents)
|
|
22
|
+
logger.debug('[YamlEditor] 文件加载成功')
|
|
23
|
+
} catch (error) {
|
|
24
|
+
logger.error(`[YamlEditor] 加载文件时出错:${error}`)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 获取指定路径的值
|
|
30
|
+
* @param path - 路径,用点号分隔,例如:'a.b.c'
|
|
31
|
+
*/
|
|
32
|
+
get (path) {
|
|
33
|
+
try {
|
|
34
|
+
if (!path) { return this.document.toJSON() }
|
|
35
|
+
return lodash.get(this.document.toJSON(), path)
|
|
36
|
+
} catch (error) {
|
|
37
|
+
logger.error(`[YamlEditor] 获取数据时出错:${error}`)
|
|
38
|
+
return null
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* 设置指定路径的值
|
|
44
|
+
* @param path - 路径,用点号分隔,例如:'a.b.c'
|
|
45
|
+
* @param value - 要设置的值
|
|
46
|
+
*/
|
|
47
|
+
set (path, value) {
|
|
48
|
+
try {
|
|
49
|
+
path = typeof path === 'string' ? path.split('.') : path
|
|
50
|
+
this.document.setIn(path, value)
|
|
51
|
+
} catch (error) {
|
|
52
|
+
logger.error(`[YamlEditor] 设置数据时出错:${error}`)
|
|
53
|
+
return null
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* 向指定路径添加新值
|
|
59
|
+
* @param path - 路径,用点号分隔,例如:'a.b.c'
|
|
60
|
+
* @param value - 要添加的值
|
|
61
|
+
*/
|
|
62
|
+
add (path, value) {
|
|
63
|
+
try {
|
|
64
|
+
path = typeof path === 'string' ? path.split('.') : path
|
|
65
|
+
this.document.addIn(path, value)
|
|
66
|
+
logger.debug(`[YamlEditor] 已在 ${path} 添加新的值`)
|
|
67
|
+
} catch (error) {
|
|
68
|
+
logger.error(`[YamlEditor] 添加数据时出错:${error}`)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* 删除指定路径
|
|
74
|
+
* @param path - 路径,用点号分隔,例如:'a.b.c'
|
|
75
|
+
* @returns 是否删除成功
|
|
76
|
+
*/
|
|
77
|
+
del (path) {
|
|
78
|
+
try {
|
|
79
|
+
path = typeof path === 'string' ? path.split('.') : path
|
|
80
|
+
this.document.deleteIn(path)
|
|
81
|
+
return true
|
|
82
|
+
} catch (error) {
|
|
83
|
+
logger.error(`[YamlEditor] 删除数据时出错:${error}`)
|
|
84
|
+
return false
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* 向指定路径的数组添加新值,可以选择添加到数组的开始或结束
|
|
90
|
+
* @param path - 路径,用点号分隔,例如:'a.b.c'
|
|
91
|
+
* @param value - 要添加的值
|
|
92
|
+
* @param prepend - 如果为 true,则添加到数组的开头,否则添加到末尾
|
|
93
|
+
*/
|
|
94
|
+
append (path, value, prepend = false) {
|
|
95
|
+
try {
|
|
96
|
+
path = typeof path === 'string' ? path.split('.') : path || []
|
|
97
|
+
let current = this.document.getIn(path)
|
|
98
|
+
if (!current) {
|
|
99
|
+
current = new Yaml.YAMLSeq()
|
|
100
|
+
this.document.setIn(path, current)
|
|
101
|
+
} else if (!(current instanceof Yaml.YAMLSeq)) {
|
|
102
|
+
throw new Error('[YamlEditor] 指定的路径不是数组')
|
|
103
|
+
} else {
|
|
104
|
+
if (prepend) {
|
|
105
|
+
current.items.unshift(value)
|
|
106
|
+
} else {
|
|
107
|
+
current.add(value)
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
logger.debug(`[YamlEditor] 已向 ${path} 数组${prepend ? '开头' : '末尾'}添加新元素:${value}`)
|
|
111
|
+
} catch (error) {
|
|
112
|
+
logger.error(`[YamlEditor] 向数组添加元素时出错:${error}`)
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* 检查指定路径的键是否存在
|
|
118
|
+
* @param path - 路径,用点号分隔
|
|
119
|
+
*/
|
|
120
|
+
has (path) {
|
|
121
|
+
try {
|
|
122
|
+
path = typeof path === 'string' ? path.split('.') : path
|
|
123
|
+
return this.document.hasIn(path)
|
|
124
|
+
} catch (error) {
|
|
125
|
+
logger.error(`[YamlEditor] 检查路径是否存在时出错:${error}`)
|
|
126
|
+
return false
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* 查询指定路径中是否包含指定的值
|
|
132
|
+
* @param path - 路径,用点号分隔
|
|
133
|
+
* @param value - 要查询的值
|
|
134
|
+
*/
|
|
135
|
+
hasVal (path, value) {
|
|
136
|
+
try {
|
|
137
|
+
path = typeof path === 'string' ? path.split('.') : path
|
|
138
|
+
const current = this.document.getIn(path)
|
|
139
|
+
if (!current) { return false }
|
|
140
|
+
/** 检查当前节点是否包含指定的值 */
|
|
141
|
+
if (current instanceof Yaml.YAMLSeq) {
|
|
142
|
+
/** 如果是序列,遍历序列查找值 */
|
|
143
|
+
return current.items.some(item => lodash.isEqual(item.toJSON(), value))
|
|
144
|
+
} else if (current instanceof Yaml.YAMLMap) {
|
|
145
|
+
/** 如果是映射,检查每个值 */
|
|
146
|
+
return Array.from(current.values()).some((v) => lodash.isEqual(v.toJSON(), value))
|
|
147
|
+
} else {
|
|
148
|
+
/** 否则,直接比较值 */
|
|
149
|
+
return lodash.isEqual(current, value)
|
|
150
|
+
}
|
|
151
|
+
} catch (error) {
|
|
152
|
+
logger.error(`[YamlEditor] 检查路径 ${path} 是否包含值时出错:${error}`)
|
|
153
|
+
return false
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* 向根节点新增元素,如果根节点不是数组,则将其转换为数组再新增元素
|
|
159
|
+
* @param value - 要新增的元素
|
|
160
|
+
*/
|
|
161
|
+
pusharr (value) {
|
|
162
|
+
try {
|
|
163
|
+
if (!(this.document.contents instanceof Yaml.YAMLSeq)) {
|
|
164
|
+
// 如果根节点不是数组,则将其转换为数组
|
|
165
|
+
this.document.contents = new Yaml.YAMLSeq()
|
|
166
|
+
logger.debug('[YamlEditor] 根节点已转换为数组')
|
|
167
|
+
}
|
|
168
|
+
this.document.contents.add(value)
|
|
169
|
+
logger.debug('[YamlEditor] 已向根节点数组新增元素:', value)
|
|
170
|
+
} catch (error) {
|
|
171
|
+
logger.error(`[YamlEditor] 向根节点数组新增元素时出错:${error}`)
|
|
172
|
+
return false
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* 根据索引从根节点数组删除元素
|
|
178
|
+
* @param index - 要删除元素的索引
|
|
179
|
+
*/
|
|
180
|
+
delarr (index) {
|
|
181
|
+
try {
|
|
182
|
+
if (!(this.document.contents instanceof Yaml.YAMLSeq)) {
|
|
183
|
+
throw new Error('[YamlEditor] 根节点不是数组')
|
|
184
|
+
}
|
|
185
|
+
if (index < 0 || index >= this.document.contents.items.length) {
|
|
186
|
+
throw new Error('[YamlEditor] 索引超出范围')
|
|
187
|
+
}
|
|
188
|
+
this.document.contents.items.splice(index, 1)
|
|
189
|
+
logger.debug('[YamlEditor] 已根据索引从根节点数组删除元素,索引:', index)
|
|
190
|
+
return true
|
|
191
|
+
} catch (error) {
|
|
192
|
+
logger.error(`[YamlEditor] 根据索引删除根节点数组元素时出错:${error}`)
|
|
193
|
+
return false
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* 保存文件
|
|
199
|
+
*/
|
|
200
|
+
save () {
|
|
201
|
+
try {
|
|
202
|
+
fs.writeFileSync(this.filePath, this.document.toString())
|
|
203
|
+
logger.info('[YamlEditor] 文件已保存')
|
|
204
|
+
} catch (error) {
|
|
205
|
+
logger.error(`[YamlEditor] 保存文件时出错:${error}`)
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Plugin, dirName, fileName } from '../types/plugin.js';
|
|
2
|
+
import { KarinMessage } from '../event/message.js';
|
|
3
|
+
declare const _default: {
|
|
4
|
+
Apps: Array<{
|
|
5
|
+
App: new () => Plugin;
|
|
6
|
+
name: string;
|
|
7
|
+
priority: number;
|
|
8
|
+
file: {
|
|
9
|
+
dir: dirName;
|
|
10
|
+
name: fileName;
|
|
11
|
+
};
|
|
12
|
+
rule: Array<{
|
|
13
|
+
reg: RegExp;
|
|
14
|
+
fnc: string;
|
|
15
|
+
}>;
|
|
16
|
+
}>;
|
|
17
|
+
add({ name, dir, App, Class }: {
|
|
18
|
+
dir: dirName;
|
|
19
|
+
name: fileName;
|
|
20
|
+
App: new () => Plugin;
|
|
21
|
+
Class: Plugin;
|
|
22
|
+
}): void;
|
|
23
|
+
/**
|
|
24
|
+
* 卸载按钮
|
|
25
|
+
* @param {string} dir 插件目录
|
|
26
|
+
* @param {string} name 插件文件名称
|
|
27
|
+
*/
|
|
28
|
+
del(dir: dirName, name: fileName): {
|
|
29
|
+
App: new () => Plugin;
|
|
30
|
+
name: string;
|
|
31
|
+
priority: number;
|
|
32
|
+
file: {
|
|
33
|
+
dir: dirName;
|
|
34
|
+
name: fileName;
|
|
35
|
+
};
|
|
36
|
+
rule: Array<{
|
|
37
|
+
reg: RegExp;
|
|
38
|
+
fnc: string;
|
|
39
|
+
}>;
|
|
40
|
+
}[];
|
|
41
|
+
update({ dir, name, App, Class }: {
|
|
42
|
+
dir: dirName;
|
|
43
|
+
name: fileName;
|
|
44
|
+
App: new () => Plugin;
|
|
45
|
+
Class: Plugin;
|
|
46
|
+
}): void;
|
|
47
|
+
get(e: KarinMessage): Promise<any[]>;
|
|
48
|
+
};
|
|
49
|
+
export default _default;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import lodash from 'lodash'
|
|
2
|
+
import logger from './logger.js'
|
|
3
|
+
export default new (class Button {
|
|
4
|
+
Apps
|
|
5
|
+
constructor () {
|
|
6
|
+
this.Apps = []
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
add ({ name, dir, App, Class }) {
|
|
10
|
+
const rule = []
|
|
11
|
+
/** 创建正则表达式 */
|
|
12
|
+
for (const v of Class.button) {
|
|
13
|
+
try {
|
|
14
|
+
const { reg, fnc } = v
|
|
15
|
+
rule.push({ reg: new RegExp(reg), fnc })
|
|
16
|
+
} catch (error) {
|
|
17
|
+
logger.error(error)
|
|
18
|
+
continue
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
this.Apps.push({
|
|
22
|
+
App,
|
|
23
|
+
name: Class.name,
|
|
24
|
+
priority: Class.priority,
|
|
25
|
+
file: { name, dir },
|
|
26
|
+
rule,
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 卸载按钮
|
|
32
|
+
* @param {string} dir 插件目录
|
|
33
|
+
* @param {string} name 插件文件名称
|
|
34
|
+
*/
|
|
35
|
+
del (dir, name) {
|
|
36
|
+
/** 未传入name则删除所有 */
|
|
37
|
+
if (!name) {
|
|
38
|
+
this.Apps = this.Apps.filter(v => v.file.dir !== dir)
|
|
39
|
+
} else {
|
|
40
|
+
/** 传入name则删除指定 */
|
|
41
|
+
this.Apps = this.Apps.filter(v => v.file.dir !== dir || v.file.name !== name)
|
|
42
|
+
}
|
|
43
|
+
/** 排序 */
|
|
44
|
+
this.Apps = lodash.orderBy(this.Apps, ['priority'], ['asc'])
|
|
45
|
+
return this.Apps
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
update ({ dir, name, App, Class }) {
|
|
49
|
+
this.del(dir, name)
|
|
50
|
+
this.add({ name, dir, App, Class })
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async get (e) {
|
|
54
|
+
const button = []
|
|
55
|
+
for (const app of this.Apps) {
|
|
56
|
+
for (const v of app.rule) {
|
|
57
|
+
/** 这里的lastIndex是为了防止正则无法从头开始匹配 */
|
|
58
|
+
v.reg.lastIndex = 0
|
|
59
|
+
if (v.reg.test(e.msg)) {
|
|
60
|
+
try {
|
|
61
|
+
const App = new app.App()
|
|
62
|
+
App.e = e
|
|
63
|
+
const res = await App[v.fnc](e)
|
|
64
|
+
if (!res) { continue }
|
|
65
|
+
/** 是否继续循环 */
|
|
66
|
+
const cycle = res.cycle ?? true
|
|
67
|
+
delete res.cycle
|
|
68
|
+
button.push(res)
|
|
69
|
+
if (cycle !== false) { return button }
|
|
70
|
+
} catch (error) {
|
|
71
|
+
logger.error(error)
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/** 理论上不会走到这里,但是还是要稳一手,不排除有所有插件都false... */
|
|
77
|
+
return button
|
|
78
|
+
}
|
|
79
|
+
})()
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import { AxiosRequestConfig } from 'axios';
|
|
4
|
+
import { Readable } from 'stream';
|
|
5
|
+
import { KarinElement, KarinNodeElement } from '../types/element.js';
|
|
6
|
+
import { dirName } from '../types/plugin.js';
|
|
7
|
+
/**
|
|
8
|
+
* 常用方法
|
|
9
|
+
*/
|
|
10
|
+
declare const _default: {
|
|
11
|
+
streamPipeline: (stream1: Readable, stream2: fs.WriteStream) => Promise<void>;
|
|
12
|
+
/**
|
|
13
|
+
* 休眠函数
|
|
14
|
+
* @param ms 毫秒
|
|
15
|
+
*/
|
|
16
|
+
sleep(ms: number): Promise<unknown>;
|
|
17
|
+
/**
|
|
18
|
+
* 下载保存文件
|
|
19
|
+
* @param fileUrl 下载地址
|
|
20
|
+
* @param savePath 保存路径
|
|
21
|
+
* @param param axios参数
|
|
22
|
+
*/
|
|
23
|
+
downFile(fileUrl: string, savePath: string, param?: AxiosRequestConfig): Promise<boolean>;
|
|
24
|
+
/**
|
|
25
|
+
* 递归创建目录
|
|
26
|
+
* @param dirname - 要创建的文件夹路径
|
|
27
|
+
*/
|
|
28
|
+
mkdir(dirname: string): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* 标准化文件路径
|
|
31
|
+
* @param file - 相对路径
|
|
32
|
+
* @param isDir - 返回绝对路径
|
|
33
|
+
* @param isFile - 添加file://前缀
|
|
34
|
+
* @returns 标准化后的路径
|
|
35
|
+
*/
|
|
36
|
+
absPath(file: string, isDir?: boolean, isFile?: boolean): string;
|
|
37
|
+
/**
|
|
38
|
+
* 判断是否为文件夹
|
|
39
|
+
* @param path - 路径
|
|
40
|
+
* @returns 返回true为文件夹
|
|
41
|
+
*/
|
|
42
|
+
isDir(path: string): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* 判断是否为插件包
|
|
45
|
+
* @param path - 路径
|
|
46
|
+
* @returns 返回true为插件包
|
|
47
|
+
*/
|
|
48
|
+
isPlugin(path: string): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* 判断路径是否存在
|
|
51
|
+
* @param path - 路径
|
|
52
|
+
* @returns 返回true为存在
|
|
53
|
+
*/
|
|
54
|
+
exists(path: string): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* 根据文件后缀名从指定路径下读取符合要求的文件
|
|
57
|
+
* @param path - 路径
|
|
58
|
+
* @param ext - 后缀名、或后缀名列表
|
|
59
|
+
* @example common.readDir('./plugins', '.js')
|
|
60
|
+
* @example common.readDir('./plugins', ['.js', '.ts'])
|
|
61
|
+
*/
|
|
62
|
+
readDir(_path: string, ext: string | string[]): string[] | null;
|
|
63
|
+
/**
|
|
64
|
+
* 传入 import.meta.url 自动构建../
|
|
65
|
+
* @param url - import.meta.url
|
|
66
|
+
*/
|
|
67
|
+
urlToPath(url: string): string;
|
|
68
|
+
/**
|
|
69
|
+
* 将文件转换为不带前缀的base64字符串
|
|
70
|
+
* @param file - 文件路径或Buffer对象、可读流对象、http地址、base64://字符串
|
|
71
|
+
* @param - 附加数据
|
|
72
|
+
* @param - 为true时,http地址会直接返回,否则会下载文件并转换为base64字符串
|
|
73
|
+
* @returns 返回base64字符串
|
|
74
|
+
*/
|
|
75
|
+
base64(file: string | Buffer | Readable, options?: {
|
|
76
|
+
http: boolean;
|
|
77
|
+
}): Promise<string>;
|
|
78
|
+
/**
|
|
79
|
+
* 将数据流对象转换为Buffer对象
|
|
80
|
+
* @param {stream.Readable} stream - 要转换的数据流对象
|
|
81
|
+
* @returns {Promise<Buffer>} - 返回Buffer
|
|
82
|
+
*/
|
|
83
|
+
stream(stream: Readable): Promise<Buffer>;
|
|
84
|
+
/**
|
|
85
|
+
* 将文件转换为Buffer对象
|
|
86
|
+
* @param {string|Buffer|http|stream.Readable} file - 文件路径或Buffer对象、可读流对象、http地址、base64://字符串
|
|
87
|
+
* @param {object} options - 附加数据
|
|
88
|
+
* @param {boolean} options.http - 为true时,http地址会直接返回,否则会下载文件并转换为Buffer对象
|
|
89
|
+
* @returns {Promise<Buffer>} - 返回Buffer对象
|
|
90
|
+
*/
|
|
91
|
+
buffer(file: string | Buffer | Readable, options?: {
|
|
92
|
+
http: boolean;
|
|
93
|
+
}): Promise<Buffer | Error | string>;
|
|
94
|
+
/**
|
|
95
|
+
* 标准化发送的消息内容
|
|
96
|
+
* @param elements - 消息内容
|
|
97
|
+
*/
|
|
98
|
+
makeMessage(elements: string | KarinElement | (string | KarinElement)[]): Array<KarinElement>;
|
|
99
|
+
/**
|
|
100
|
+
* 制作简单转发,返回segment.node[]。仅简单包装node,也可以自己组装
|
|
101
|
+
* @param {Array<{object}> | object} elements
|
|
102
|
+
* @param fakeUin 用户id
|
|
103
|
+
* @param fakeNick 用户昵称
|
|
104
|
+
* @return {Array<KarinNodeElement>}
|
|
105
|
+
*/
|
|
106
|
+
makeForward(elements: KarinElement | KarinElement[], fakeUin: string, fakeNick: string): Array<KarinNodeElement>;
|
|
107
|
+
/**
|
|
108
|
+
* 获取所有插件列表
|
|
109
|
+
* @param isDir - 返回绝对路径
|
|
110
|
+
* @param isPack - 屏蔽不带packageon的插件
|
|
111
|
+
*/
|
|
112
|
+
getPlugins(isDir?: boolean, isPack?: boolean): Array<dirName>;
|
|
113
|
+
/**
|
|
114
|
+
* 获取运行时间
|
|
115
|
+
*/
|
|
116
|
+
uptime(): string;
|
|
117
|
+
/**
|
|
118
|
+
* 构建消息体日志
|
|
119
|
+
* @param - 消息体
|
|
120
|
+
*/
|
|
121
|
+
makeMessageLog(message: Array<KarinElement>): string;
|
|
122
|
+
};
|
|
123
|
+
export default _default;
|