alemonjs 2.0.14 → 2.0.16

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/README.md CHANGED
@@ -20,9 +20,9 @@ start('src/index.js')
20
20
  > src/response/res.js
21
21
 
22
22
  ```js
23
- import { createSelects, onResponse, Text, useSend } from 'alemonjs'
23
+ import { onSelects, onResponse, Text, useSend } from 'alemonjs'
24
24
  // 创建事件类型
25
- export const selects = createSelects(['message.create'])
25
+ export const selects = onSelects(['message.create'])
26
26
  // 导出响应
27
27
  export default onResponse(selects, event => {
28
28
  // 使用发送函数
@@ -1,4 +1,4 @@
1
- import { ResultCode } from '../code.js';
1
+ import { ResultCode } from '../core/code.js';
2
2
 
3
3
  /**
4
4
  * 定义机器人
@@ -1,4 +1,4 @@
1
- import { ResultCode } from '../code.js';
1
+ import { ResultCode } from '../core/code.js';
2
2
 
3
3
  /**
4
4
  * 定义子事件
@@ -1,4 +1,4 @@
1
- import { ResultCode } from '../code.js';
1
+ import { ResultCode } from '../core/code.js';
2
2
 
3
3
  /**
4
4
  * 中间件
@@ -1,8 +1,8 @@
1
- import { ResultCode } from '../code.js';
1
+ import { ResultCode } from '../core/code.js';
2
2
  import { expendEvent } from './event-processor-event.js';
3
3
  import { expendMiddleware } from './event-processor-middleware.js';
4
4
  import { expendSubscribeCreate, expendSubscribeMount, expendSubscribeUnmount } from './event-processor-subscribe.js';
5
- import { getConfigValue } from '../config.js';
5
+ import { getConfigValue } from '../core/config.js';
6
6
 
7
7
  /**
8
8
  * 打印日志
@@ -3,7 +3,7 @@ import { useState } from './hook-use-state.js';
3
3
  import { showErrorModule } from './utils.js';
4
4
  import { Response } from './store.js';
5
5
  import { useSend } from './hook-use-api.js';
6
- import { EventMessageText } from './config.js';
6
+ import { EventMessageText } from '../core/variable.js';
7
7
 
8
8
  /**
9
9
  * @fileoverview 消息处理快
@@ -93,7 +93,9 @@ const expendEvent = async (valueEvent, select, next) => {
93
93
  }
94
94
  }
95
95
  }
96
- const currents = Array.isArray(app.default.current) ? app.default.current : [app.default.current];
96
+ const currents = Array.isArray(app.default.current)
97
+ ? app.default.current
98
+ : [app.default.current];
97
99
  let index = 0;
98
100
  let isClose = false;
99
101
  let isNext = false;
@@ -3,7 +3,7 @@ import { useState } from './hook-use-state.js';
3
3
  import { showErrorModule } from './utils.js';
4
4
  import { Middleware } from './store.js';
5
5
  import { useSend } from './hook-use-api.js';
6
- import { EventMessageText } from './config.js';
6
+ import { EventMessageText } from '../core/variable.js';
7
7
 
8
8
  /**
9
9
  * @fileoverview 消息处理快
@@ -91,7 +91,9 @@ const expendMiddleware = async (valueEvent, select, next) => {
91
91
  nextMiddleware();
92
92
  return;
93
93
  }
94
- const currents = Array.isArray(app.default.current) ? app.default.current : [app.default.current];
94
+ const currents = Array.isArray(app.default.current)
95
+ ? app.default.current
96
+ : [app.default.current];
95
97
  let index = 0;
96
98
  let isClose = false;
97
99
  let isNext = false;
@@ -1,12 +1,9 @@
1
- import { getConfigValue } from '../config.js';
1
+ import { getConfigValue } from '../core/config.js';
2
+ import { processor_repeated_clear_time_min, processor_repeated_clear_time_max, processor_repeated_event_time, processor_repeated_user_time, processor_repeated_clear_size } from '../core/variable.js';
2
3
  import { expendCycle } from './event-processor-cycle.js';
4
+ import { ProcessorEventAutoClearMap, ProcessorEventUserAudoClearMap } from './store.js';
3
5
  import { createHash } from './utils.js';
4
6
 
5
- const MIN_TIME = 3000;
6
- const MAX_TIME = 10000;
7
- const CONTROL_SIZE = 37;
8
- const eventStore = new Map();
9
- const userStore = new Map();
10
7
  /**
11
8
  * 过滤掉重复消息
12
9
  * @param param0
@@ -42,21 +39,23 @@ const cleanupStore = ({ Now, store, INTERVAL }) => {
42
39
  const cleanupStoreAll = () => {
43
40
  const Now = Date.now();
44
41
  const value = getConfigValue();
45
- const EVENT_INTERVAL = value?.ALEMONJS_EVENT_INTERVAL ?? 1000 * 60;
46
- const USER_INTERVAL = value?.ALEMONJS_USER_INTERVAL ?? 1000 * 1;
47
- cleanupStore({ Now, INTERVAL: EVENT_INTERVAL, store: eventStore });
48
- cleanupStore({ Now, INTERVAL: USER_INTERVAL, store: userStore });
42
+ const EVENT_INTERVAL = value?.processor?.repeated_event_time ?? processor_repeated_event_time;
43
+ const USER_INTERVAL = value?.processor?.repeated_user_time ?? processor_repeated_user_time;
44
+ cleanupStore({ Now, INTERVAL: EVENT_INTERVAL, store: ProcessorEventAutoClearMap });
45
+ cleanupStore({ Now, INTERVAL: USER_INTERVAL, store: ProcessorEventUserAudoClearMap });
49
46
  };
50
47
  // 清理消息
51
48
  const callback = () => {
52
49
  cleanupStoreAll();
53
50
  // 下一次清理的时间,应该随着长度的增加而减少
54
- const length = eventStore.size + userStore.size;
51
+ const length = ProcessorEventAutoClearMap.size + ProcessorEventUserAudoClearMap.size;
55
52
  // 长度控制在37个以内
56
- const time = length > CONTROL_SIZE ? MIN_TIME : MAX_TIME;
53
+ const time = length > processor_repeated_clear_size
54
+ ? processor_repeated_clear_time_min
55
+ : processor_repeated_clear_time_max;
57
56
  setTimeout(callback, time);
58
57
  };
59
- setTimeout(callback, MIN_TIME);
58
+ setTimeout(callback, processor_repeated_clear_time_min);
60
59
  /**
61
60
  * 消息处理器
62
61
  * @param name
@@ -67,13 +66,13 @@ setTimeout(callback, MIN_TIME);
67
66
  const onProcessor = (name, event, data) => {
68
67
  const Now = Date.now();
69
68
  const value = getConfigValue();
70
- const EVENT_INTERVAL = value?.processor?.repeated_event_time ?? 1000 * 60;
71
- const USER_INTERVAL = value?.processor?.repeated_user_time ?? 1000 * 1;
69
+ const EVENT_INTERVAL = value?.processor?.repeated_event_time ?? processor_repeated_event_time;
70
+ const USER_INTERVAL = value?.processor?.repeated_user_time ?? processor_repeated_user_time;
72
71
  if (event['MessageId']) {
73
72
  // 消息过长,要减少消息的长度
74
73
  const MessageId = createHash(event['MessageId']);
75
74
  // 重复消息
76
- if (filter({ Now, INTERVAL: EVENT_INTERVAL, store: eventStore }, MessageId)) {
75
+ if (filter({ Now, INTERVAL: EVENT_INTERVAL, store: ProcessorEventAutoClearMap }, MessageId)) {
77
76
  return;
78
77
  }
79
78
  }
@@ -81,7 +80,7 @@ const onProcessor = (name, event, data) => {
81
80
  // 编号过长,要减少编号的长度
82
81
  const UserId = createHash(event['UserId']);
83
82
  // 频繁操作
84
- if (filter({ Now, INTERVAL: USER_INTERVAL, store: userStore }, UserId)) {
83
+ if (filter({ Now, INTERVAL: USER_INTERVAL, store: ProcessorEventUserAudoClearMap }, UserId)) {
85
84
  return;
86
85
  }
87
86
  }
@@ -1,4 +1,4 @@
1
- import { ResultCode } from '../code.js';
1
+ import { ResultCode } from '../core/code.js';
2
2
 
3
3
  /**
4
4
  * 处理响应事件
@@ -31,6 +31,7 @@ declare const useMention: <T extends EventKeys>(event: Events[T]) => {
31
31
  * @throws {Error} - 如果 event 无效,抛出错误。
32
32
  */
33
33
  declare const useSend: <T extends EventKeys>(event: Events[T]) => (...val: DataEnums[]) => Promise<Result | ClientAPIMessageResult[]>;
34
+ declare const useSends: <T extends EventKeys>(event: Events[T]) => ((val: DataEnums[]) => Promise<Result | ClientAPIMessageResult[]>)[];
34
35
  /**
35
36
  * 卸载模块
36
37
  * @param name
@@ -47,6 +48,11 @@ declare const unMount: () => void;
47
48
  * @param values
48
49
  * @returns
49
50
  */
51
+ declare const onSelects: <T extends EventKeys[] | EventKeys>(values: T) => T;
52
+ /**
53
+ * 废弃,请使用onSelects
54
+ * @deprecated
55
+ */
50
56
  declare const createSelects: <T extends EventKeys[] | EventKeys>(values: T) => T;
51
57
 
52
- export { createSelects, unChildren, unMount, useMention, useSend };
58
+ export { createSelects, onSelects, unChildren, unMount, useMention, useSend, useSends };
@@ -1,4 +1,4 @@
1
- import { ResultCode } from '../code.js';
1
+ import { ResultCode } from '../core/code.js';
2
2
  import { ChildrenApp } from './store.js';
3
3
  import { createResult } from './utils.js';
4
4
 
@@ -113,6 +113,23 @@ const useSend = (event) => {
113
113
  return await alemonjsBot.api.use.send(event, val);
114
114
  };
115
115
  };
116
+ const useSends = (event) => {
117
+ if (!event || typeof event !== 'object') {
118
+ logger.error({
119
+ code: ResultCode.FailParams,
120
+ message: 'Invalid event: event must be an object',
121
+ data: null
122
+ });
123
+ throw new Error('Invalid event: event must be an object');
124
+ }
125
+ const send = async (val) => {
126
+ if (!val || val.length === 0) {
127
+ return createResult(ResultCode.FailParams, 'Invalid val: val must be a non-empty array', null);
128
+ }
129
+ return await alemonjsBot.api.use.send(event, val);
130
+ };
131
+ return [send];
132
+ };
116
133
  /**
117
134
  * 卸载模块
118
135
  * @param name
@@ -146,6 +163,12 @@ const unMount = () => {
146
163
  * @param values
147
164
  * @returns
148
165
  */
149
- const createSelects = (values) => values;
166
+ const onSelects = (values) => values;
167
+ global.onSelects = onSelects;
168
+ /**
169
+ * 废弃,请使用onSelects
170
+ * @deprecated
171
+ */
172
+ const createSelects = onSelects;
150
173
 
151
- export { createSelects, unChildren, unMount, useMention, useSend };
174
+ export { createSelects, onSelects, unChildren, unMount, useMention, useSend, useSends };
@@ -1,5 +1,5 @@
1
- import { getConfig } from '../config.js';
2
- import { ResultCode } from '../code.js';
1
+ import { getConfig } from '../core/config.js';
2
+ import { ResultCode } from '../core/code.js';
3
3
  import { State, StateSubscribe } from './store.js';
4
4
 
5
5
  /**
@@ -10,10 +10,13 @@ import '../global.js';
10
10
  */
11
11
  declare const useSubscribe: <T extends EventKeys>(event: Events[T], select: T) => ((callback: Current<T>, keys: (keyof Events[T])[]) => void)[];
12
12
  /**
13
- * 使用观察者
14
- * @param event
15
- * @param option
16
- * @returns
13
+ * 废弃,请使用
14
+ * ***
15
+ * const [_, observer] = useSubscribe(event, option)
16
+ * ***
17
+ * observer()
18
+ * ***
19
+ * @deprecated
17
20
  */
18
21
  declare const useObserver: <T extends EventKeys>(event: Events[T], option: T) => (callback: Current<T>, keys: (keyof Events[T])[]) => void;
19
22
 
@@ -1,4 +1,4 @@
1
- import { ResultCode } from '../code.js';
1
+ import { ResultCode } from '../core/code.js';
2
2
  import { SubscribeList } from './store.js';
3
3
 
4
4
  /**
@@ -55,10 +55,13 @@ const useSubscribe = (event, select) => {
55
55
  return [create, mountBefore, unmount];
56
56
  };
57
57
  /**
58
- * 使用观察者
59
- * @param event
60
- * @param option
61
- * @returns
58
+ * 废弃,请使用
59
+ * ***
60
+ * const [_, observer] = useSubscribe(event, option)
61
+ * ***
62
+ * observer()
63
+ * ***
64
+ * @deprecated
62
65
  */
63
66
  const useObserver = (event, option) => {
64
67
  const [_, mount] = useSubscribe(event, option);
package/lib/app/load.js CHANGED
@@ -3,10 +3,10 @@ import { existsSync } from 'fs';
3
3
  import { showErrorModule, getRecursiveDirFiles, createEventName } from './utils.js';
4
4
  import { createRequire } from 'module';
5
5
  import { ChildrenApp } from './store.js';
6
- import { ResultCode } from '../code.js';
6
+ import { ResultCode } from '../core/code.js';
7
+ import { file_suffix_middleware } from '../core/variable.js';
7
8
 
8
9
  const require = createRequire(import.meta.url);
9
- const mwReg = /^mw(\.|\..*\.)(js|ts|jsx|tsx)$/;
10
10
  /**
11
11
  * 加载子模块
12
12
  * @param mainPath
@@ -103,7 +103,7 @@ const loadChildren = async (mainPath, appName) => {
103
103
  * load middleware files
104
104
  */
105
105
  const mwDir = join(mainDir, 'middleware');
106
- const mwFiles = getRecursiveDirFiles(mwDir, item => mwReg.test(item.name));
106
+ const mwFiles = getRecursiveDirFiles(mwDir, item => file_suffix_middleware.test(item.name));
107
107
  const mwData = [];
108
108
  for (const file of mwFiles) {
109
109
  // 切掉 mainDir
@@ -1,3 +1,4 @@
1
+ import { OnDataFormatFunc } from '../typing/event/index.js';
1
2
  import { ClientAPIMessageResult } from '../typing/client/index.js';
2
3
  import { DataEnums } from '../typing/message/index.js';
3
4
  import '../global.js';
@@ -8,7 +9,12 @@ import '../global.js';
8
9
  * @returns {DataEnums[]} - 返回格式化后的数据数组。
9
10
  * @throws {Error} - 如果 data 无效,抛出错误。
10
11
  */
11
- declare const createSendDataFormat: (...data: DataEnums[]) => DataEnums[];
12
+ declare const format: OnDataFormatFunc;
13
+ /**
14
+ * 废弃
15
+ * @deprecated
16
+ */
17
+ declare const createSendDataFormat: OnDataFormatFunc;
12
18
  /**
13
19
  * 向指定频道发送消息。
14
20
  * @param {string} channel_id - 目标频道的 ID。
@@ -24,4 +30,4 @@ declare const sendToChannel: (channel_id: string, data: DataEnums[]) => Promise<
24
30
  */
25
31
  declare const sendToUser: (user_id: string, data: DataEnums[]) => Promise<ClientAPIMessageResult[]>;
26
32
 
27
- export { createSendDataFormat, sendToChannel, sendToUser };
33
+ export { createSendDataFormat, format, sendToChannel, sendToUser };
@@ -1,4 +1,4 @@
1
- import { ResultCode } from '../code.js';
1
+ import { ResultCode } from '../core/code.js';
2
2
 
3
3
  /**
4
4
  * 创建数据格式。
@@ -6,7 +6,7 @@ import { ResultCode } from '../code.js';
6
6
  * @returns {DataEnums[]} - 返回格式化后的数据数组。
7
7
  * @throws {Error} - 如果 data 无效,抛出错误。
8
8
  */
9
- const createSendDataFormat = (...data) => {
9
+ const format = (...data) => {
10
10
  if (!data || data.length === 0) {
11
11
  logger.error({
12
12
  code: ResultCode.FailParams,
@@ -17,6 +17,12 @@ const createSendDataFormat = (...data) => {
17
17
  }
18
18
  return data;
19
19
  };
20
+ global.format = format;
21
+ /**
22
+ * 废弃
23
+ * @deprecated
24
+ */
25
+ const createSendDataFormat = format;
20
26
  /**
21
27
  * 向指定频道发送消息。
22
28
  * @param {string} channel_id - 目标频道的 ID。
@@ -52,4 +58,4 @@ const sendToUser = async (user_id, data) => {
52
58
  return await alemonjsBot.api.active.send.user(user_id, data);
53
59
  };
54
60
 
55
- export { createSendDataFormat, sendToChannel, sendToUser };
61
+ export { createSendDataFormat, format, sendToChannel, sendToUser };
@@ -86,5 +86,7 @@ declare class ChildrenApp {
86
86
  */
87
87
  get value(): StoreChildrenApp;
88
88
  }
89
+ declare const ProcessorEventAutoClearMap: Map<any, any>;
90
+ declare const ProcessorEventUserAudoClearMap: Map<any, any>;
89
91
 
90
- export { ChildrenApp, Core, Logger, Middleware, Response, State, StateSubscribe, SubscribeList };
92
+ export { ChildrenApp, Core, Logger, Middleware, ProcessorEventAutoClearMap, ProcessorEventUserAudoClearMap, Response, State, StateSubscribe, SubscribeList };
package/lib/app/store.js CHANGED
@@ -267,5 +267,7 @@ class ChildrenApp {
267
267
  return alemonjsCore.storeChildrenApp[this.#name];
268
268
  }
269
269
  }
270
+ const ProcessorEventAutoClearMap = new Map();
271
+ const ProcessorEventUserAudoClearMap = new Map();
270
272
 
271
- export { ChildrenApp, Core, Logger, Middleware, Response, State, StateSubscribe, SubscribeList };
273
+ export { ChildrenApp, Core, Logger, Middleware, ProcessorEventAutoClearMap, ProcessorEventUserAudoClearMap, Response, State, StateSubscribe, SubscribeList };
@@ -1,5 +1,5 @@
1
1
  import { Dirent } from 'fs';
2
- import { ResultCode } from '../code.js';
2
+ import { ResultCode } from '../core/code.js';
3
3
 
4
4
  /**
5
5
  * 将字符串转为定长字符串
package/lib/app/utils.js CHANGED
@@ -2,7 +2,8 @@ import crypto from 'crypto';
2
2
  import fs, { existsSync, readdirSync } from 'fs';
3
3
  import path, { join } from 'path';
4
4
  import { createRequire } from 'module';
5
- import { ResultCode } from '../code.js';
5
+ import { ResultCode } from '../core/code.js';
6
+ import { file_suffix_response } from '../core/variable.js';
6
7
 
7
8
  const require = createRequire(import.meta.url);
8
9
  /**
@@ -61,14 +62,13 @@ const stringToNumber = (str, size = 33) => {
61
62
  *通过执行无符号位移,将带符号的int转换为无符号*/
62
63
  return hash >>> 0;
63
64
  };
64
- const resReg = /^res(\.|\..*\.)(js|ts|jsx|tsx)$/;
65
65
  /**
66
66
  * 递归获取所有文件
67
67
  * @param dir
68
68
  * @param condition
69
69
  * @returns
70
70
  */
71
- const getRecursiveDirFiles = (dir, condition = item => resReg.test(item.name)) => {
71
+ const getRecursiveDirFiles = (dir, condition = item => file_suffix_response.test(item.name)) => {
72
72
  //
73
73
  let results = [];
74
74
  if (!existsSync(dir))
@@ -1,6 +1,3 @@
1
- /**
2
- * 结果反馈码
3
- */
4
1
  /**
5
2
  * 结果反馈码
6
3
  * @description
@@ -0,0 +1,17 @@
1
+ import { FailParams, Warn, FailInternal, FailAuth, Fail, Ok } from './variable.js';
2
+
3
+ /**
4
+ * 结果反馈码
5
+ * @description
6
+ * - 2000: 成功
7
+ */
8
+ const ResultCode = {
9
+ Ok,
10
+ Fail,
11
+ FailParams,
12
+ Warn,
13
+ FailAuth,
14
+ FailInternal
15
+ };
16
+
17
+ export { ResultCode };
@@ -1,5 +1,5 @@
1
- import './global.js';
2
- import { Package } from './typing/package/index.js';
1
+ import '../global.js';
2
+ import { Package } from '../typing/package/index.js';
3
3
 
4
4
  /**
5
5
  * 配置类
@@ -1,4 +1,4 @@
1
- import './typing/event/actions.js';
1
+ import '../typing/event/actions.js';
2
2
  import { existsSync, readFileSync, watch, mkdirSync, writeFileSync } from 'fs';
3
3
  import { join, dirname } from 'path';
4
4
  import YAML from 'yaml';
@@ -0,0 +1,37 @@
1
+ const processor_repeated_event_time = 1000 * 60;
2
+ const processor_repeated_user_time = 1000 * 1;
3
+ const processor_repeated_clear_time_min = 1000 * 3;
4
+ const processor_repeated_clear_time_max = 1000 * 10;
5
+ const processor_repeated_clear_size = 37;
6
+ // 中间件文件后缀正则
7
+ const file_suffix_middleware = /^mw(\.|\..*\.)(js|ts|jsx|tsx)$/;
8
+ // 相应文件后缀正则
9
+ const file_suffix_response = /^res(\.|\..*\.)(js|ts|jsx|tsx)$/;
10
+ // 框架前缀正则
11
+ const file_prefix_framework = /^alemonjs-/;
12
+ // 通用框架前缀正则
13
+ const file_prefix_common = /^(@alemonjs\/|alemonjs-)/;
14
+ // 默认登录
15
+ const default_login = 'gui';
16
+ const default_platform_prefix = 'alemonjs-';
17
+ const default_platform_common_prefix = '@alemonjs/';
18
+ /**
19
+ * 结果反馈码
20
+ */
21
+ // 成功码
22
+ const Ok = 2000; // 成功
23
+ // 警惕码
24
+ const Warn = 2100; // 任意警告
25
+ // 失败码
26
+ const Fail = 4000; // 未知错误
27
+ const FailParams = 4001; // 参数错误
28
+ const FailAuth = 4002; // 权限不足
29
+ const FailInternal = 5000; // 内部错误
30
+ const EventMessageText = [
31
+ 'message.create',
32
+ 'private.message.create',
33
+ 'interaction.create',
34
+ 'private.interaction.create'
35
+ ];
36
+
37
+ export { EventMessageText, Fail, FailAuth, FailInternal, FailParams, Ok, Warn, default_login, default_platform_common_prefix, default_platform_prefix, file_prefix_common, file_prefix_framework, file_suffix_middleware, file_suffix_response, processor_repeated_clear_size, processor_repeated_clear_time_max, processor_repeated_clear_time_min, processor_repeated_event_time, processor_repeated_user_time };
package/lib/global.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { OnResponseFunc, OnResponseReversalFunc, OnMiddlewareFunc, OnMiddlewareReversalFunc, DefineChildrenFunc, DefinePlatformFunc } from './typing/event/index.js';
1
+ import { OnResponseFunc, OnResponseReversalFunc, OnMiddlewareFunc, OnMiddlewareReversalFunc, DefineChildrenFunc, DefinePlatformFunc, OnSelectsFunc, OnDataFormatFunc } from './typing/event/index.js';
2
2
  import { ClientAPI } from './typing/client/index.js';
3
3
  import { StoreChildrenApp } from './typing/store/res.js';
4
4
  import { StateSubscribeMap, SubscribeKeysMap } from './typing/subscribe/index.js';
@@ -68,6 +68,14 @@ declare global {
68
68
  * 定义一个平台
69
69
  */
70
70
  var definePlatform: DefinePlatformFunc;
71
+ /**
72
+ * 定义选择器
73
+ */
74
+ var onSelects: OnSelectsFunc;
75
+ /**
76
+ * 定义数据格式
77
+ */
78
+ var format: OnDataFormatFunc;
71
79
  }
72
80
  declare const logger: any;
73
81
  declare const core: {
package/lib/index.d.ts CHANGED
@@ -10,7 +10,7 @@ export { PublicEventMessageCreate, PublicEventMessageDelete, PublicEventMessageR
10
10
  export { PrivateEventMessageCreate, PrivateEventMessageDelete, PrivateEventMessageUpdate } from './typing/event/message/private.message.js';
11
11
  export { PrivateEventRequestFriendAdd, PrivateEventRequestGuildAdd } from './typing/event/request/index.js';
12
12
  export { ActionsEventEnum } from './typing/event/actions.js';
13
- export { Current, CurrentResult, CurrentResultValue, DefineBot, DefineBotCallback, DefineBotValue, DefineChildrenCallback, DefineChildrenFunc, DefineChildrenValue, DefinePlatformCallback, DefinePlatformFunc, DefinePlatformValue, OnMiddlewareFunc, OnMiddlewareReversalFunc, OnMiddlewareValue, OnResponseFunc, OnResponseReversalFunc, OnResponseValue } from './typing/event/index.js';
13
+ export { Current, CurrentResult, CurrentResultValue, DefineBot, DefineBotCallback, DefineBotValue, DefineChildrenCallback, DefineChildrenFunc, DefineChildrenValue, DefinePlatformCallback, DefinePlatformFunc, DefinePlatformValue, OnDataFormatFunc, OnMiddlewareFunc, OnMiddlewareReversalFunc, OnMiddlewareValue, OnResponseFunc, OnResponseReversalFunc, OnResponseValue, OnSelectsFunc } from './typing/event/index.js';
14
14
  export { EventKeys, Events, EventsEnum, EventsKeyEnum, EventsMessageCreate, EventsMessageCreateEnum, EventsMessageCreateKeys } from './typing/event/map.js';
15
15
  export { LoggerUtils } from './typing/logger/index.js';
16
16
  export { ClientAPI, ClientAPIMessageResult } from './typing/client/index.js';
@@ -18,22 +18,22 @@ export { DataEnums, MessageDataFormat } from './typing/message/index.js';
18
18
  export { StoreChildrenApp, StoreMiddleware, StoreMiddlewareItem, StoreResponse, StoreResponseItem } from './typing/store/res.js';
19
19
  export { StateSubscribeMap, SubscribeKeysMap, SubscribeMap, SubscribeValue } from './typing/subscribe/index.js';
20
20
  export { core, logger } from './global.js';
21
- export { ConfigCore, getConfig, getConfigValue } from './config.js';
21
+ export { ConfigCore, getConfig, getConfigValue } from './core/config.js';
22
22
  export { defineBot, definePlatform } from './app/define-bot.js';
23
23
  export { defineChildren } from './app/define-chidren.js';
24
24
  export { OnMiddleware, onMiddleware } from './app/event-middleware.js';
25
25
  export { OnProcessor, onProcessor } from './app/event-processor.js';
26
26
  export { OnResponse, onResponse } from './app/event-response.js';
27
- export { createSelects, unChildren, unMount, useMention, useSend } from './app/hook-use-api.js';
27
+ export { createSelects, onSelects, unChildren, unMount, useMention, useSend, useSends } from './app/hook-use-api.js';
28
28
  export { eventState, onState, unEventState, unState, useState } from './app/hook-use-state.js';
29
29
  export { useObserver, useSubscribe } from './app/hook-use-subscribe.js';
30
30
  export { loadChildren, loadChildrenFile, loadModule, moduleChildrenFiles } from './app/load.js';
31
- export { createSendDataFormat, sendToChannel, sendToUser } from './app/message-api.js';
31
+ export { createSendDataFormat, 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
- export { ChildrenApp, Core, Logger, Middleware, Response, State, StateSubscribe, SubscribeList } from './app/store.js';
33
+ export { ChildrenApp, Core, Logger, Middleware, ProcessorEventAutoClearMap, ProcessorEventUserAudoClearMap, Response, State, StateSubscribe, SubscribeList } from './app/store.js';
34
34
  export { ErrorModule, Result, createEventName, createHash, createResult, getInputExportPath, getRecursiveDirFiles, showErrorModule, stringToNumber, useUserHashKey } from './app/utils.js';
35
35
  export { run, start } from './main.js';
36
- export { ResultCode } from './code.js';
36
+ export { ResultCode } from './core/code.js';
37
37
  export { DataText } from './typing/message/text.js';
38
38
  export { DataLink } from './typing/message/link.js';
39
39
  export { DataMention } from './typing/message/mention.js';
package/lib/index.js CHANGED
@@ -1,19 +1,19 @@
1
1
  export { ActionsEventEnum } from './typing/event/actions.js';
2
2
  export { EventsKeyEnum } from './typing/event/map.js';
3
3
  export { core, logger } from './global.js';
4
- export { ConfigCore, getConfig, getConfigValue } from './config.js';
4
+ export { ConfigCore, getConfig, getConfigValue } from './core/config.js';
5
5
  export { defineBot, definePlatform } from './app/define-bot.js';
6
6
  export { defineChildren } from './app/define-chidren.js';
7
7
  export { OnMiddleware, onMiddleware } from './app/event-middleware.js';
8
8
  export { OnProcessor, onProcessor } from './app/event-processor.js';
9
9
  export { OnResponse, onResponse } from './app/event-response.js';
10
- export { createSelects, unChildren, unMount, useMention, useSend } from './app/hook-use-api.js';
10
+ export { createSelects, onSelects, unChildren, unMount, useMention, useSend, useSends } from './app/hook-use-api.js';
11
11
  export { eventState, onState, unEventState, unState, useState } from './app/hook-use-state.js';
12
12
  export { useObserver, useSubscribe } from './app/hook-use-subscribe.js';
13
13
  export { loadChildren, loadChildrenFile, loadModule, moduleChildrenFiles } from './app/load.js';
14
- export { createSendDataFormat, sendToChannel, sendToUser } from './app/message-api.js';
14
+ export { createSendDataFormat, format, sendToChannel, sendToUser } from './app/message-api.js';
15
15
  export { Ark, BT, Image, ImageFile, ImageURL, Link, MD, Mention, Text } from './app/message-format.js';
16
- export { ChildrenApp, Core, Logger, Middleware, Response, State, StateSubscribe, SubscribeList } from './app/store.js';
16
+ export { ChildrenApp, Core, Logger, Middleware, ProcessorEventAutoClearMap, ProcessorEventUserAudoClearMap, Response, State, StateSubscribe, SubscribeList } from './app/store.js';
17
17
  export { ErrorModule, createEventName, createHash, createResult, getInputExportPath, getRecursiveDirFiles, showErrorModule, stringToNumber, useUserHashKey } from './app/utils.js';
18
18
  export { run, start } from './main.js';
19
- export { ResultCode } from './code.js';
19
+ export { ResultCode } from './core/code.js';
package/lib/jsx.d.ts CHANGED
@@ -85,6 +85,11 @@ declare const BT: React.FC<BTProps> & {
85
85
  }>;
86
86
  };
87
87
 
88
+ declare function Format(_props: {
89
+ children?: React.ReactNode;
90
+ }): React.ReactElement<{
91
+ dataType: string;
92
+ }, string | React.JSXElementConstructor<any>>;
88
93
  /**
89
94
  * 转换数据
90
95
  * ***
@@ -104,6 +109,12 @@ declare function JSX(...arg: React.JSX.Element[]): DataEnums[];
104
109
  * @returns
105
110
  */
106
111
  declare const useSend: <T extends EventKeys>(e: Events[T]) => (...arg: React.JSX.Element[]) => Promise<Result | ClientAPIMessageResult[]>;
112
+ /**
113
+ * 发送消息
114
+ * @param e
115
+ * @returns
116
+ */
117
+ declare const useSends: <T extends EventKeys>(e: Events[T]) => ((arg: React.JSX.Element) => Promise<Result | ClientAPIMessageResult[]>)[];
107
118
  /**
108
119
  *
109
120
  * @param channel_id
@@ -119,4 +130,4 @@ declare const sendToChannel: (channel_id: string, data: React.JSX.Element[]) =>
119
130
  */
120
131
  declare const sendToUser: (user_id: string, data: React.JSX.Element[]) => Promise<ClientAPIMessageResult[]>;
121
132
 
122
- export { BT, Image, ImageFile, ImageURL, JSX, Mention, Text, sendToChannel, sendToUser, useSend };
133
+ export { BT, Format, Image, ImageFile, ImageURL, JSX, Mention, Text, sendToChannel, sendToUser, useSend, useSends };
package/lib/jsx.js CHANGED
@@ -10,7 +10,7 @@ import './typing/event/actions.js';
10
10
  import 'fs';
11
11
  import 'path';
12
12
  import 'yaml';
13
- import { ResultCode } from './code.js';
13
+ import { ResultCode } from './core/code.js';
14
14
  import 'node:fs';
15
15
  import 'log4js';
16
16
  import './app/load.js';
@@ -100,6 +100,11 @@ BT.group = ButtonGroup;
100
100
  BT.template = ButtonTemplate;
101
101
  // BT.row 子组件
102
102
  BT.row = ButtonRows;
103
+ function Format(_props) {
104
+ return React.createElement('div', {
105
+ dataType: 'Format'
106
+ });
107
+ }
103
108
  /**
104
109
  * 转换数据
105
110
  * ***
@@ -184,6 +189,24 @@ function JSX(...arg) {
184
189
  }
185
190
  }
186
191
  }
192
+ else if (dataType === 'Format') {
193
+ // Format 的 children 就是直接复用 JSX
194
+ let children = [];
195
+ if (Array.isArray(props?.children)) {
196
+ children = props?.children;
197
+ }
198
+ else {
199
+ children = [props?.children];
200
+ }
201
+ if (children.length > 0) {
202
+ const format = JSX(...children);
203
+ format.forEach((item) => {
204
+ if (item) {
205
+ data.push(item);
206
+ }
207
+ });
208
+ }
209
+ }
187
210
  }
188
211
  if (data.length === 0) {
189
212
  logger.warn({
@@ -203,6 +226,16 @@ const useSend = (e) => {
203
226
  const Send = useSend$1(e);
204
227
  return (...arg) => Send(...JSX(...arg));
205
228
  };
229
+ /**
230
+ * 发送消息
231
+ * @param e
232
+ * @returns
233
+ */
234
+ const useSends = (e) => {
235
+ const Send = useSend$1(e);
236
+ const send = (arg) => Send(...JSX(arg));
237
+ return [send];
238
+ };
206
239
  /**
207
240
  *
208
241
  * @param channel_id
@@ -222,4 +255,4 @@ const sendToUser = async (user_id, data) => {
222
255
  return sendToUser$1(user_id, JSX(...data));
223
256
  };
224
257
 
225
- export { BT, Image, ImageFile, ImageURL, JSX, Mention, Text, sendToChannel, sendToUser, useSend };
258
+ export { BT, Format, Image, ImageFile, ImageURL, JSX, Mention, Text, sendToChannel, sendToUser, useSend, useSends };
package/lib/main.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { join } from 'path';
2
2
  import { existsSync } from 'fs';
3
- import { getConfig, getConfigValue } from './config.js';
3
+ import { getConfig, getConfigValue } from './core/config.js';
4
4
  import { loadChildren, loadChildrenFile } from './app/load.js';
5
5
  import { showErrorModule, getInputExportPath } from './app/utils.js';
6
6
  import './app/define-bot.js';
@@ -8,11 +8,14 @@ import './app/define-chidren.js';
8
8
  import './app/event-middleware.js';
9
9
  import './app/event-processor.js';
10
10
  import './app/event-response.js';
11
- import { ResultCode } from './code.js';
11
+ import './app/hook-use-api.js';
12
+ import { useState } from './app/hook-use-state.js';
13
+ import { ResultCode } from './core/code.js';
12
14
  import 'node:fs';
13
15
  import 'log4js';
14
- import { useState } from './app/hook-use-state.js';
16
+ import './app/message-api.js';
15
17
  import './app/message-format.js';
18
+ import { file_prefix_common, default_login, default_platform_prefix, default_platform_common_prefix, file_prefix_framework } from './core/variable.js';
16
19
 
17
20
  const loadConfig = () => {
18
21
  const value = getConfigValue() ?? {};
@@ -51,9 +54,11 @@ const run = (input) => {
51
54
  const start = async (input, pm) => {
52
55
  const cfg = getConfig();
53
56
  const platform$1 = pm ?? cfg.argv?.platform ?? cfg.value?.platform;
54
- const login$1 = platform$1 ? platform$1.replace(/^(@alemonjs\/|alemonjs-)/, '') : null;
55
- const login = login$1 ?? cfg.argv?.login ?? cfg.value?.login ?? 'gui';
56
- const prefix = platform$1 && /^alemonjs-/.test(platform$1) ? `alemonjs-` : `@alemonjs/`;
57
+ const login$1 = platform$1 ? platform$1.replace(file_prefix_common, '') : null;
58
+ const login = login$1 ?? cfg.argv?.login ?? cfg.value?.login ?? default_login;
59
+ const prefix = platform$1 && file_prefix_framework.test(platform$1)
60
+ ? default_platform_prefix
61
+ : default_platform_common_prefix;
57
62
  const platform = `${prefix}${login}`;
58
63
  // 启动机器人
59
64
  try {
@@ -70,6 +70,14 @@ type DefinePlatformValue = {
70
70
  * 定义一个平台
71
71
  */
72
72
  type DefinePlatformFunc = (callback: DefinePlatformCallback) => DefinePlatformValue;
73
+ /**
74
+ * 定义选择器
75
+ */
76
+ type OnSelectsFunc = <T extends EventKeys[] | EventKeys>(values: T) => T;
77
+ /**
78
+ * 定义数据格式
79
+ */
80
+ type OnDataFormatFunc = (...data: DataEnums[]) => DataEnums[];
73
81
  /**
74
82
  * 废弃,请使用 DefinePlatformCallback
75
83
  * @deprecated
@@ -86,4 +94,4 @@ type DefineBotValue = DefinePlatformValue;
86
94
  */
87
95
  type DefineBot = DefinePlatformFunc;
88
96
 
89
- export type { Current, CurrentResult, CurrentResultValue, DefineBot, DefineBotCallback, DefineBotValue, DefineChildrenCallback, DefineChildrenFunc, DefineChildrenValue, DefinePlatformCallback, DefinePlatformFunc, DefinePlatformValue, OnMiddlewareFunc, OnMiddlewareReversalFunc, OnMiddlewareValue, OnResponseFunc, OnResponseReversalFunc, OnResponseValue };
97
+ export type { Current, CurrentResult, CurrentResultValue, DefineBot, DefineBotCallback, DefineBotValue, DefineChildrenCallback, DefineChildrenFunc, DefineChildrenValue, DefinePlatformCallback, DefinePlatformFunc, DefinePlatformValue, OnDataFormatFunc, OnMiddlewareFunc, OnMiddlewareReversalFunc, OnMiddlewareValue, OnResponseFunc, OnResponseReversalFunc, OnResponseValue, OnSelectsFunc };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "alemonjs",
3
- "version": "2.0.14",
3
+ "version": "2.0.16",
4
4
  "description": "bot script",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",
package/lib/app/config.js DELETED
@@ -1,8 +0,0 @@
1
- const EventMessageText = [
2
- 'message.create',
3
- 'private.message.create',
4
- 'interaction.create',
5
- 'private.interaction.create'
6
- ];
7
-
8
- export { EventMessageText };
package/lib/code.js DELETED
@@ -1,27 +0,0 @@
1
- /**
2
- * 结果反馈码
3
- */
4
- // 成功码
5
- const Ok = 2000; // 成功
6
- // 警惕码
7
- const Warn = 2100; // 任意警告
8
- // 失败码
9
- const Fail = 4000; // 未知错误
10
- const FailParams = 4001; // 参数错误
11
- const FailAuth = 4002; // 权限不足
12
- const FailInternal = 5000; // 内部错误
13
- /**
14
- * 结果反馈码
15
- * @description
16
- * - 2000: 成功
17
- */
18
- const ResultCode = {
19
- Ok,
20
- Fail,
21
- FailParams,
22
- Warn,
23
- FailAuth,
24
- FailInternal
25
- };
26
-
27
- export { ResultCode };