alemonjs 2.0.14 → 2.0.15

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.
@@ -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,21 @@ 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 ? processor_repeated_clear_time_min : processor_repeated_clear_time_max;
57
54
  setTimeout(callback, time);
58
55
  };
59
- setTimeout(callback, MIN_TIME);
56
+ setTimeout(callback, processor_repeated_clear_time_min);
60
57
  /**
61
58
  * 消息处理器
62
59
  * @param name
@@ -67,13 +64,13 @@ setTimeout(callback, MIN_TIME);
67
64
  const onProcessor = (name, event, data) => {
68
65
  const Now = Date.now();
69
66
  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;
67
+ const EVENT_INTERVAL = value?.processor?.repeated_event_time ?? processor_repeated_event_time;
68
+ const USER_INTERVAL = value?.processor?.repeated_user_time ?? processor_repeated_user_time;
72
69
  if (event['MessageId']) {
73
70
  // 消息过长,要减少消息的长度
74
71
  const MessageId = createHash(event['MessageId']);
75
72
  // 重复消息
76
- if (filter({ Now, INTERVAL: EVENT_INTERVAL, store: eventStore }, MessageId)) {
73
+ if (filter({ Now, INTERVAL: EVENT_INTERVAL, store: ProcessorEventAutoClearMap }, MessageId)) {
77
74
  return;
78
75
  }
79
76
  }
@@ -81,7 +78,7 @@ const onProcessor = (name, event, data) => {
81
78
  // 编号过长,要减少编号的长度
82
79
  const UserId = createHash(event['UserId']);
83
80
  // 频繁操作
84
- if (filter({ Now, INTERVAL: USER_INTERVAL, store: userStore }, UserId)) {
81
+ if (filter({ Now, INTERVAL: USER_INTERVAL, store: ProcessorEventUserAudoClearMap }, UserId)) {
85
82
  return;
86
83
  }
87
84
  }
@@ -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
  import { ChildrenApp } from './store.js';
3
3
  import { createResult } from './utils.js';
4
4
 
@@ -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
  /**
@@ -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
  /**
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,4 +1,4 @@
1
- import { ResultCode } from '../code.js';
1
+ import { ResultCode } from '../core/code.js';
2
2
 
3
3
  /**
4
4
  * 创建数据格式。
@@ -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/index.d.ts CHANGED
@@ -18,7 +18,7 @@ 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';
@@ -30,10 +30,10 @@ export { useObserver, useSubscribe } from './app/hook-use-subscribe.js';
30
30
  export { loadChildren, loadChildrenFile, loadModule, moduleChildrenFiles } from './app/load.js';
31
31
  export { createSendDataFormat, 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,7 +1,7 @@
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';
@@ -13,7 +13,7 @@ export { useObserver, useSubscribe } from './app/hook-use-subscribe.js';
13
13
  export { loadChildren, loadChildrenFile, loadModule, moduleChildrenFiles } from './app/load.js';
14
14
  export { createSendDataFormat, 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.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';
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,12 @@ 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 { ResultCode } from './core/code.js';
12
12
  import 'node:fs';
13
13
  import 'log4js';
14
14
  import { useState } from './app/hook-use-state.js';
15
15
  import './app/message-format.js';
16
+ import { file_prefix_common, default_login, default_platform_prefix, default_platform_common_prefix, file_prefix_framework } from './core/variable.js';
16
17
 
17
18
  const loadConfig = () => {
18
19
  const value = getConfigValue() ?? {};
@@ -51,9 +52,9 @@ const run = (input) => {
51
52
  const start = async (input, pm) => {
52
53
  const cfg = getConfig();
53
54
  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/`;
55
+ const login$1 = platform$1 ? platform$1.replace(file_prefix_common, '') : null;
56
+ const login = login$1 ?? cfg.argv?.login ?? cfg.value?.login ?? default_login;
57
+ const prefix = platform$1 && file_prefix_framework.test(platform$1) ? default_platform_prefix : default_platform_common_prefix;
57
58
  const platform = `${prefix}${login}`;
58
59
  // 启动机器人
59
60
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "alemonjs",
3
- "version": "2.0.14",
3
+ "version": "2.0.15",
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 };