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/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 './app/utils.js';
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 './app/utils.js';
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 './app/utils.js';
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';
@@ -34,7 +34,7 @@ type ActionMentionGet = {
34
34
  };
35
35
  };
36
36
  type base = {
37
- actionID?: string;
37
+ actionId?: string;
38
38
  DeviceId?: string;
39
39
  };
40
40
  type Actions = (ActionMessageSend | ActionMentionGet | ActionMessageSendChannel | ActionMessageSendUser) & base;
@@ -0,0 +1,18 @@
1
+ type Apis = {
2
+ /**
3
+ * 行为
4
+ */
5
+ action: string;
6
+ payload: {
7
+ event: any;
8
+ key: string;
9
+ params: any[];
10
+ };
11
+ /**
12
+ * 标记
13
+ */
14
+ apiId?: string;
15
+ DeviceId?: string;
16
+ };
17
+
18
+ export type { Apis };
@@ -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 '../../app/utils.js';
4
+ import { Result } from '../../core/utils.js';
5
5
  import '../../global.js';
6
6
 
7
7
  type ClientAPIMessageResult = Result & {
@@ -15,6 +15,10 @@ type User = {
15
15
  UserName?: string;
16
16
  /**
17
17
  * 用户头像地址
18
+ * https://
19
+ * http://
20
+ * base64://
21
+ * file://
18
22
  */
19
23
  UserAvatar?: string;
20
24
  /**
@@ -13,7 +13,7 @@ type DataButton = {
13
13
  confirm: string;
14
14
  cancel: string;
15
15
  };
16
- isLink?: boolean;
16
+ type?: 'command' | 'link' | 'call';
17
17
  };
18
18
  };
19
19
  type ButtonRow = {
@@ -3,7 +3,7 @@
3
3
  */
4
4
  type DataImage = {
5
5
  type: 'Image';
6
- value: Buffer;
6
+ value: string;
7
7
  };
8
8
  /**
9
9
  * 图片链接
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.1",
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
  }