alemonjs 1.1.0 → 1.1.2
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/index.js +4 -0
- package/lib/one/alemon/message/MESSAGES.js +1 -1
- package/lib/utils.js +62 -0
- package/lib/villa/alemon/controller.js +1 -1
- package/logs.d.ts +1 -1
- package/logs.js +16 -16
- package/package.json +3 -4
- package/run.d.ts +1 -1
- package/run.js +22 -22
- package/types/index.d.ts +4 -0
- package/types/utils.d.ts +20 -0
package/lib/index.js
CHANGED
|
@@ -58,7 +58,7 @@ export async function MESSAGES(event) {
|
|
|
58
58
|
*/
|
|
59
59
|
reply: async (msg, select) => {
|
|
60
60
|
if (select?.open_id && select?.open_id != '') {
|
|
61
|
-
return await directController(msg, select
|
|
61
|
+
return await directController(msg, select?.open_id);
|
|
62
62
|
}
|
|
63
63
|
const guild_id = select?.guild_id ?? event.group_id;
|
|
64
64
|
return await replyController(msg, guild_id);
|
package/lib/utils.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Villa按钮自动排咧
|
|
3
|
+
* @param arr
|
|
4
|
+
* @returns
|
|
5
|
+
*/
|
|
6
|
+
export function buttonAutomaticArrangement(arr = []) {
|
|
7
|
+
const small = [];
|
|
8
|
+
const mid = [];
|
|
9
|
+
const big = [];
|
|
10
|
+
for (const item of arr) {
|
|
11
|
+
if (item.text.length <= 2) {
|
|
12
|
+
small.push(item);
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
if (item.text.length <= 4) {
|
|
16
|
+
mid.push(item);
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
if (item.text.length <= 10) {
|
|
20
|
+
big.push(item);
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
// 应该先按照数字大小分 三个类 再进行 分类中的小分区
|
|
25
|
+
const small_component_group_list = [];
|
|
26
|
+
const mid_component_group_list = [];
|
|
27
|
+
const big_component_group_list = [];
|
|
28
|
+
let slist = [];
|
|
29
|
+
for (const item of small) {
|
|
30
|
+
// 装进去
|
|
31
|
+
if (slist.length < 3) {
|
|
32
|
+
slist.push(item);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
// 大了 就要做记录
|
|
36
|
+
small_component_group_list.push(slist);
|
|
37
|
+
slist = [];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
// 如果 slist是 1 slist是 2 就留到下一批
|
|
41
|
+
for (const item of slist) {
|
|
42
|
+
mid.push(item);
|
|
43
|
+
}
|
|
44
|
+
let mlist = [];
|
|
45
|
+
for (const item of mid) {
|
|
46
|
+
if (mlist.length < 2) {
|
|
47
|
+
mlist.push(item);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
mid_component_group_list.push(mlist);
|
|
51
|
+
mlist = [];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
for (const item of mlist) {
|
|
55
|
+
big_component_group_list.push(item);
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
big_component_group_list: big_component_group_list,
|
|
59
|
+
mid_component_group_list: mid_component_group_list,
|
|
60
|
+
small_component_group_list: small_component_group_list // 3
|
|
61
|
+
};
|
|
62
|
+
}
|
package/logs.d.ts
CHANGED
package/logs.js
CHANGED
|
@@ -4,20 +4,20 @@
|
|
|
4
4
|
* @param prefix 前缀
|
|
5
5
|
*/
|
|
6
6
|
export function setLog(fun) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
7
|
+
const log = console.log
|
|
8
|
+
global.console.log = (...argv) => {
|
|
9
|
+
log(fun(), ...argv)
|
|
10
|
+
}
|
|
11
|
+
const info = console.info
|
|
12
|
+
global.console.info = (...argv) => {
|
|
13
|
+
info(fun(), ...argv)
|
|
14
|
+
}
|
|
15
|
+
const error = console.error
|
|
16
|
+
global.console.error = (...argv) => {
|
|
17
|
+
error(fun(), ...argv)
|
|
18
|
+
}
|
|
19
|
+
const debug = console.debug
|
|
20
|
+
global.console.debug = (...argv) => {
|
|
21
|
+
debug(fun(), ...argv)
|
|
22
|
+
}
|
|
23
23
|
}
|
package/package.json
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "alemonjs",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "DOCS https://alemonjs.com/",
|
|
5
5
|
"author": "ningmengchongshui",
|
|
6
6
|
"license": "GPL-2.0",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"app": "ts-node alemon.config.ts",
|
|
10
|
-
"
|
|
11
|
-
"build": "npm run format && npm run tsc && npm run tsc:logs && npm run tsc:run ",
|
|
10
|
+
"build": "npm run tsc && npm run tsc:logs && npm run tsc:run ",
|
|
12
11
|
"tsc": "tsc",
|
|
13
12
|
"tsc:logs": "tsc --module NodeNext --declaration ./logs.ts",
|
|
14
13
|
"tsc:run": "tsc --module NodeNext --declaration ./run.ts",
|
|
@@ -88,4 +87,4 @@
|
|
|
88
87
|
"engines": {
|
|
89
88
|
"node": ">=16.14.0"
|
|
90
89
|
}
|
|
91
|
-
}
|
|
90
|
+
}
|
package/run.d.ts
CHANGED
package/run.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import { spawn } from 'child_process'
|
|
2
|
-
import { existsSync } from 'fs'
|
|
3
|
-
import { join } from 'path'
|
|
1
|
+
import { spawn } from 'child_process'
|
|
2
|
+
import { existsSync } from 'fs'
|
|
3
|
+
import { join } from 'path'
|
|
4
4
|
/**
|
|
5
5
|
* 指令运行队则
|
|
6
6
|
* @param ars 指令参数数组
|
|
7
7
|
*/
|
|
8
8
|
export function commandRun(ars) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
const isTypeScript = item.endsWith('.ts');
|
|
18
|
-
const command = isTypeScript ? 'ts-node' : 'node';
|
|
19
|
-
const cmd = `${command} ${item} ${argsWithoutFiles}`;
|
|
20
|
-
console.info(cmd);
|
|
21
|
-
const childProcess = spawn(cmd, { shell: true });
|
|
22
|
-
childProcess.stdout.on('data', data => {
|
|
23
|
-
process.stdout.write(data.toString());
|
|
24
|
-
});
|
|
25
|
-
childProcess.stderr.on('data', data => {
|
|
26
|
-
process.stderr.write(data.toString());
|
|
27
|
-
});
|
|
9
|
+
const msg = ars.join(' ')
|
|
10
|
+
const files = msg.match(/(\S+\.js|\S+\.ts)/g) ?? ['alemon.config.ts']
|
|
11
|
+
const argsWithoutFiles = msg.replace(/(\S+\.js|\S+\.ts)/g, '')
|
|
12
|
+
for (const item of files) {
|
|
13
|
+
if (!existsSync(join(process.cwd(), item))) {
|
|
14
|
+
console.info('no file', item)
|
|
15
|
+
continue
|
|
28
16
|
}
|
|
17
|
+
const isTypeScript = item.endsWith('.ts')
|
|
18
|
+
const command = isTypeScript ? 'ts-node' : 'node'
|
|
19
|
+
const cmd = `${command} ${item} ${argsWithoutFiles}`
|
|
20
|
+
console.info(cmd)
|
|
21
|
+
const childProcess = spawn(cmd, { shell: true })
|
|
22
|
+
childProcess.stdout.on('data', data => {
|
|
23
|
+
process.stdout.write(data.toString())
|
|
24
|
+
})
|
|
25
|
+
childProcess.stderr.on('data', data => {
|
|
26
|
+
process.stderr.write(data.toString())
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
29
|
}
|
package/types/index.d.ts
CHANGED
package/types/utils.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Villa按钮自动排咧
|
|
3
|
+
* @param arr
|
|
4
|
+
* @returns
|
|
5
|
+
*/
|
|
6
|
+
export declare function buttonAutomaticArrangement(arr?: {
|
|
7
|
+
id: string;
|
|
8
|
+
text: string;
|
|
9
|
+
type?: number;
|
|
10
|
+
c_type?: number;
|
|
11
|
+
link?: string;
|
|
12
|
+
input?: string;
|
|
13
|
+
need_callback?: boolean;
|
|
14
|
+
need_token?: boolean;
|
|
15
|
+
extra?: string;
|
|
16
|
+
}[]): {
|
|
17
|
+
big_component_group_list: any[];
|
|
18
|
+
mid_component_group_list: any[];
|
|
19
|
+
small_component_group_list: any[];
|
|
20
|
+
};
|