alemonjs 1.0.26 → 1.0.28
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/bin/main.js +2 -2
- package/lib/core/apps.js +3 -3
- package/lib/core/dealmsg.js +1 -1
- package/lib/core/ip.js +1 -1
- package/lib/core/puppeteer.js +44 -86
- package/lib/core/screenshot.js +0 -1
- package/lib/login.js +1 -1
- package/lib/run.js +2 -2
- package/package.json +71 -71
- package/types/core/screenshot.d.ts +0 -1
package/bin/main.js
CHANGED
|
@@ -9,13 +9,13 @@ const files = msg.match(/(\S+\.js|\S+\.ts)/g) ?? ['alemon.config.ts']
|
|
|
9
9
|
const argsWithoutFiles = msg.replace(/(\S+\.js|\S+\.ts)/g, '')
|
|
10
10
|
for (const item of files) {
|
|
11
11
|
if (!existsSync(join(process.cwd(), item))) {
|
|
12
|
-
console.
|
|
12
|
+
console.info('[NO FILE]', item)
|
|
13
13
|
continue
|
|
14
14
|
}
|
|
15
15
|
const isTypeScript = item.endsWith('.ts')
|
|
16
16
|
const command = isTypeScript ? 'npx ts-node' : 'node'
|
|
17
17
|
const cmd = `${command} ${item} ${argsWithoutFiles}`
|
|
18
|
-
console.
|
|
18
|
+
console.info('[alemonjs]', cmd)
|
|
19
19
|
const childProcess = spawn(cmd, { shell: true })
|
|
20
20
|
childProcess.stdout.on('data', data => {
|
|
21
21
|
process.stdout.write(data.toString())
|
package/lib/core/apps.js
CHANGED
|
@@ -52,7 +52,7 @@ export function createApp(AppName) {
|
|
|
52
52
|
return true;
|
|
53
53
|
}
|
|
54
54
|
catch (err) {
|
|
55
|
-
console.error(err);
|
|
55
|
+
console.error('[AlemonJS]重定义消息', err);
|
|
56
56
|
return false;
|
|
57
57
|
}
|
|
58
58
|
},
|
|
@@ -100,7 +100,7 @@ export function createApp(AppName) {
|
|
|
100
100
|
return true;
|
|
101
101
|
}
|
|
102
102
|
catch (err) {
|
|
103
|
-
console.error(err);
|
|
103
|
+
console.error('[AlemonJS]插件解析', err);
|
|
104
104
|
return false;
|
|
105
105
|
}
|
|
106
106
|
},
|
|
@@ -113,7 +113,7 @@ export function createApp(AppName) {
|
|
|
113
113
|
setApp(AppName, apps);
|
|
114
114
|
}
|
|
115
115
|
catch (err) {
|
|
116
|
-
console.error(err);
|
|
116
|
+
console.error('[AlemonJS]应用挂起', err);
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
};
|
package/lib/core/dealmsg.js
CHANGED
|
@@ -178,7 +178,7 @@ async function loadPlugins(dir) {
|
|
|
178
178
|
if (existsSync(`${dir}/${appname}${main}.${type}`)) {
|
|
179
179
|
await import(`file://${dir}/${appname}${main}.${type}`).catch(err => {
|
|
180
180
|
console.error(`file://${dir}/${appname}${main}.${type}`);
|
|
181
|
-
console.error(err);
|
|
181
|
+
console.error('[AlemonJS]加载出错', err);
|
|
182
182
|
process.exit();
|
|
183
183
|
});
|
|
184
184
|
}
|
package/lib/core/ip.js
CHANGED
package/lib/core/puppeteer.js
CHANGED
|
@@ -16,18 +16,6 @@ let browser;
|
|
|
16
16
|
* 实例控制
|
|
17
17
|
*/
|
|
18
18
|
let isBrowser = false;
|
|
19
|
-
/**
|
|
20
|
-
* 对每个页面进行缓存
|
|
21
|
-
*/
|
|
22
|
-
const pageCache = {};
|
|
23
|
-
/**
|
|
24
|
-
* 清除缓存
|
|
25
|
-
*/
|
|
26
|
-
function delCache() {
|
|
27
|
-
for (const item in pageCache) {
|
|
28
|
-
delete pageCache[item];
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
19
|
/**
|
|
32
20
|
* 实例配置
|
|
33
21
|
*/
|
|
@@ -72,9 +60,10 @@ export async function pupStartCheck() {
|
|
|
72
60
|
*/
|
|
73
61
|
pic = 0;
|
|
74
62
|
console.info('[puppeteer] close');
|
|
75
|
-
delCache();
|
|
76
63
|
isBrowser = false;
|
|
77
|
-
browser.close().catch(err =>
|
|
64
|
+
browser.close().catch(err => {
|
|
65
|
+
console.error('[AlemonJS]pup关闭错误', err);
|
|
66
|
+
});
|
|
78
67
|
console.info('[puppeteer] reopen');
|
|
79
68
|
if (!(await startChrom()))
|
|
80
69
|
return false;
|
|
@@ -98,43 +87,29 @@ export async function screenshotByFile(htmlPath, Options) {
|
|
|
98
87
|
}
|
|
99
88
|
const { SOptions, tab = 'body', timeout = 120000 } = Options;
|
|
100
89
|
try {
|
|
101
|
-
/**
|
|
102
|
-
* 实例化
|
|
103
|
-
*/
|
|
104
90
|
const page = await browser.newPage();
|
|
105
|
-
/**
|
|
106
|
-
* 挂载网页
|
|
107
|
-
*/
|
|
108
91
|
await page.goto(`file://${htmlPath}`, {
|
|
109
92
|
timeout
|
|
110
93
|
});
|
|
111
|
-
/**
|
|
112
|
-
* 获取元素
|
|
113
|
-
*/
|
|
114
94
|
const body = await page.$(tab);
|
|
115
|
-
/**
|
|
116
|
-
* 得到图片
|
|
117
|
-
*/
|
|
118
95
|
console.info('[puppeteer] success');
|
|
119
96
|
const buff = await body
|
|
120
97
|
.screenshot(SOptions)
|
|
121
98
|
.catch(err => {
|
|
122
|
-
console.error(err);
|
|
99
|
+
console.error('[AlemonJS]pup截图错误', err);
|
|
123
100
|
return false;
|
|
124
101
|
});
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* 空的
|
|
131
|
-
*/
|
|
132
|
-
if (!buff)
|
|
102
|
+
await page.close().catch((err) => {
|
|
103
|
+
console.error('[AlemonJS]page关闭错误', err);
|
|
104
|
+
});
|
|
105
|
+
if (!buff) {
|
|
133
106
|
console.error('[puppeteer]', htmlPath);
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
134
109
|
return buff;
|
|
135
110
|
}
|
|
136
111
|
catch (err) {
|
|
137
|
-
console.error(err);
|
|
112
|
+
console.error('[AlemonJS]page实例化错误', err);
|
|
138
113
|
return false;
|
|
139
114
|
}
|
|
140
115
|
}
|
|
@@ -149,55 +124,41 @@ export async function screenshotByUrl(val) {
|
|
|
149
124
|
return false;
|
|
150
125
|
}
|
|
151
126
|
const { url, time, rand, params, tab, cache } = val;
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
127
|
+
try {
|
|
128
|
+
const page = await browser.newPage();
|
|
129
|
+
const query = queryString.stringify(params ?? {});
|
|
130
|
+
const isurl = params == undefined ? url : `${url}?${query}`;
|
|
131
|
+
await page.setCacheEnabled(cache == undefined ? true : cache);
|
|
132
|
+
await page.goto(isurl);
|
|
133
|
+
console.info(`open ${isurl}`);
|
|
134
|
+
const body = await page.$(tab ?? 'body');
|
|
135
|
+
if (!body) {
|
|
136
|
+
await page.close();
|
|
137
|
+
console.error('[AlemonJS]tab 获取失败');
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
await new Promise(resolve => setTimeout(resolve, time ?? 1000));
|
|
141
|
+
const buff = await body
|
|
142
|
+
.screenshot(rand ?? {
|
|
143
|
+
type: 'jpeg',
|
|
144
|
+
quality: 90,
|
|
145
|
+
path: ''
|
|
146
|
+
})
|
|
147
|
+
.catch(err => {
|
|
148
|
+
console.error('[AlemonJS]page截图错误', err);
|
|
149
|
+
return false;
|
|
150
|
+
});
|
|
151
|
+
await page.close();
|
|
152
|
+
if (!buff) {
|
|
153
|
+
console.error('[AlemonJS]buff截图错误', url);
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
return buff;
|
|
173
157
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
*/
|
|
177
|
-
await new Promise(resolve => setTimeout(resolve, time ?? 1000));
|
|
178
|
-
/**
|
|
179
|
-
* 截图
|
|
180
|
-
*/
|
|
181
|
-
const buff = await body
|
|
182
|
-
.screenshot(rand ?? {
|
|
183
|
-
type: 'jpeg',
|
|
184
|
-
quality: 90,
|
|
185
|
-
path: ''
|
|
186
|
-
})
|
|
187
|
-
.catch(err => {
|
|
188
|
-
console.error(err);
|
|
158
|
+
catch (err) {
|
|
159
|
+
console.error('[AlemonJS]page实例化错误', err);
|
|
189
160
|
return false;
|
|
190
|
-
});
|
|
191
|
-
/**
|
|
192
|
-
* 打印错误
|
|
193
|
-
*/
|
|
194
|
-
if (!buff) {
|
|
195
|
-
// 确保页面已经不再使用后再删除
|
|
196
|
-
await pageCache[url].close();
|
|
197
|
-
delete pageCache[url];
|
|
198
|
-
console.error(`buff err:${url}`);
|
|
199
161
|
}
|
|
200
|
-
return buff;
|
|
201
162
|
}
|
|
202
163
|
/**
|
|
203
164
|
* 启动浏览器
|
|
@@ -207,15 +168,12 @@ export async function startChrom() {
|
|
|
207
168
|
try {
|
|
208
169
|
browser = await puppeteer.launch(LaunchCfg);
|
|
209
170
|
isBrowser = true;
|
|
210
|
-
delCache();
|
|
211
171
|
console.info('[puppeteer] open success');
|
|
212
172
|
return true;
|
|
213
173
|
}
|
|
214
174
|
catch (err) {
|
|
215
|
-
console.error(err);
|
|
216
175
|
isBrowser = false;
|
|
217
|
-
|
|
218
|
-
console.error('[puppeteer] open fail');
|
|
176
|
+
console.error('[puppeteer] 打开错误', err);
|
|
219
177
|
return false;
|
|
220
178
|
}
|
|
221
179
|
}
|
package/lib/core/screenshot.js
CHANGED
package/lib/login.js
CHANGED
package/lib/run.js
CHANGED
|
@@ -7,13 +7,13 @@ export function commandRun(ars) {
|
|
|
7
7
|
const argsWithoutFiles = msg.replace(/(\S+\.js|\S+\.ts)/g, '');
|
|
8
8
|
for (const item of files) {
|
|
9
9
|
if (!existsSync(join(process.cwd(), item))) {
|
|
10
|
-
console.
|
|
10
|
+
console.info('[NO FILE]', item);
|
|
11
11
|
continue;
|
|
12
12
|
}
|
|
13
13
|
const isTypeScript = item.endsWith('.ts');
|
|
14
14
|
const command = isTypeScript ? 'npx ts-node' : 'node';
|
|
15
15
|
const cmd = `${command} ${item} ${argsWithoutFiles}`;
|
|
16
|
-
console.
|
|
16
|
+
console.info('[alemonjs]', cmd);
|
|
17
17
|
const childProcess = spawn(cmd, { shell: true });
|
|
18
18
|
childProcess.stdout.on('data', data => {
|
|
19
19
|
process.stdout.write(data.toString());
|
package/package.json
CHANGED
|
@@ -1,72 +1,72 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "alemonjs",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "docs https://alemonjs.com/",
|
|
5
|
-
"author": "ningmengchongshui",
|
|
6
|
-
"license": "GPL-2.0",
|
|
7
|
-
"type": "module",
|
|
8
|
-
"scripts": {
|
|
9
|
-
"tsc": "npx tsc",
|
|
10
|
-
"format": "prettier --write .",
|
|
11
|
-
"lint": "eslint . --ext .js,.ts --fix --ignore-path .gitignore"
|
|
12
|
-
},
|
|
13
|
-
"dependencies": {
|
|
14
|
-
"@discordjs/builders": "^1.6.3",
|
|
15
|
-
"@discordjs/core": "^0.6.0",
|
|
16
|
-
"@discordjs/rest": "^1.7.1",
|
|
17
|
-
"axios": "^1.4.0",
|
|
18
|
-
"discord.js": "^14.11.0",
|
|
19
|
-
"image-size": "^1.0.2",
|
|
20
|
-
"kook-ws": "^1.0.4",
|
|
21
|
-
"lodash": "^4.17.21",
|
|
22
|
-
"mys-villa": "^1.1.8",
|
|
23
|
-
"public-ip": "^6.0.1",
|
|
24
|
-
"puppeteer": "^20.7.1",
|
|
25
|
-
"qq-channel": "^1.0.0",
|
|
26
|
-
"qq-guild-bot": "^2.9.5",
|
|
27
|
-
"qrcode": "^1.5.3"
|
|
28
|
-
},
|
|
29
|
-
"devDependencies": {
|
|
30
|
-
"@types/lodash": "^4.14.186",
|
|
31
|
-
"@types/node": "^20.2.4",
|
|
32
|
-
"@types/progress": "^2.0.5",
|
|
33
|
-
"@types/qrcode": "^1.5.0",
|
|
34
|
-
"@types/ws": "^8.5.5",
|
|
35
|
-
"@typescript-eslint/eslint-plugin": "^5.60.0",
|
|
36
|
-
"@typescript-eslint/parser": "^5.60.0",
|
|
37
|
-
"eslint": "^8.43.0",
|
|
38
|
-
"eslint-config-prettier": "^8.8.0",
|
|
39
|
-
"eslint-plugin-prettier": "^4.2.1",
|
|
40
|
-
"prettier": "^2.8.8",
|
|
41
|
-
"ts-node": "^10.9.1",
|
|
42
|
-
"typescript": ">=5.0.4 <5.1.0"
|
|
43
|
-
},
|
|
44
|
-
"types": "types",
|
|
45
|
-
"main": "lib/index.js",
|
|
46
|
-
"files": [
|
|
47
|
-
"bin",
|
|
48
|
-
"lib",
|
|
49
|
-
"types",
|
|
50
|
-
"run.js",
|
|
51
|
-
"run.d.ts"
|
|
52
|
-
],
|
|
53
|
-
"exports": {
|
|
54
|
-
".": {
|
|
55
|
-
"import": "./lib/index.js",
|
|
56
|
-
"types": "./types/index.d.ts"
|
|
57
|
-
},
|
|
58
|
-
"./run": {
|
|
59
|
-
"import": "./run.js",
|
|
60
|
-
"types": "./run.d.ts"
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
"bin": {
|
|
64
|
-
"alemonjs": "bin/main.js"
|
|
65
|
-
},
|
|
66
|
-
"publishConfig": {
|
|
67
|
-
"registry": "https://registry.npmjs.org"
|
|
68
|
-
},
|
|
69
|
-
"engines": {
|
|
70
|
-
"node": ">=16.14.0"
|
|
71
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "alemonjs",
|
|
3
|
+
"version": "1.0.28",
|
|
4
|
+
"description": "docs https://alemonjs.com/",
|
|
5
|
+
"author": "ningmengchongshui",
|
|
6
|
+
"license": "GPL-2.0",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"tsc": "npx tsc",
|
|
10
|
+
"format": "prettier --write .",
|
|
11
|
+
"lint": "eslint . --ext .js,.ts --fix --ignore-path .gitignore"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@discordjs/builders": "^1.6.3",
|
|
15
|
+
"@discordjs/core": "^0.6.0",
|
|
16
|
+
"@discordjs/rest": "^1.7.1",
|
|
17
|
+
"axios": "^1.4.0",
|
|
18
|
+
"discord.js": "^14.11.0",
|
|
19
|
+
"image-size": "^1.0.2",
|
|
20
|
+
"kook-ws": "^1.0.4",
|
|
21
|
+
"lodash": "^4.17.21",
|
|
22
|
+
"mys-villa": "^1.1.8",
|
|
23
|
+
"public-ip": "^6.0.1",
|
|
24
|
+
"puppeteer": "^20.7.1",
|
|
25
|
+
"qq-channel": "^1.0.0",
|
|
26
|
+
"qq-guild-bot": "^2.9.5",
|
|
27
|
+
"qrcode": "^1.5.3"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/lodash": "^4.14.186",
|
|
31
|
+
"@types/node": "^20.2.4",
|
|
32
|
+
"@types/progress": "^2.0.5",
|
|
33
|
+
"@types/qrcode": "^1.5.0",
|
|
34
|
+
"@types/ws": "^8.5.5",
|
|
35
|
+
"@typescript-eslint/eslint-plugin": "^5.60.0",
|
|
36
|
+
"@typescript-eslint/parser": "^5.60.0",
|
|
37
|
+
"eslint": "^8.43.0",
|
|
38
|
+
"eslint-config-prettier": "^8.8.0",
|
|
39
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
40
|
+
"prettier": "^2.8.8",
|
|
41
|
+
"ts-node": "^10.9.1",
|
|
42
|
+
"typescript": ">=5.0.4 <5.1.0"
|
|
43
|
+
},
|
|
44
|
+
"types": "types",
|
|
45
|
+
"main": "lib/index.js",
|
|
46
|
+
"files": [
|
|
47
|
+
"bin",
|
|
48
|
+
"lib",
|
|
49
|
+
"types",
|
|
50
|
+
"run.js",
|
|
51
|
+
"run.d.ts"
|
|
52
|
+
],
|
|
53
|
+
"exports": {
|
|
54
|
+
".": {
|
|
55
|
+
"import": "./lib/index.js",
|
|
56
|
+
"types": "./types/index.d.ts"
|
|
57
|
+
},
|
|
58
|
+
"./run": {
|
|
59
|
+
"import": "./run.js",
|
|
60
|
+
"types": "./run.d.ts"
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
"bin": {
|
|
64
|
+
"alemonjs": "bin/main.js"
|
|
65
|
+
},
|
|
66
|
+
"publishConfig": {
|
|
67
|
+
"registry": "https://registry.npmjs.org"
|
|
68
|
+
},
|
|
69
|
+
"engines": {
|
|
70
|
+
"node": ">=16.14.0"
|
|
71
|
+
}
|
|
72
72
|
}
|