alemonjs 1.0.28 → 1.0.30

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.
Files changed (94) hide show
  1. package/README.md +9 -16
  2. package/lib/config/login.js +14 -41
  3. package/lib/config/pup.js +2 -0
  4. package/lib/core/app.js +2 -2
  5. package/lib/core/apps.js +9 -10
  6. package/lib/core/buffer.js +4 -4
  7. package/lib/core/configs.js +15 -0
  8. package/lib/core/dealmsg.js +140 -80
  9. package/lib/core/dialogue.js +11 -16
  10. package/lib/core/ip.js +3 -3
  11. package/lib/core/message.js +1 -3
  12. package/lib/core/plugin.js +100 -2
  13. package/lib/core/puppeteer.js +19 -17
  14. package/lib/core/qrcode.js +2 -2
  15. package/lib/core/screenshot.js +4 -5
  16. package/lib/core/typings.js +0 -1
  17. package/lib/define/api.js +0 -4
  18. package/lib/define/child_process.js +4 -4
  19. package/lib/define/command.js +3 -3
  20. package/lib/define/main.js +14 -9
  21. package/lib/define/map.js +1 -9
  22. package/lib/index.js +0 -4
  23. package/lib/kook/index.js +1 -1
  24. package/lib/kook/login.js +3 -3
  25. package/lib/login.js +2 -2
  26. package/lib/ntqq/index.js +4 -4
  27. package/lib/ntqq/login.js +3 -3
  28. package/lib/ntqq/sdk/config.js +1 -1
  29. package/lib/qq/alemon/message/DIRECT_MESSAGE.js +1 -1
  30. package/lib/qq/alemon/message/GUILD_MEMBERS.js +1 -1
  31. package/lib/qq/alemon/message/MESSAGE.js +1 -1
  32. package/lib/qq/alemon/privatechat.js +1 -1
  33. package/lib/qq/index.js +3 -3
  34. package/lib/qq/login.js +16 -18
  35. package/lib/qq/sdk/api.js +86 -0
  36. package/lib/qq/sdk/config.js +23 -0
  37. package/lib/qq/sdk/index.js +4 -0
  38. package/lib/qq/sdk/intents.js +65 -0
  39. package/lib/qq/sdk/typings.js +15 -0
  40. package/lib/qq/sdk/wss.js +144 -0
  41. package/lib/run.js +4 -0
  42. package/lib/villa/index.js +1 -1
  43. package/lib/villa/login.js +3 -3
  44. package/package.json +4 -9
  45. package/run.js +4 -0
  46. package/types/config/login.d.ts +6 -11
  47. package/types/config/pup.d.ts +2 -0
  48. package/types/config/types.d.ts +1 -2
  49. package/types/core/app.d.ts +2 -2
  50. package/types/core/apps.d.ts +11 -13
  51. package/types/core/buffer.d.ts +4 -4
  52. package/types/core/configs.d.ts +10 -0
  53. package/types/core/dealmsg.d.ts +9 -11
  54. package/types/core/dialogue.d.ts +10 -12
  55. package/types/core/ip.d.ts +3 -3
  56. package/types/core/message.d.ts +1 -1
  57. package/types/core/plugin.d.ts +64 -3
  58. package/types/core/puppeteer.d.ts +16 -12
  59. package/types/core/qrcode.d.ts +2 -2
  60. package/types/core/screenshot.d.ts +4 -4
  61. package/types/core/typings.d.ts +3 -3
  62. package/types/default/types.d.ts +0 -28
  63. package/types/define/api.d.ts +0 -4
  64. package/types/define/child_process.d.ts +4 -4
  65. package/types/define/command.d.ts +3 -3
  66. package/types/define/main.d.ts +2 -2
  67. package/types/define/map.d.ts +1 -2
  68. package/types/define/types.d.ts +5 -0
  69. package/types/login.d.ts +2 -2
  70. package/types/ntqq/sdk/config.d.ts +1 -1
  71. package/types/qq/sdk/api.d.ts +35 -0
  72. package/types/qq/sdk/config.d.ts +12 -0
  73. package/types/qq/sdk/index.d.ts +4 -0
  74. package/types/qq/sdk/intents.d.ts +2 -0
  75. package/types/qq/sdk/typings.d.ts +15 -0
  76. package/types/qq/sdk/wss.d.ts +24 -0
  77. package/types/run.d.ts +4 -0
  78. package/bin/main.js +0 -26
  79. package/lib/discord/alemon/api.js +0 -44
  80. package/lib/discord/alemon/bot.js +0 -11
  81. package/lib/discord/alemon/conversation.js +0 -7
  82. package/lib/discord/alemon/message/PUBLIC_GUILD_MESSAGES.js +0 -185
  83. package/lib/discord/alemon/segment.js +0 -62
  84. package/lib/discord/discord.js +0 -16
  85. package/lib/discord/index.js +0 -50
  86. package/lib/discord/login.js +0 -54
  87. package/types/discord/alemon/api.d.ts +0 -11
  88. package/types/discord/alemon/bot.d.ts +0 -6
  89. package/types/discord/alemon/conversation.d.ts +0 -6
  90. package/types/discord/alemon/message/PUBLIC_GUILD_MESSAGES.d.ts +0 -7
  91. package/types/discord/alemon/segment.d.ts +0 -46
  92. package/types/discord/discord.d.ts +0 -8
  93. package/types/discord/index.d.ts +0 -1
  94. package/types/discord/login.d.ts +0 -7
package/README.md CHANGED
@@ -1,33 +1,26 @@
1
1
  ☞[English document](./README_English.md)
2
2
 
3
- ## Almeon 阿柠檬跨平台开发框架机器人
4
-
5
- > 支持 NtQQ、QQ 频道、Discord、米游社大别野、KOOK
6
-
7
- | 分支 | 类型 | 说明 |
8
- | ----- | ------ | -------------------- |
9
- | main | 核心 | 机器实例 |
10
- | redis | 数据库 | 特殊连接独立 |
11
- | cli | 脚手架 | 开发模板脚手架 |
12
- | web | 网站 | 共享平台插件贡献地址 |
3
+ ## 阿柠檬跨平台开发框架机器人
13
4
 
14
5
  > 需要配置机器人才可启动
15
6
 
16
- 文档查看 OPEN[alemonjs.com](https://alemonjs.com)
7
+ 开发文档 OPEN[https://alemonjs.com](https://alemonjs.com)
17
8
 
18
- 开发模板 GITEE[create-alemonjs](https://gitee.com/ningmengchongshui/alemon/tree/cli/bin/template)
9
+ 类型/接口 OPEN[docs](https://ningmengchongshui.github.io/alemon/)
19
10
 
20
- 开发模板 GITHUB[create-alemonjs](https://github.com/ningmengchongshui/alemon/tree/cli/bin/template)
11
+ 开发模板 GITEE[create-alemonjs](https://gitee.com/ningmengchongshui/alemon/tree/cli/bin)
21
12
 
22
- ### 共享平台
13
+ 开发模板 GITHUB[create-alemonjs](https://github.com/ningmengchongshui/alemon/tree/cli/bin)
23
14
 
24
- > 仓库只做资源收集,对齐安全性不做任何检查,请谨慎选择
15
+ ### 共享平台
25
16
 
26
17
  贡献资源 OPEN[Gitee](https://gitee.com/ningmengchongshui/alemon/blob/web/docs/about/plugins.md)
27
18
 
28
19
  贡献资源 OPEN[Github](https://gitee.com/ningmengchongshui/alemon/blob/web/docs/about/plugins.md)
29
20
 
30
- > 仅限签署开源协议的仓库、不开源将不做考虑范围内
21
+ - 仓库只做资源收集,对齐安全性不做任何检查,请谨慎选择
22
+
23
+ - 仅限签署开源协议的仓库、不开源将不做考虑范围内
31
24
 
32
25
  ## 开源协议
33
26
 
@@ -2,7 +2,6 @@ import redis from '../default/redis.js';
2
2
  import mysql from '../default/mysql.js';
3
3
  import server from '../default/server.js';
4
4
  import puppeteer from '../default/pup.js';
5
- import discord from '../discord/discord.js';
6
5
  import kook from '../kook/kook.js';
7
6
  import villa from '../villa/villa.js';
8
7
  import qq from '../qq/qq.js';
@@ -15,7 +14,6 @@ import ntqq from '../ntqq/ntqq.js';
15
14
  const config = {
16
15
  redis,
17
16
  mysql,
18
- discord,
19
17
  kook,
20
18
  villa,
21
19
  qq,
@@ -24,41 +22,9 @@ const config = {
24
22
  puppeteer
25
23
  };
26
24
  /**
27
- * init config
28
- * @param val
29
- */
30
- export function setBotConfig(val) {
31
- // 分布覆盖
32
- for (const i in val) {
33
- // 当且仅当存在同key的时候才会覆盖默认配置
34
- if (Object.prototype.hasOwnProperty.call(config, i)) {
35
- if (i == 'puppeteer') {
36
- // pup 不用检查 直接覆盖
37
- for (const j in val[i]) {
38
- config[i][j] = val[i][j];
39
- }
40
- }
41
- else {
42
- for (const j in val[i]) {
43
- // 当前仅当同属性名的时候才会覆盖默认配置
44
- if (Object.prototype.hasOwnProperty.call(config[i], j)) {
45
- config[i][j] = val[i][j];
46
- }
47
- else {
48
- console.info('[alemonjs][存在无效参数]', val[i]);
49
- }
50
- }
51
- }
52
- }
53
- else {
54
- console.info('[alemonjs][存在无效参数]', val[i]);
55
- }
56
- }
57
- }
58
- /**
59
- * set
60
- * @param key
61
- * @param val
25
+ * 设置机器人基础配置
26
+ * @param key 配置名
27
+ * @param val 配置值
62
28
  */
63
29
  export function setBotConfigByKey(key, val) {
64
30
  if (key == 'puppeteer') {
@@ -74,15 +40,22 @@ export function setBotConfigByKey(key, val) {
74
40
  config[key][item] = val[item];
75
41
  }
76
42
  else {
77
- console.info('[alemonjs][存在无效参数]', val[item]);
43
+ try {
44
+ config[key] = {};
45
+ config[key] = val[item];
46
+ console.info('[alemonjs][新增KEY成功]');
47
+ }
48
+ catch {
49
+ console.info('[alemonjs][新增KEY失败]');
50
+ }
78
51
  }
79
52
  }
80
53
  }
81
54
  }
82
55
  /**
83
- * get
84
- * @param key
85
- * @returns
56
+ * g得到机器人基础配置
57
+ * @param key 配置名
58
+ * @returns 得到配置值
86
59
  */
87
60
  export function getBotConfigByKey(key) {
88
61
  return config[key];
package/lib/config/pup.js CHANGED
@@ -60,7 +60,9 @@ else if (platform == 'linux' || platform == 'android') {
60
60
  }
61
61
  }
62
62
  /**
63
+ * 得到pup可寻地址
63
64
  * @type {import("puppeteer").Configuration}
65
+ * @returns 得到配置对象
64
66
  */
65
67
  export function getPupPath() {
66
68
  return {
package/lib/core/app.js CHANGED
@@ -3,7 +3,7 @@ const APP = {};
3
3
  /**
4
4
  * 得到应用
5
5
  * @param key 插件名
6
- * @returns
6
+ * @returns 得到应用集
7
7
  */
8
8
  export function getApp(key) {
9
9
  return APP[key];
@@ -27,7 +27,7 @@ export function delApp(key) {
27
27
  }
28
28
  /**
29
29
  * 得到应用
30
- * @returns
30
+ * @returns 得到指定应用值
31
31
  */
32
32
  export function getAppKey() {
33
33
  const arr = [];
package/lib/core/apps.js CHANGED
@@ -4,16 +4,16 @@ import { setMessage } from './message.js';
4
4
  import { setApp } from './app.js';
5
5
  /**
6
6
  * 得到执行路径
7
- * @param url
8
- * @returns
7
+ * @param url import.meta.url
8
+ * @returns AppName目录名
9
9
  */
10
10
  export function getAppPath(url) {
11
11
  return dirname(fileURLToPath(url)).replace(/\\/g, '/');
12
12
  }
13
13
  /**
14
14
  * 得到执行目录
15
- * @param {} url
16
- * @returns
15
+ * @param {} url import.meta.url
16
+ * @returns AppName目录名
17
17
  */
18
18
  export function getAppName(url) {
19
19
  return basename(getAppPath(url));
@@ -21,15 +21,15 @@ export function getAppName(url) {
21
21
  /**
22
22
  * 创建应用对象
23
23
  * @param url import.meta.url
24
- * @returns
24
+ * @returns AppName目录名
25
25
  */
26
26
  export function createApps(url) {
27
27
  return createApp(getAppName(url));
28
28
  }
29
29
  /**
30
30
  * 创建应用对象
31
- * @param AppName
32
- * @returns
31
+ * @param AppName 目录名 getAppName(import.meta.url)
32
+ * @returns 应用app对象
33
33
  */
34
34
  export function createApp(AppName) {
35
35
  /**
@@ -43,8 +43,8 @@ export function createApp(AppName) {
43
43
  return {
44
44
  /**
45
45
  * 重定义消息
46
- * @param fnc
47
- * @returns
46
+ * @param fnc 回调函数
47
+ * @returns 是否成功定义
48
48
  */
49
49
  setMessage: (fnc) => {
50
50
  try {
@@ -106,7 +106,6 @@ export function createApp(AppName) {
106
106
  },
107
107
  /**
108
108
  * 挂起应用
109
- * @returns
110
109
  */
111
110
  mount: () => {
112
111
  try {
@@ -4,8 +4,8 @@ import https from 'https';
4
4
  import { join } from 'path';
5
5
  /**
6
6
  * 异步请求图片
7
- * @param url
8
- * @returns
7
+ * @param url 网络地址
8
+ * @returns buffer
9
9
  */
10
10
  export function getUrlbuffer(url) {
11
11
  return new Promise((resolve, reject) => {
@@ -26,8 +26,8 @@ export function getUrlbuffer(url) {
26
26
  }
27
27
  /**
28
28
  * 读取本地图片
29
- * @param path 根路径
30
- * @returns
29
+ * @param path 本地地址 /public/img/xx.png
30
+ * @returns buffer
31
31
  */
32
32
  export function getPathBuffer(path) {
33
33
  // 读取本地图片
@@ -1,3 +1,8 @@
1
+ /**
2
+ * ***********
3
+ * 插件解析配置
4
+ * ***********
5
+ */
1
6
  const ApplicationProcessingConfiguration = {
2
7
  dir: '/application',
3
8
  main: '/index',
@@ -7,12 +12,22 @@ const ApplicationProcessingConfiguration = {
7
12
  route: '/public/defset',
8
13
  regex: true
9
14
  };
15
+ /**
16
+ * 设置插件解析配置
17
+ * @param key 配置名
18
+ * @param val 配置值
19
+ */
10
20
  export function setAppProCoinfg(key, val) {
11
21
  // 当前仅当同属性名的时候才会覆盖默认配置
12
22
  if (Object.prototype.hasOwnProperty.call(ApplicationProcessingConfiguration, key)) {
13
23
  ApplicationProcessingConfiguration[key] = val;
14
24
  }
15
25
  }
26
+ /**
27
+ * 得到插件解析配置
28
+ * @param key 配置名
29
+ * @returns 配置值
30
+ */
16
31
  export function getAppProCoinfg(key) {
17
32
  return ApplicationProcessingConfiguration[key];
18
33
  }
@@ -9,6 +9,7 @@ import { conversationHandlers, getConversationState } from './dialogue.js';
9
9
  import { getAppProCoinfg } from './configs.js';
10
10
  const Command = {};
11
11
  const CommandNotMessage = {};
12
+ const CommandApp = {};
12
13
  /**
13
14
  * 机器人统计
14
15
  */
@@ -18,7 +19,7 @@ let mergedRegex;
18
19
  /**
19
20
  * 得到机器人帮助
20
21
  * @param AppName
21
- * @returns
22
+ * @returns 指令对象
22
23
  */
23
24
  export function getPluginHelp(AppName) {
24
25
  const c = getAppProCoinfg('regex');
@@ -63,8 +64,8 @@ function createPluginHelp() {
63
64
  }
64
65
  /**
65
66
  * 应用挂载
66
- * @param AppsObj
67
- * @param appname
67
+ * @param AppsObj 插件集成对象
68
+ * @param appname 插件名
68
69
  */
69
70
  async function synthesis(AppsObj, appname) {
70
71
  // 没有记载
@@ -72,6 +73,7 @@ async function synthesis(AppsObj, appname) {
72
73
  plugins[appname] = [];
73
74
  }
74
75
  for (const item in AppsObj) {
76
+ // 解析class
75
77
  const keys = new AppsObj[item]();
76
78
  // 控制类型
77
79
  const eventType = keys['eventType'] ?? 'CREATE';
@@ -81,6 +83,25 @@ async function synthesis(AppsObj, appname) {
81
83
  keys['rule'].length == 0) {
82
84
  continue;
83
85
  }
86
+ /**
87
+ * 收藏app
88
+ */
89
+ let x = 1;
90
+ let itemX = item;
91
+ const T = true;
92
+ while (T) {
93
+ // 名字不重复
94
+ if (!Object.prototype.hasOwnProperty.call(CommandApp, itemX)) {
95
+ break;
96
+ }
97
+ // 同名了 需要重命名
98
+ itemX = `${item}${x}`;
99
+ x++;
100
+ }
101
+ CommandApp[itemX] = {
102
+ name: appname,
103
+ APP: AppsObj[item]
104
+ };
84
105
  // 指令不存在
85
106
  for await (const key of keys['rule']) {
86
107
  if (!key['fnc'] ||
@@ -93,8 +114,6 @@ async function synthesis(AppsObj, appname) {
93
114
  const priority = key['priority'] ?? keys['priority'] ?? 9000;
94
115
  // 得到函数名
95
116
  const fncName = key['fnc'];
96
- // 得到函数
97
- const fnc = keys[fncName];
98
117
  const doc = key['doc'] ?? '';
99
118
  const dsc = key['dsc'] ?? '';
100
119
  // 如果类型正确
@@ -103,6 +122,8 @@ async function synthesis(AppsObj, appname) {
103
122
  const event = 'MESSAGES';
104
123
  // 得到解析
105
124
  const reg = key['reg'];
125
+ if (!reg)
126
+ continue;
106
127
  // 推送
107
128
  plugins[appname].push({
108
129
  event: event,
@@ -119,8 +140,7 @@ async function synthesis(AppsObj, appname) {
119
140
  reg: new RegExp(reg),
120
141
  priority,
121
142
  fncName,
122
- fnc,
123
- AppName: appname
143
+ APP: itemX
124
144
  });
125
145
  }
126
146
  else {
@@ -139,9 +159,9 @@ async function synthesis(AppsObj, appname) {
139
159
  event: event,
140
160
  eventType: eventType,
141
161
  priority,
162
+ reg: /./,
142
163
  fncName,
143
- fnc,
144
- AppName: appname
164
+ APP: itemX
145
165
  });
146
166
  }
147
167
  }
@@ -150,7 +170,7 @@ async function synthesis(AppsObj, appname) {
150
170
  }
151
171
  /**
152
172
  * 加载应用插件
153
- * @param dir
173
+ * @param dir 插件路径
154
174
  */
155
175
  async function loadPlugins(dir) {
156
176
  if (!existsSync(dir))
@@ -169,9 +189,7 @@ async function loadPlugins(dir) {
169
189
  return true;
170
190
  return !close.test(item);
171
191
  });
172
- /**
173
- * 动态扫描
174
- */
192
+ //动态扫描
175
193
  const main = getAppProCoinfg('main');
176
194
  const type = getAppProCoinfg('type');
177
195
  for await (const appname of apps) {
@@ -189,17 +207,21 @@ async function loadPlugins(dir) {
189
207
  * 初始化应用
190
208
  */
191
209
  function dataInit() {
210
+ // 清事件
192
211
  for (const item of EventEnum) {
193
212
  if (isNaN(Number(item))) {
194
213
  Command[item] = [];
195
214
  CommandNotMessage[item] = [];
196
215
  }
197
216
  }
217
+ // 清class
218
+ for (const item in CommandApp) {
219
+ delete CommandApp[item];
220
+ }
198
221
  return;
199
222
  }
200
223
  /**
201
- * 应用初始化
202
- * @returns
224
+ * 插件初始化
203
225
  */
204
226
  export async function appsInit() {
205
227
  // 清空当前的apps
@@ -236,83 +258,112 @@ export async function appsInit() {
236
258
  createPluginHelp();
237
259
  // 打印
238
260
  console.info(`[LOAD] APPS*${Object.keys(plugins).length} `);
239
- return;
240
261
  }
241
262
  /**
242
- * 得到大正则
243
- * @returns
263
+ * 得到指令大正则
264
+ * @returns 正则
244
265
  */
245
266
  export function getMergedRegex() {
246
267
  return mergedRegex;
247
268
  }
248
269
  /**
249
- * 初始化应用
250
- * @returns
270
+ * 扫描插件
251
271
  */
252
272
  export async function loadInit() {
253
273
  await loadPlugins(join(process.cwd(), getAppProCoinfg('dir')));
254
- return;
255
274
  }
256
275
  /**
257
276
  * 指令匹配
258
- * @param e
259
- * @returns
277
+ * @param e alemonjs message
278
+ * @returns 是否处理完成
260
279
  */
261
280
  export async function InstructionMatching(e) {
262
281
  /**
263
- * 获取对话状态
282
+ * 对话机
264
283
  */
265
284
  const state = await getConversationState(e.user_id);
266
- /**
267
- * 获取对话处理函数
268
- */
269
285
  const handler = conversationHandlers.get(e.user_id);
270
- /**
271
- * 拦截
272
- */
273
286
  if (handler && state) {
274
- /**
275
- * 如果用户处于对话状态
276
- * 则调用对话处理函数
277
- */
278
287
  await handler(e, state);
279
288
  return true;
280
289
  }
281
290
  /**
282
- * 撤回事件 匹配不到事件 或者 大正则不匹配
291
+ *
292
+ */
293
+ const APPCACHE = {};
294
+ /**
295
+ * 上下文
296
+ */
297
+ for (const item in CommandApp) {
298
+ const { name, APP } = CommandApp[item];
299
+ const AppFnc = getMessage(name);
300
+ try {
301
+ if (typeof AppFnc == 'function')
302
+ e = AppFnc(e);
303
+ const app = new APP(e);
304
+ // 设置this.e
305
+ app.e = e;
306
+ // 如果存在用户上下文
307
+ if (app.getContext) {
308
+ // 得到缓存
309
+ const context = app.getContext();
310
+ // 是否为 null && undefined && '' && [] && {}
311
+ if (!lodash.isEmpty(context)) {
312
+ // 得到缓存中的e消息
313
+ for (const fnc in context) {
314
+ // 丢给自己
315
+ if (app[fnc])
316
+ app[fnc](context[fnc]);
317
+ }
318
+ return;
319
+ }
320
+ }
321
+ // 如果存在频道上下文
322
+ if (app.getContextGroup) {
323
+ // 得到缓存
324
+ const context = app.getContextGroup();
325
+ // 是否为 null && undefined && '' && [] && {}
326
+ if (!lodash.isEmpty(context)) {
327
+ // 得到缓存中的e消息
328
+ for (const fnc in context) {
329
+ // 丢给自己
330
+ if (app[fnc])
331
+ app[fnc](context[fnc]);
332
+ return;
333
+ }
334
+ }
335
+ }
336
+ APPCACHE[item] = app;
337
+ }
338
+ catch (err) {
339
+ console.log('[AlemonJS]上下文出错', err);
340
+ return;
341
+ }
342
+ }
343
+ /**
344
+ * 撤回事件 || 匹配不到事件 || 大正则不匹配
283
345
  */
284
346
  if (e.isRecall || !Command[e.event] || !mergedRegex.test(e.msg))
285
347
  return true;
286
348
  /**
287
- * 循环所有指令 用 awwat确保指令顺序
349
+ * 循环所有指令
288
350
  */
289
- for await (const data of Command[e.event]) {
351
+ for (const data of Command[e.event]) {
290
352
  if (e.eventType != data.eventType ||
291
353
  data.reg === undefined ||
292
354
  !data.reg.test(e.msg)) {
293
355
  continue;
294
356
  }
295
- const AppFnc = getMessage(data.AppName);
296
357
  try {
297
- if (typeof AppFnc == 'function')
298
- e = AppFnc(e);
299
- const res = await data
300
- .fnc(e)
301
- .then((res) => {
302
- console.info(`\n[${data.event}][${data.AppName}][${data.fncName}][${true}]`);
303
- return res;
304
- })
305
- .catch((err) => {
306
- console.error(`\n[${data.event}][${data.AppName}][${data.fncName}][${false}]\n[${err}]`);
307
- return false;
308
- });
309
- // 不是false都直接中断匹配
310
- if (res !== false) {
358
+ const app = APPCACHE[data.APP];
359
+ const res = await app[data.fncName](e)
360
+ .then(info(data))
361
+ .catch(logErr(data));
362
+ if (res != false)
311
363
  break;
312
- }
313
364
  }
314
365
  catch (err) {
315
- logErr(err, data);
366
+ logErr(data)(err);
316
367
  return false;
317
368
  }
318
369
  }
@@ -321,47 +372,56 @@ export async function InstructionMatching(e) {
321
372
  /**
322
373
  * 不匹配指令的方法
323
374
  * 只用匹配类型函数
324
- * @param e
325
- * @returns
375
+ * @param e alemonjs message
376
+ * @returns 是否处理完成
326
377
  */
327
378
  export async function typeMessage(e) {
328
379
  if (!CommandNotMessage[e.event])
329
380
  return true;
381
+ const APPCACHE = {};
382
+ for (const item in CommandApp) {
383
+ const { name, APP } = CommandApp[item];
384
+ const AppFnc = getMessage(name);
385
+ try {
386
+ if (typeof AppFnc == 'function')
387
+ e = AppFnc(e);
388
+ const app = new APP(e);
389
+ app.e = e;
390
+ APPCACHE[item] = app;
391
+ }
392
+ catch (err) {
393
+ console.log('[AlemonJS]上下文出错', err);
394
+ return;
395
+ }
396
+ }
330
397
  // 循环查找
331
398
  for (const data of CommandNotMessage[e.event]) {
332
399
  if (e.eventType != data.eventType)
333
400
  continue;
334
401
  try {
335
- const AppFnc = getMessage(data.AppName);
336
- if (typeof AppFnc == 'function')
337
- e = AppFnc(e);
338
- const res = await data
339
- .fnc(e)
340
- .then((res) => {
341
- console.info(`\n[${data.event}][${data.AppName}][${data.fncName}][${true}]`);
342
- return res;
343
- })
344
- .catch((err) => {
345
- console.error(`\n[${data.event}][${data.AppName}][${data.fncName}][${false}]\n[${err}]`);
346
- return false;
347
- });
348
- if (res) {
402
+ const app = APPCACHE[data.APP];
403
+ const res = await app[data.fncName](e)
404
+ .then(info(data))
405
+ .catch(logErr(data));
406
+ if (res != false)
349
407
  break;
350
- }
351
408
  }
352
409
  catch (err) {
353
- logErr(err, data);
410
+ logErr(data)(err);
354
411
  continue;
355
412
  }
356
413
  }
357
414
  return true;
358
415
  }
359
- /**
360
- * 错误信息反馈
361
- * @param err
362
- * @param data
363
- */
364
- function logErr(err, data) {
365
- console.error(`\n[${data.event}][${data.AppName}][${data.fncName}][${false}]\n[${err}]`);
366
- return;
416
+ function logErr(data) {
417
+ return (err) => {
418
+ console.error(`\n[${data.event}][${data.fncName}][${false}]\n[${err}]`);
419
+ return false;
420
+ };
421
+ }
422
+ function info(data) {
423
+ return (res) => {
424
+ console.info(`\n[${data.event}][${data.fncName}][${true}]`);
425
+ return res;
426
+ };
367
427
  }