alemonjs 2.1.0-alpha.1 → 2.1.0-alpha.10
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/app/event-processor-event.js +1 -1
- package/lib/app/event-processor-middleware.js +1 -1
- package/lib/app/event-processor.js +1 -1
- package/lib/app/hook-use-api.d.ts +9 -2
- package/lib/app/hook-use-api.js +34 -18
- package/lib/app/load.js +10 -14
- package/lib/app/message-api.d.ts +4 -4
- package/lib/app/message-format.d.ts +1 -1
- package/lib/app/message-format.js +1 -1
- package/lib/app/store.js +4 -3
- package/lib/cbp/actions.js +9 -21
- package/lib/cbp/api.js +36 -0
- package/lib/cbp/config.js +8 -2
- package/lib/cbp/connect.d.ts +6 -2
- package/lib/cbp/connect.js +208 -26
- package/lib/cbp/index.js +50 -4
- package/lib/core/utils.d.ts +77 -0
- package/lib/core/utils.js +162 -0
- package/lib/global.d.ts +8 -0
- package/lib/index.d.ts +2 -2
- package/lib/index.js +2 -2
- package/lib/main.js +1 -1
- package/lib/typing/actions.d.ts +1 -1
- package/lib/typing/apis.d.ts +18 -0
- package/lib/typing/client/index.d.ts +1 -1
- package/lib/typing/event/base/user.d.ts +4 -0
- package/lib/typing/message/button.d.ts +1 -1
- package/lib/typing/message/image.d.ts +1 -1
- package/lib/utils.d.ts +43 -0
- package/lib/utils.js +108 -0
- package/package.json +5 -1
package/lib/index.d.ts
CHANGED
|
@@ -24,14 +24,14 @@ export { defineChildren } from './app/define-chidren.js';
|
|
|
24
24
|
export { onMiddleware } from './app/event-middleware.js';
|
|
25
25
|
export { OnProcessor, onProcessor } from './app/event-processor.js';
|
|
26
26
|
export { onResponse } from './app/event-response.js';
|
|
27
|
-
export { createSelects, onSelects, unChildren, useChannel, useMenber, useMention, useMessage, useSend, useSends } from './app/hook-use-api.js';
|
|
27
|
+
export { createSelects, onSelects, unChildren, useChannel, useClient, useMenber, useMention, useMessage, useSend, useSends } from './app/hook-use-api.js';
|
|
28
28
|
export { onState, unState, useState } from './app/hook-use-state.js';
|
|
29
29
|
export { useSubscribe } from './app/hook-use-subscribe.js';
|
|
30
30
|
export { loadChildren, loadChildrenFile } from './app/load.js';
|
|
31
31
|
export { format, sendToChannel, sendToUser } from './app/message-api.js';
|
|
32
32
|
export { Ark, BT, Image, ImageFile, ImageURL, Link, MD, Mention, Text } from './app/message-format.js';
|
|
33
33
|
export { ChildrenApp, Core, Logger, Middleware, ProcessorEventAutoClearMap, ProcessorEventUserAudoClearMap, Response, State, StateSubscribe, SubscribeList } from './app/store.js';
|
|
34
|
-
export { Result, createEventName, createHash, createResult, getInputExportPath, getRecursiveDirFiles, showErrorModule, stringToNumber, useUserHashKey } from './
|
|
34
|
+
export { Result, createEventName, createHash, createResult, getInputExportPath, getRecursiveDirFiles, showErrorModule, stringToNumber, useUserHashKey } from './core/utils.js';
|
|
35
35
|
export { cbpClient, cbpPlatform } from './cbp/connect.js';
|
|
36
36
|
export { run, start } from './main.js';
|
|
37
37
|
export { ResultCode } from './core/code.js';
|
package/lib/index.js
CHANGED
|
@@ -6,14 +6,14 @@ export { defineChildren } from './app/define-chidren.js';
|
|
|
6
6
|
export { onMiddleware } from './app/event-middleware.js';
|
|
7
7
|
export { OnProcessor, onProcessor } from './app/event-processor.js';
|
|
8
8
|
export { onResponse } from './app/event-response.js';
|
|
9
|
-
export { createSelects, onSelects, unChildren, useChannel, useMenber, useMention, useMessage, useSend, useSends } from './app/hook-use-api.js';
|
|
9
|
+
export { createSelects, onSelects, unChildren, useChannel, useClient, useMenber, useMention, useMessage, useSend, useSends } from './app/hook-use-api.js';
|
|
10
10
|
export { onState, unState, useState } from './app/hook-use-state.js';
|
|
11
11
|
export { useSubscribe } from './app/hook-use-subscribe.js';
|
|
12
12
|
export { loadChildren, loadChildrenFile } from './app/load.js';
|
|
13
13
|
export { format, sendToChannel, sendToUser } from './app/message-api.js';
|
|
14
14
|
export { Ark, BT, Image, ImageFile, ImageURL, Link, MD, Mention, Text } from './app/message-format.js';
|
|
15
15
|
export { ChildrenApp, Core, Logger, Middleware, ProcessorEventAutoClearMap, ProcessorEventUserAudoClearMap, Response, State, StateSubscribe, SubscribeList } from './app/store.js';
|
|
16
|
-
export { createEventName, createHash, createResult, getInputExportPath, getRecursiveDirFiles, showErrorModule, stringToNumber, useUserHashKey } from './
|
|
16
|
+
export { createEventName, createHash, createResult, getInputExportPath, getRecursiveDirFiles, showErrorModule, stringToNumber, useUserHashKey } from './core/utils.js';
|
|
17
17
|
export { cbpClient, cbpPlatform } from './cbp/connect.js';
|
|
18
18
|
export { run, start } from './main.js';
|
|
19
19
|
export { ResultCode } from './core/code.js';
|
package/lib/main.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getConfig, getConfigValue } from './core/config.js';
|
|
2
2
|
import { loadChildren, loadChildrenFile } from './app/load.js';
|
|
3
|
-
import { getInputExportPath } from './
|
|
3
|
+
import { getInputExportPath } from './core/utils.js';
|
|
4
4
|
import './app/define-chidren.js';
|
|
5
5
|
import './app/event-middleware.js';
|
|
6
6
|
import './app/event-processor.js';
|
package/lib/typing/actions.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EventKeys, Events } from '../event/map.js';
|
|
2
2
|
import { User } from '../event/base/user.js';
|
|
3
3
|
import { DataEnums } from '../message/index.js';
|
|
4
|
-
import { Result } from '../../
|
|
4
|
+
import { Result } from '../../core/utils.js';
|
|
5
5
|
import '../../global.js';
|
|
6
6
|
|
|
7
7
|
type ClientAPIMessageResult = Result & {
|
package/lib/utils.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 通过URL获取Buffer
|
|
3
|
+
* @param url
|
|
4
|
+
* @returns
|
|
5
|
+
*/
|
|
6
|
+
declare const getBufferByURL: (url: string) => Promise<Buffer>;
|
|
7
|
+
/**
|
|
8
|
+
* 通过路径获取Buffer
|
|
9
|
+
* @param val
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
declare const getBufferByPath: (val: string) => Buffer | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* 生成二维码
|
|
15
|
+
* @param text
|
|
16
|
+
* @param localpath
|
|
17
|
+
* @returns
|
|
18
|
+
*/
|
|
19
|
+
declare const createQRCode: (text: string, localpath?: string) => Promise<Buffer | false>;
|
|
20
|
+
declare class Counter {
|
|
21
|
+
#private;
|
|
22
|
+
/**
|
|
23
|
+
* 计数器
|
|
24
|
+
* @param initialValue
|
|
25
|
+
*/
|
|
26
|
+
constructor(initialValue: number);
|
|
27
|
+
/**
|
|
28
|
+
* 获取当前计数值
|
|
29
|
+
*/
|
|
30
|
+
get value(): number;
|
|
31
|
+
/**
|
|
32
|
+
* 获取下一个计数值
|
|
33
|
+
* @returns
|
|
34
|
+
*/
|
|
35
|
+
next(): number;
|
|
36
|
+
/**
|
|
37
|
+
* 重置计数器
|
|
38
|
+
* @param initialValue
|
|
39
|
+
*/
|
|
40
|
+
reStart(initialValue?: number): void;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export { Counter, createQRCode, getBufferByPath, getBufferByURL };
|
package/lib/utils.js
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { existsSync, readFileSync, writeFile } from 'fs';
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
import { toDataURL } from 'qrcode';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 通过URL获取Buffer
|
|
8
|
+
* @param url
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
const getBufferByURL = async (url) => {
|
|
12
|
+
return await axios
|
|
13
|
+
.get(url, {
|
|
14
|
+
responseType: 'arraybuffer'
|
|
15
|
+
})
|
|
16
|
+
.then(res => Buffer.from(res.data, 'binary'));
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* 通过路径获取Buffer
|
|
20
|
+
* @param val
|
|
21
|
+
* @returns
|
|
22
|
+
*/
|
|
23
|
+
const getBufferByPath = (val) => {
|
|
24
|
+
const add = join(process.cwd(), val);
|
|
25
|
+
// 绝对路径
|
|
26
|
+
if (existsSync(add))
|
|
27
|
+
return Buffer.from(readFileSync(add));
|
|
28
|
+
// 相对路径
|
|
29
|
+
if (existsSync(val))
|
|
30
|
+
return Buffer.from(readFileSync(val));
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* 生成二维码
|
|
34
|
+
* @param text
|
|
35
|
+
* @param localpath
|
|
36
|
+
* @returns
|
|
37
|
+
*/
|
|
38
|
+
const createQRCode = async (text, localpath) => {
|
|
39
|
+
try {
|
|
40
|
+
const qrDataURL = await new Promise((resolve, reject) => {
|
|
41
|
+
toDataURL(text, {
|
|
42
|
+
margin: 2,
|
|
43
|
+
width: 500
|
|
44
|
+
}, (err, qrDataURL) => {
|
|
45
|
+
if (err) {
|
|
46
|
+
console.error(err);
|
|
47
|
+
reject(err);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
resolve(qrDataURL);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
const bufferData = Buffer.from(qrDataURL.split(',')[1], 'base64');
|
|
55
|
+
if (localpath != undefined) {
|
|
56
|
+
writeFile(localpath, bufferData, (err) => {
|
|
57
|
+
if (err)
|
|
58
|
+
throw err;
|
|
59
|
+
console.info('buffer set', localpath);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return bufferData;
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
console.error(err);
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
class Counter {
|
|
70
|
+
#counter = 1;
|
|
71
|
+
#val = 0;
|
|
72
|
+
/**
|
|
73
|
+
* 计数器
|
|
74
|
+
* @param initialValue
|
|
75
|
+
*/
|
|
76
|
+
constructor(initialValue) {
|
|
77
|
+
this.#counter = initialValue;
|
|
78
|
+
this.#val = initialValue;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* 获取当前计数值
|
|
82
|
+
*/
|
|
83
|
+
get value() {
|
|
84
|
+
return this.#counter;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* 获取下一个计数值
|
|
88
|
+
* @returns
|
|
89
|
+
*/
|
|
90
|
+
next() {
|
|
91
|
+
return ++this.#counter;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* 重置计数器
|
|
95
|
+
* @param initialValue
|
|
96
|
+
*/
|
|
97
|
+
reStart(initialValue) {
|
|
98
|
+
if (initialValue !== undefined) {
|
|
99
|
+
this.#val = initialValue;
|
|
100
|
+
this.#counter = initialValue;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
this.#counter = this.#val;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export { Counter, createQRCode, getBufferByPath, getBufferByURL };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "alemonjs",
|
|
3
|
-
"version": "2.1.0-alpha.
|
|
3
|
+
"version": "2.1.0-alpha.10",
|
|
4
4
|
"description": "bot script",
|
|
5
5
|
"author": "lemonade",
|
|
6
6
|
"license": "MIT",
|
|
@@ -16,6 +16,10 @@
|
|
|
16
16
|
"types": "./lib/index.d.ts"
|
|
17
17
|
},
|
|
18
18
|
"./package": "./package.json",
|
|
19
|
+
"./utils": {
|
|
20
|
+
"import": "./lib/utils.js",
|
|
21
|
+
"types": "./lib/utils.d.ts"
|
|
22
|
+
},
|
|
19
23
|
"./env": {
|
|
20
24
|
"types": "./lib/global.d.ts"
|
|
21
25
|
}
|