alemonjs 1.0.5 → 1.0.7
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/alemon/dealmsg.js +14 -12
- package/lib/default/pup.js +1 -2
- package/lib/define/main.js +15 -0
- package/lib/define/plugin.js +61 -21
- package/package.json +1 -1
- package/types/alemon/dealmsg.d.ts +8 -0
- package/types/define/plugin.d.ts +2 -1
package/lib/alemon/dealmsg.js
CHANGED
|
@@ -49,6 +49,16 @@ export function setAppRegex(val) {
|
|
|
49
49
|
appRegexClose = RegexClose;
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* 得到插件名匹配模式
|
|
54
|
+
* @returns
|
|
55
|
+
*/
|
|
56
|
+
export function getAppRegex() {
|
|
57
|
+
return {
|
|
58
|
+
RegexOpen: appRegex,
|
|
59
|
+
RegexClose: appRegexClose
|
|
60
|
+
};
|
|
61
|
+
}
|
|
52
62
|
/**
|
|
53
63
|
* 设置指令json地址
|
|
54
64
|
* @param rt '/public/defset'
|
|
@@ -197,22 +207,14 @@ async function synthesis(AppsObj, appname, belong) {
|
|
|
197
207
|
* @param dir
|
|
198
208
|
*/
|
|
199
209
|
async function loadPlugins(dir) {
|
|
200
|
-
|
|
201
|
-
* ********************
|
|
202
|
-
* 没有该文件夹直接返回
|
|
203
|
-
* *******************
|
|
204
|
-
*/
|
|
205
|
-
if (!existsSync(dir)) {
|
|
210
|
+
if (!existsSync(dir))
|
|
206
211
|
return;
|
|
207
|
-
}
|
|
208
212
|
const flies = readdirSync(dir);
|
|
209
|
-
if (flies.length == 0)
|
|
213
|
+
if (flies.length == 0)
|
|
210
214
|
return;
|
|
211
|
-
|
|
212
|
-
const app = flies
|
|
215
|
+
const apps = flies
|
|
213
216
|
.filter(item => appRegex.test(item))
|
|
214
217
|
.filter(item => {
|
|
215
|
-
// 关闭符合条件的
|
|
216
218
|
if (!appRegexClose) {
|
|
217
219
|
return true;
|
|
218
220
|
}
|
|
@@ -224,7 +226,7 @@ async function loadPlugins(dir) {
|
|
|
224
226
|
/**
|
|
225
227
|
* 识别并执行插件
|
|
226
228
|
*/
|
|
227
|
-
for await (const appname of
|
|
229
|
+
for await (const appname of apps) {
|
|
228
230
|
if (existsSync(`${dir}/${appname}/index.ts`)) {
|
|
229
231
|
/**
|
|
230
232
|
* 优先考虑ts
|
package/lib/default/pup.js
CHANGED
package/lib/define/main.js
CHANGED
|
@@ -5,6 +5,8 @@ import { nodeScripts } from './child_process.js';
|
|
|
5
5
|
import { ClientAPIByQQ as ClientByNTQQ } from '../ntqq/sdk/index.js';
|
|
6
6
|
import { createApp, loadInit, setBotConfigByKey, setLanchConfig, getPupPath, getBotConfigByKey, setAppRegex } from '../index.js';
|
|
7
7
|
import { command } from './command.js';
|
|
8
|
+
import { copyAppsFile } from './plugin.js';
|
|
9
|
+
import { join } from 'path';
|
|
8
10
|
// 设置ntqq独立鉴权路径
|
|
9
11
|
export const setAuthenticationByNtqq = ClientByNTQQ.setAuthentication;
|
|
10
12
|
let appDir = 'application';
|
|
@@ -115,6 +117,11 @@ export async function defineAlemonConfig(Options) {
|
|
|
115
117
|
await rebotMap[item]();
|
|
116
118
|
}
|
|
117
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* ********
|
|
122
|
+
* 登录提示
|
|
123
|
+
* ********
|
|
124
|
+
*/
|
|
118
125
|
if (!Options?.login || Object.keys(Options?.login ?? {}).length == 0) {
|
|
119
126
|
console.info('[LOGIN] 无登录配置');
|
|
120
127
|
}
|
|
@@ -140,6 +147,14 @@ export async function defineAlemonConfig(Options) {
|
|
|
140
147
|
RegexClose: Options?.plugin?.RegexClose
|
|
141
148
|
});
|
|
142
149
|
}
|
|
150
|
+
/**
|
|
151
|
+
* ***************
|
|
152
|
+
* 是否同步文件
|
|
153
|
+
* ***************
|
|
154
|
+
*/
|
|
155
|
+
if (Options?.plugin?.mountFile) {
|
|
156
|
+
copyAppsFile(join(process.cwd(), `/${address}`));
|
|
157
|
+
}
|
|
143
158
|
/**
|
|
144
159
|
* ************
|
|
145
160
|
* 扫描插件
|
package/lib/define/plugin.js
CHANGED
|
@@ -1,25 +1,65 @@
|
|
|
1
|
+
import { existsSync, readdirSync, copyFileSync, mkdirSync } from 'fs';
|
|
2
|
+
import { getAppRegex } from '../alemon/index.js';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
/**
|
|
5
|
+
* 遍历复制方法
|
|
6
|
+
*/
|
|
7
|
+
const copyFiles = (source, destination) => {
|
|
8
|
+
if (!existsSync(destination)) {
|
|
9
|
+
mkdirSync(destination, { recursive: true });
|
|
10
|
+
}
|
|
11
|
+
const files = readdirSync(source);
|
|
12
|
+
for (const file of files) {
|
|
13
|
+
const sourcePath = join(source, file);
|
|
14
|
+
const destinationPath = join(destination, file);
|
|
15
|
+
copyFileSync(sourcePath, destinationPath);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
1
18
|
/**
|
|
2
19
|
* 同步挂载文件
|
|
20
|
+
* @param dir 插件目录
|
|
3
21
|
*/
|
|
4
|
-
export function copyAppsFile() {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
export function copyAppsFile(dir) {
|
|
23
|
+
if (!existsSync(dir))
|
|
24
|
+
return;
|
|
25
|
+
const flies = readdirSync(dir);
|
|
26
|
+
if (flies.length === 0)
|
|
27
|
+
return;
|
|
28
|
+
const { RegexOpen, RegexClose } = getAppRegex();
|
|
29
|
+
// 插件名
|
|
30
|
+
const apps = flies
|
|
31
|
+
.filter(item => RegexOpen.test(item))
|
|
32
|
+
.filter(item => {
|
|
33
|
+
// 关闭符合条件的
|
|
34
|
+
if (!RegexClose) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
if (RegexClose.test(item)) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
return true;
|
|
41
|
+
});
|
|
42
|
+
for (const appname of apps) {
|
|
43
|
+
const appPath = join(dir, appname);
|
|
44
|
+
if (existsSync(`${appPath}/assets`)) {
|
|
45
|
+
const originalAddress = `${appPath}/assets`;
|
|
46
|
+
const destinationAddress = join(process.cwd(), `/assets/.${appname}/assets`);
|
|
47
|
+
copyFiles(originalAddress, destinationAddress);
|
|
48
|
+
}
|
|
49
|
+
if (existsSync(`${appPath}/pages`)) {
|
|
50
|
+
const originalAddress = `${appPath}/pages`;
|
|
51
|
+
const destinationAddress = join(process.cwd(), `/pages/.${appname}/pages`);
|
|
52
|
+
copyFiles(originalAddress, destinationAddress);
|
|
53
|
+
}
|
|
54
|
+
if (existsSync(`${appPath}/plugins`)) {
|
|
55
|
+
const originalAddress = `${appPath}/plugins`;
|
|
56
|
+
const destinationAddress = join(process.cwd(), `/plugins/.${appname}/plugins`);
|
|
57
|
+
copyFiles(originalAddress, destinationAddress);
|
|
58
|
+
}
|
|
59
|
+
if (existsSync(`${appPath}/server`)) {
|
|
60
|
+
const originalAddress = `${appPath}/server`;
|
|
61
|
+
const destinationAddress = join(process.cwd(), `/server/.${appname}/server`);
|
|
62
|
+
copyFiles(originalAddress, destinationAddress);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
25
65
|
}
|
package/package.json
CHANGED
|
@@ -8,6 +8,14 @@ interface RegexControl {
|
|
|
8
8
|
* @param val
|
|
9
9
|
*/
|
|
10
10
|
export declare function setAppRegex(val: RegexControl): void;
|
|
11
|
+
/**
|
|
12
|
+
* 得到插件名匹配模式
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
15
|
+
export declare function getAppRegex(): {
|
|
16
|
+
RegexOpen: RegExp;
|
|
17
|
+
RegexClose: RegExp;
|
|
18
|
+
};
|
|
11
19
|
/**
|
|
12
20
|
* 设置指令json地址
|
|
13
21
|
* @param rt '/public/defset'
|
package/types/define/plugin.d.ts
CHANGED