alemonjs 2.0.13 → 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,7 +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 '../core/config.js';
5
6
 
6
7
  /**
7
8
  * 打印日志
@@ -74,19 +75,11 @@ const expendCycle = async (valueEvent, select) => {
74
75
  }
75
76
  expendMiddleware(valueEvent, select, nextMount);
76
77
  };
77
- if (process.env?.ALEMONJS_EVENT_LOGS_CHANNEL_ID) {
78
- try {
79
- const channelIds = JSON.parse(process.env?.ALEMONJS_EVENT_LOGS_CHANNEL_ID);
80
- if (channelIds && channelIds.length > 0 && channelIds.includes(valueEvent['ChannelId'])) {
81
- showLog(valueEvent, select);
82
- }
83
- }
84
- catch (e) {
85
- logger.error({
86
- code: ResultCode.FailParams,
87
- message: 'ALEMONJS_EVENT_LOGS_CHANNEL_ID is not json string',
88
- data: null
89
- });
78
+ const value = getConfigValue() ?? {};
79
+ if (Array.isArray(value?.logs?.channel_id)) {
80
+ const channelIds = value?.logs?.channel_id;
81
+ if (channelIds && channelIds.length > 0 && channelIds.includes(valueEvent['ChannelId'])) {
82
+ showLog(valueEvent, select);
90
83
  }
91
84
  }
92
85
  else {
@@ -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 消息处理快
@@ -61,12 +61,7 @@ const expendEvent = async (valueEvent, select, next) => {
61
61
  //
62
62
  try {
63
63
  const app = await import(`file://${file.path}`);
64
- if (!app?.default) {
65
- // 继续
66
- nextEvent();
67
- return;
68
- }
69
- if (!app.default?.current) {
64
+ if (!app?.default || !app?.default?.current || !app?.default?.select) {
70
65
  // 继续
71
66
  nextEvent();
72
67
  return;
@@ -80,23 +75,12 @@ const expendEvent = async (valueEvent, select, next) => {
80
75
  return;
81
76
  }
82
77
  }
83
- // 如果是数组
84
- if (Array.isArray(app.default?.select)) {
85
- // 没有匹配到
86
- if (!app.default.select.includes(select)) {
87
- // 继续
88
- nextEvent();
89
- return;
90
- }
91
- // 如果不是数组
92
- }
93
- else {
94
- // 没有匹配到
95
- if (app.default?.select !== select) {
96
- // 继续
97
- nextEvent();
98
- return;
99
- }
78
+ const selects = Array.isArray(app.default.select) ? app.default.select : [app.default.select];
79
+ // 没有匹配到
80
+ if (!selects.includes(select)) {
81
+ // 继续
82
+ nextEvent();
83
+ return;
100
84
  }
101
85
  // 消息类型数据
102
86
  if (EventMessageText.includes(select)) {
@@ -109,87 +93,59 @@ const expendEvent = async (valueEvent, select, next) => {
109
93
  }
110
94
  }
111
95
  }
112
- if (Array.isArray(app.default.current)) {
113
- let i = 0;
114
- let isNext = false;
115
- const onRes = (res) => {
116
- if (isNext) {
117
- // 内部调用了next
118
- return;
119
- }
120
- if (Array.isArray(res)) {
121
- if (res.length > 0) {
122
- // 发送数据
123
- Send(...res);
124
- }
125
- }
126
- else if (typeof res === 'object') {
127
- if (Array.isArray(res.data)) {
128
- // 发送数据
129
- Send(...res.data);
130
- }
131
- }
132
- };
133
- const start = async () => {
134
- if (i >= app.default.current.length)
135
- return;
136
- if (isNext)
137
- return;
138
- if (isAsyncFunction(app.default.current[i])) {
139
- const res = await app.default.current[i](valueEvent, (...cns) => {
140
- isNext = true;
141
- nextEvent(...cns);
142
- });
143
- onRes(res);
144
- }
145
- else {
146
- const res = app.default.current[i](valueEvent, (...cns) => {
147
- isNext = true;
148
- nextEvent(...cns);
149
- });
150
- onRes(res);
151
- }
152
- ++i;
153
- await start();
154
- };
155
- await start();
156
- }
157
- else {
158
- let isNext = false;
159
- const onRes = (res) => {
160
- if (isNext) {
161
- return;
162
- }
163
- if (typeof res === 'boolean') {
96
+ const currents = Array.isArray(app.default.current)
97
+ ? app.default.current
98
+ : [app.default.current];
99
+ let index = 0;
100
+ let isClose = false;
101
+ let isNext = false;
102
+ const onRes = (res) => {
103
+ if (!res) {
104
+ isClose = true;
105
+ return;
106
+ }
107
+ if (Array.isArray(res)) {
108
+ if (res.length > 0) {
109
+ // 发送数据
110
+ Send(...res);
164
111
  }
165
- else if (Array.isArray(res)) {
166
- if (res.length > 0) {
167
- Send(...res);
168
- }
112
+ isClose = true;
113
+ }
114
+ else if (typeof res === 'object') {
115
+ if (Array.isArray(res.data)) {
116
+ // 发送数据
117
+ Send(...res.data);
169
118
  }
170
- else if (typeof res === 'object') {
171
- if (Array.isArray(res.data)) {
172
- // 发送数据
173
- Send(...res.data);
174
- }
119
+ if (!res.allowGrouping) {
120
+ isClose = true;
175
121
  }
176
- };
177
- // 这里是否继续时 next 说了算
178
- if (isAsyncFunction(app.default?.current)) {
179
- const res = await app.default?.current(valueEvent, (...cns) => {
122
+ }
123
+ };
124
+ const start = async () => {
125
+ if (index >= currents.length)
126
+ return;
127
+ if (isNext)
128
+ return;
129
+ if (isClose)
130
+ return;
131
+ if (isAsyncFunction(currents[index])) {
132
+ const res = await currents[index](valueEvent, (...cns) => {
180
133
  isNext = true;
181
134
  nextEvent(...cns);
182
135
  });
183
136
  onRes(res);
184
137
  }
185
138
  else {
186
- const res = app.default?.current(valueEvent, (...cns) => {
139
+ const res = currents[index](valueEvent, (...cns) => {
187
140
  isNext = true;
188
141
  nextEvent(...cns);
189
142
  });
190
143
  onRes(res);
191
144
  }
192
- }
145
+ ++index;
146
+ start();
147
+ };
148
+ start();
193
149
  }
194
150
  catch (err) {
195
151
  showErrorModule(err);
@@ -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 消息处理快
@@ -61,12 +61,7 @@ const expendMiddleware = async (valueEvent, select, next) => {
61
61
  }
62
62
  try {
63
63
  const app = await import(`file://${file.path}`);
64
- if (!app?.default) {
65
- // 继续
66
- nextMiddleware();
67
- return;
68
- }
69
- if (!app.default.current) {
64
+ if (!app?.default || !app?.default?.current || !app?.default?.select) {
70
65
  // 继续
71
66
  nextMiddleware();
72
67
  return;
@@ -90,108 +85,69 @@ const expendMiddleware = async (valueEvent, select, next) => {
90
85
  }
91
86
  }
92
87
  }
93
- // 是数组
94
- if (Array.isArray(app.default?.select)) {
95
- // 不包含
96
- if (!app.default?.select.includes(select)) {
97
- // 继续
98
- nextMiddleware();
99
- return;
100
- }
101
- // 不是数组
88
+ const selects = Array.isArray(app.default.select) ? app.default.select : [app.default.select];
89
+ if (!selects.includes(select)) {
90
+ // 继续
91
+ nextMiddleware();
92
+ return;
102
93
  }
103
- else {
104
- // 不匹配
105
- if (app.default?.select !== select) {
106
- // 继续
107
- nextMiddleware();
108
- return;
94
+ const currents = Array.isArray(app.default.current)
95
+ ? app.default.current
96
+ : [app.default.current];
97
+ let index = 0;
98
+ let isClose = false;
99
+ let isNext = false;
100
+ /**
101
+ *
102
+ * @param res
103
+ * @returns
104
+ */
105
+ const onRes = (res) => {
106
+ if (!res) {
107
+ isClose = true;
109
108
  }
110
- }
111
- if (Array.isArray(app.default.current)) {
112
- let i = 0;
113
- let isNext = false;
114
- /**
115
- *
116
- * @param res
117
- * @returns
118
- */
119
- const onRes = (res) => {
120
- if (isNext) {
121
- return;
109
+ else if (Array.isArray(res)) {
110
+ if (res.length > 0) {
111
+ // 发送数据
112
+ Send(...res);
122
113
  }
123
- if (Array.isArray(res)) {
124
- if (res.length > 0) {
125
- // 发送数据
126
- Send(...res);
127
- }
128
- }
129
- else if (typeof res === 'object') {
130
- if (Array.isArray(res.data)) {
131
- // 发送数据
132
- Send(...res.data);
133
- }
134
- }
135
- };
136
- const start = async () => {
137
- if (i >= app.default.current.length)
138
- return;
139
- if (isNext)
140
- return;
141
- if (isAsyncFunction(app.default.current[i])) {
142
- const res = await app.default.current[i](valueEvent, (...cns) => {
143
- isNext = true;
144
- nextMiddleware(...cns);
145
- });
146
- onRes(res);
147
- }
148
- else {
149
- const res = app.default.current[i](valueEvent, (...cns) => {
150
- isNext = true;
151
- nextMiddleware(...cns);
152
- });
153
- onRes(res);
154
- }
155
- ++i;
156
- await start();
157
- };
158
- await start();
159
- }
160
- else {
161
- let isNext = false;
162
- const onRes = (res) => {
163
- if (isNext) {
164
- return;
165
- }
166
- if (Array.isArray(res)) {
167
- if (res.length > 0) {
168
- // 发送数据
169
- Send(...res);
170
- }
114
+ isClose = true;
115
+ }
116
+ else if (typeof res === 'object') {
117
+ if (Array.isArray(res.data)) {
118
+ // 发送数据
119
+ Send(...res.data);
171
120
  }
172
- else if (typeof res === 'object') {
173
- if (Array.isArray(res.data)) {
174
- // 发送数据
175
- Send(...res.data);
176
- }
121
+ if (!res.allowGrouping) {
122
+ isClose = true;
177
123
  }
178
- };
179
- // 这里是否继续时 next 说了算
180
- if (isAsyncFunction(app.default?.current)) {
181
- const res = await app.default?.current(valueEvent, (...cns) => {
124
+ }
125
+ };
126
+ const start = async () => {
127
+ if (index >= currents.length)
128
+ return;
129
+ if (isNext)
130
+ return;
131
+ if (isClose)
132
+ return;
133
+ if (isAsyncFunction(currents[index])) {
134
+ const res = await currents[index](valueEvent, (...cns) => {
182
135
  isNext = true;
183
136
  nextMiddleware(...cns);
184
137
  });
185
138
  onRes(res);
186
139
  }
187
140
  else {
188
- const res = app.default?.current(valueEvent, (...cns) => {
141
+ const res = currents[index](valueEvent, (...cns) => {
189
142
  isNext = true;
190
143
  nextMiddleware(...cns);
191
144
  });
192
145
  onRes(res);
193
146
  }
194
- }
147
+ ++index;
148
+ start();
149
+ };
150
+ start();
195
151
  }
196
152
  catch (err) {
197
153
  showErrorModule(err);
@@ -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
@@ -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, 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, OnMiddlewareFunc, OnMiddlewareReversalFunc, OnMiddlewareValue, OnResponseFunc, OnResponseReversalFunc, OnResponseValue } 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,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 {
@@ -11,10 +11,11 @@ type CurrentResult = {
11
11
  data?: DataEnums[];
12
12
  [key: string]: any;
13
13
  };
14
+ type CurrentResultValue = void | CurrentResult['allowGrouping'] | CurrentResult | CurrentResult['data'];
14
15
  /**
15
16
  * 当前事件
16
17
  */
17
- type Current<T extends EventKeys> = (event: Events[T], next: Next) => void | CurrentResult['allowGrouping'] | CurrentResult | CurrentResult['data'];
18
+ type Current<T extends EventKeys> = (event: Events[T], next: Next) => CurrentResultValue;
18
19
  /**
19
20
  * 定义一个响应
20
21
  */
@@ -85,4 +86,4 @@ type DefineBotValue = DefinePlatformValue;
85
86
  */
86
87
  type DefineBot = DefinePlatformFunc;
87
88
 
88
- export type { Current, CurrentResult, DefineBot, DefineBotCallback, DefineBotValue, DefineChildrenCallback, DefineChildrenFunc, DefineChildrenValue, DefinePlatformCallback, DefinePlatformFunc, DefinePlatformValue, OnMiddlewareFunc, OnMiddlewareReversalFunc, OnMiddlewareValue, OnResponseFunc, OnResponseReversalFunc, OnResponseValue };
89
+ export type { Current, CurrentResult, CurrentResultValue, DefineBot, DefineBotCallback, DefineBotValue, DefineChildrenCallback, DefineChildrenFunc, DefineChildrenValue, DefinePlatformCallback, DefinePlatformFunc, DefinePlatformValue, OnMiddlewareFunc, OnMiddlewareReversalFunc, OnMiddlewareValue, OnResponseFunc, OnResponseReversalFunc, OnResponseValue };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "alemonjs",
3
- "version": "2.0.13",
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 };