alemonjs 1.0.29 → 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 (44) hide show
  1. package/README.md +8 -6
  2. package/lib/config/login.js +6 -6
  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 +51 -51
  9. package/lib/core/dialogue.js +11 -16
  10. package/lib/core/ip.js +2 -2
  11. package/lib/core/message.js +1 -3
  12. package/lib/core/plugin.js +10 -7
  13. package/lib/core/puppeteer.js +10 -10
  14. package/lib/core/qrcode.js +2 -2
  15. package/lib/core/screenshot.js +4 -5
  16. package/lib/define/child_process.js +4 -4
  17. package/lib/define/command.js +3 -3
  18. package/lib/define/main.js +2 -2
  19. package/lib/define/map.js +1 -1
  20. package/lib/login.js +2 -2
  21. package/lib/run.js +4 -0
  22. package/package.json +3 -1
  23. package/run.js +4 -0
  24. package/types/config/login.d.ts +6 -6
  25. package/types/config/pup.d.ts +2 -0
  26. package/types/core/app.d.ts +2 -2
  27. package/types/core/apps.d.ts +11 -13
  28. package/types/core/buffer.d.ts +4 -4
  29. package/types/core/configs.d.ts +10 -0
  30. package/types/core/dealmsg.d.ts +9 -11
  31. package/types/core/dialogue.d.ts +9 -11
  32. package/types/core/ip.d.ts +2 -2
  33. package/types/core/message.d.ts +1 -1
  34. package/types/core/plugin.d.ts +10 -7
  35. package/types/core/puppeteer.d.ts +10 -10
  36. package/types/core/qrcode.d.ts +2 -2
  37. package/types/core/screenshot.d.ts +4 -4
  38. package/types/core/typings.d.ts +1 -1
  39. package/types/define/child_process.d.ts +4 -4
  40. package/types/define/command.d.ts +3 -3
  41. package/types/define/main.d.ts +2 -2
  42. package/types/define/map.d.ts +1 -1
  43. package/types/login.d.ts +2 -2
  44. package/types/run.d.ts +4 -0
package/README.md CHANGED
@@ -1,10 +1,12 @@
1
1
  ☞[English document](./README_English.md)
2
2
 
3
- ## Almeon 阿柠檬跨平台开发框架机器人
3
+ ## 阿柠檬跨平台开发框架机器人
4
4
 
5
5
  > 需要配置机器人才可启动
6
6
 
7
- 文档查看 OPEN[https://alemonjs.com](https://alemonjs.com)
7
+ 开发文档 OPEN[https://alemonjs.com](https://alemonjs.com)
8
+
9
+ 类型/接口 OPEN[docs](https://ningmengchongshui.github.io/alemon/)
8
10
 
9
11
  开发模板 GITEE[create-alemonjs](https://gitee.com/ningmengchongshui/alemon/tree/cli/bin)
10
12
 
@@ -12,14 +14,14 @@
12
14
 
13
15
  ### 共享平台
14
16
 
15
- > 仓库只做资源收集,对齐安全性不做任何检查,请谨慎选择
16
-
17
- > 仅限签署开源协议的仓库、不开源将不做考虑范围内
18
-
19
17
  贡献资源 OPEN[Gitee](https://gitee.com/ningmengchongshui/alemon/blob/web/docs/about/plugins.md)
20
18
 
21
19
  贡献资源 OPEN[Github](https://gitee.com/ningmengchongshui/alemon/blob/web/docs/about/plugins.md)
22
20
 
21
+ - 仓库只做资源收集,对齐安全性不做任何检查,请谨慎选择
22
+
23
+ - 仅限签署开源协议的仓库、不开源将不做考虑范围内
24
+
23
25
  ## 开源协议
24
26
 
25
27
  GNU GPL 是使用最广泛的自由软件许可证,并有强烈的版权要求
@@ -22,9 +22,9 @@ const config = {
22
22
  puppeteer
23
23
  };
24
24
  /**
25
- * set
26
- * @param key
27
- * @param val
25
+ * 设置机器人基础配置
26
+ * @param key 配置名
27
+ * @param val 配置值
28
28
  */
29
29
  export function setBotConfigByKey(key, val) {
30
30
  if (key == 'puppeteer') {
@@ -53,9 +53,9 @@ export function setBotConfigByKey(key, val) {
53
53
  }
54
54
  }
55
55
  /**
56
- * get
57
- * @param key
58
- * @returns
56
+ * g得到机器人基础配置
57
+ * @param key 配置名
58
+ * @returns 得到配置值
59
59
  */
60
60
  export function getBotConfigByKey(key) {
61
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
  }
@@ -19,7 +19,7 @@ let mergedRegex;
19
19
  /**
20
20
  * 得到机器人帮助
21
21
  * @param AppName
22
- * @returns
22
+ * @returns 指令对象
23
23
  */
24
24
  export function getPluginHelp(AppName) {
25
25
  const c = getAppProCoinfg('regex');
@@ -64,8 +64,8 @@ function createPluginHelp() {
64
64
  }
65
65
  /**
66
66
  * 应用挂载
67
- * @param AppsObj
68
- * @param appname
67
+ * @param AppsObj 插件集成对象
68
+ * @param appname 插件名
69
69
  */
70
70
  async function synthesis(AppsObj, appname) {
71
71
  // 没有记载
@@ -73,6 +73,16 @@ async function synthesis(AppsObj, appname) {
73
73
  plugins[appname] = [];
74
74
  }
75
75
  for (const item in AppsObj) {
76
+ // 解析class
77
+ const keys = new AppsObj[item]();
78
+ // 控制类型
79
+ const eventType = keys['eventType'] ?? 'CREATE';
80
+ // 不合法
81
+ if (!keys['rule'] ||
82
+ !Array.isArray(keys['rule']) ||
83
+ keys['rule'].length == 0) {
84
+ continue;
85
+ }
76
86
  /**
77
87
  * 收藏app
78
88
  */
@@ -92,18 +102,6 @@ async function synthesis(AppsObj, appname) {
92
102
  name: appname,
93
103
  APP: AppsObj[item]
94
104
  };
95
- /**
96
- * 解析class
97
- */
98
- const keys = new AppsObj[item]();
99
- // 控制类型
100
- const eventType = keys['eventType'] ?? 'CREATE';
101
- // 不合法
102
- if (!keys['rule'] ||
103
- !Array.isArray(keys['rule']) ||
104
- keys['rule'].length == 0) {
105
- continue;
106
- }
107
105
  // 指令不存在
108
106
  for await (const key of keys['rule']) {
109
107
  if (!key['fnc'] ||
@@ -172,7 +170,7 @@ async function synthesis(AppsObj, appname) {
172
170
  }
173
171
  /**
174
172
  * 加载应用插件
175
- * @param dir
173
+ * @param dir 插件路径
176
174
  */
177
175
  async function loadPlugins(dir) {
178
176
  if (!existsSync(dir))
@@ -191,9 +189,7 @@ async function loadPlugins(dir) {
191
189
  return true;
192
190
  return !close.test(item);
193
191
  });
194
- /**
195
- * 动态扫描
196
- */
192
+ //动态扫描
197
193
  const main = getAppProCoinfg('main');
198
194
  const type = getAppProCoinfg('type');
199
195
  for await (const appname of apps) {
@@ -225,8 +221,7 @@ function dataInit() {
225
221
  return;
226
222
  }
227
223
  /**
228
- * 应用初始化
229
- * @returns
224
+ * 插件初始化
230
225
  */
231
226
  export async function appsInit() {
232
227
  // 清空当前的apps
@@ -263,27 +258,24 @@ export async function appsInit() {
263
258
  createPluginHelp();
264
259
  // 打印
265
260
  console.info(`[LOAD] APPS*${Object.keys(plugins).length} `);
266
- return;
267
261
  }
268
262
  /**
269
- * 得到大正则
270
- * @returns
263
+ * 得到指令大正则
264
+ * @returns 正则
271
265
  */
272
266
  export function getMergedRegex() {
273
267
  return mergedRegex;
274
268
  }
275
269
  /**
276
- * 初始化应用
277
- * @returns
270
+ * 扫描插件
278
271
  */
279
272
  export async function loadInit() {
280
273
  await loadPlugins(join(process.cwd(), getAppProCoinfg('dir')));
281
- return;
282
274
  }
283
275
  /**
284
276
  * 指令匹配
285
- * @param e
286
- * @returns
277
+ * @param e alemonjs message
278
+ * @returns 是否处理完成
287
279
  */
288
280
  export async function InstructionMatching(e) {
289
281
  /**
@@ -295,6 +287,10 @@ export async function InstructionMatching(e) {
295
287
  await handler(e, state);
296
288
  return true;
297
289
  }
290
+ /**
291
+ *
292
+ */
293
+ const APPCACHE = {};
298
294
  /**
299
295
  * 上下文
300
296
  */
@@ -316,9 +312,8 @@ export async function InstructionMatching(e) {
316
312
  // 得到缓存中的e消息
317
313
  for (const fnc in context) {
318
314
  // 丢给自己
319
- if (app[fnc]) {
315
+ if (app[fnc])
320
316
  app[fnc](context[fnc]);
321
- }
322
317
  }
323
318
  return;
324
319
  }
@@ -332,13 +327,13 @@ export async function InstructionMatching(e) {
332
327
  // 得到缓存中的e消息
333
328
  for (const fnc in context) {
334
329
  // 丢给自己
335
- if (app[fnc]) {
330
+ if (app[fnc])
336
331
  app[fnc](context[fnc]);
337
- }
338
332
  return;
339
333
  }
340
334
  }
341
335
  }
336
+ APPCACHE[item] = app;
342
337
  }
343
338
  catch (err) {
344
339
  console.log('[AlemonJS]上下文出错', err);
@@ -353,24 +348,18 @@ export async function InstructionMatching(e) {
353
348
  /**
354
349
  * 循环所有指令
355
350
  */
356
- for await (const data of Command[e.event]) {
351
+ for (const data of Command[e.event]) {
357
352
  if (e.eventType != data.eventType ||
358
353
  data.reg === undefined ||
359
354
  !data.reg.test(e.msg)) {
360
355
  continue;
361
356
  }
362
357
  try {
363
- const { name, APP } = CommandApp[data.APP];
364
- const AppFnc = getMessage(name);
365
- if (typeof AppFnc == 'function')
366
- e = AppFnc(e);
367
- // 不能每次都new一个
368
- const app = new APP(e);
369
- app.e = e;
358
+ const app = APPCACHE[data.APP];
370
359
  const res = await app[data.fncName](e)
371
360
  .then(info(data))
372
361
  .catch(logErr(data));
373
- if (res)
362
+ if (res != false)
374
363
  break;
375
364
  }
376
365
  catch (err) {
@@ -383,27 +372,38 @@ export async function InstructionMatching(e) {
383
372
  /**
384
373
  * 不匹配指令的方法
385
374
  * 只用匹配类型函数
386
- * @param e
387
- * @returns
375
+ * @param e alemonjs message
376
+ * @returns 是否处理完成
388
377
  */
389
378
  export async function typeMessage(e) {
390
379
  if (!CommandNotMessage[e.event])
391
380
  return true;
392
- // 循环查找
393
- for (const data of CommandNotMessage[e.event]) {
394
- if (e.eventType != data.eventType)
395
- continue;
381
+ const APPCACHE = {};
382
+ for (const item in CommandApp) {
383
+ const { name, APP } = CommandApp[item];
384
+ const AppFnc = getMessage(name);
396
385
  try {
397
- const { name, APP } = CommandApp[data.APP];
398
- const AppFnc = getMessage(name);
399
386
  if (typeof AppFnc == 'function')
400
387
  e = AppFnc(e);
401
388
  const app = new APP(e);
402
389
  app.e = e;
390
+ APPCACHE[item] = app;
391
+ }
392
+ catch (err) {
393
+ console.log('[AlemonJS]上下文出错', err);
394
+ return;
395
+ }
396
+ }
397
+ // 循环查找
398
+ for (const data of CommandNotMessage[e.event]) {
399
+ if (e.eventType != data.eventType)
400
+ continue;
401
+ try {
402
+ const app = APPCACHE[data.APP];
403
403
  const res = await app[data.fncName](e)
404
404
  .then(info(data))
405
405
  .catch(logErr(data));
406
- if (res)
406
+ if (res != false)
407
407
  break;
408
408
  }
409
409
  catch (err) {
@@ -4,16 +4,16 @@
4
4
  const Sockes = {};
5
5
  /**
6
6
  * 得到对话
7
- * @param key
8
- * @returns
7
+ * @param key 对话键
8
+ * @returns 对话值
9
9
  */
10
10
  const getAsync = async (key) => {
11
11
  return Sockes[key];
12
12
  };
13
13
  /**
14
14
  * 设置对话
15
- * @param key
16
- * @param val
15
+ * @param key 对话键
16
+ * @param val 对话值
17
17
  */
18
18
  const setAsync = async (key, val) => {
19
19
  Sockes[key] = val;
@@ -21,11 +21,10 @@ const setAsync = async (key, val) => {
21
21
  };
22
22
  /**
23
23
  * 删除对话
24
- * @param key
24
+ * @param key 对话键
25
25
  */
26
26
  const delAsync = async (key) => {
27
27
  delete Sockes[key];
28
- return;
29
28
  };
30
29
  /**
31
30
  * 注册对话处理器
@@ -33,29 +32,25 @@ const delAsync = async (key) => {
33
32
  export const conversationHandlers = new Map();
34
33
  /**
35
34
  * 获取对话状态
36
- * @param userId 根据id获取
37
- * @returns
35
+ * @param userId 用户编号
36
+ * @returns 对话状态值
38
37
  */
39
38
  export const getConversationState = async (userId) => {
40
39
  const state = await getAsync(`conversation-state:${userId}`);
41
40
  return state ? JSON.parse(state) : null;
42
41
  };
43
42
  /**
44
- * 保存对话状态
45
- * @param userId
46
- * @param state
47
- * @returns
43
+ * 设置对话状态
44
+ * @param userId 用户编号
45
+ * @param state 状态记录
48
46
  */
49
47
  export const setConversationState = async (userId, state) => {
50
48
  await setAsync(`conversation-state:${userId}`, JSON.stringify(state));
51
- return;
52
49
  };
53
50
  /**
54
51
  * 删除对话状态
55
- * @param userId
56
- * @returns
52
+ * @param userId 用户编号
57
53
  */
58
54
  export const deleteConversationState = async (userId) => {
59
55
  await delAsync(`conversation-state:${userId}`);
60
- return;
61
56
  };
package/lib/core/ip.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { publicIp } from 'public-ip';
2
2
  let myIp;
3
3
  /**
4
- * 得到ip地址
5
- * @returns
4
+ * 得到本机IP地址
5
+ * @returns ip
6
6
  */
7
7
  export async function getIP() {
8
8
  if (myIp) {
@@ -3,7 +3,7 @@ const MSG = {};
3
3
  /**
4
4
  * 得到消息
5
5
  * @param key 插件名
6
- * @returns
6
+ * @returns 重定义回调函数
7
7
  */
8
8
  export function getMessage(key) {
9
9
  return MSG[key];
@@ -15,7 +15,6 @@ export function getMessage(key) {
15
15
  */
16
16
  export function setMessage(key, fnc) {
17
17
  MSG[key] = fnc;
18
- return;
19
18
  }
20
19
  /**
21
20
  * 删除消息
@@ -23,5 +22,4 @@ export function setMessage(key, fnc) {
23
22
  */
24
23
  export function delMessage(key) {
25
24
  delete MSG[key];
26
- return;
27
25
  }
@@ -3,7 +3,8 @@
3
3
  */
4
4
  const stateCache = {};
5
5
  /**
6
- * 插件模板
6
+ * 插件基础类
7
+ * @class
7
8
  */
8
9
  export class plugin {
9
10
  /**
@@ -66,7 +67,7 @@ export class plugin {
66
67
  * @param content 内容
67
68
  * @param img 图片buffer | 指定图片名
68
69
  * @param name 指定图片名
69
- * @returns
70
+ * @returns 是否处理完成
70
71
  */
71
72
  reply(content, img, name) {
72
73
  if (!this.e.reply || !content || content == '')
@@ -77,7 +78,7 @@ export class plugin {
77
78
  /**
78
79
  * 得到缓存的key
79
80
  * @param isGroup
80
- * @returns
81
+ * @returns key
81
82
  */
82
83
  conKey(isGroup = false) {
83
84
  if (isGroup) {
@@ -90,6 +91,7 @@ export class plugin {
90
91
  }
91
92
  }
92
93
  /**
94
+ * 设置上下文
93
95
  * @param type 执行方法
94
96
  * @param isGroup 是否群聊
95
97
  * @param time 操作时间,默认120秒
@@ -112,20 +114,21 @@ export class plugin {
112
114
  }
113
115
  /**
114
116
  *
115
- * 得到用户缓存
116
- * @returns
117
+ * 得到用户缓存消息对象
118
+ * @returns message
117
119
  */
118
120
  getContext() {
119
121
  return stateCache[this.conKey()];
120
122
  }
121
123
  /**
122
- * 得到频道缓存
123
- * @returns
124
+ * 得到频道缓存消息对象
125
+ * @returns message
124
126
  */
125
127
  getContextGroup() {
126
128
  return stateCache[this.conKey(true)];
127
129
  }
128
130
  /**
131
+ * 完成上下文
129
132
  * @param type 执行方法
130
133
  * @param isGroup 是否公信
131
134
  */
@@ -22,21 +22,21 @@ let isBrowser = false;
22
22
  let LaunchCfg;
23
23
  /**
24
24
  * 配置浏览器参数
25
- * @param val
25
+ * @param val 参数值
26
26
  */
27
27
  export function setLanchConfig(val) {
28
28
  LaunchCfg = val;
29
29
  }
30
30
  /**
31
31
  * 得到pup配置
32
- * @returns
32
+ * @returns config
33
33
  */
34
34
  export function getLanchConfig() {
35
35
  return LaunchCfg;
36
36
  }
37
37
  /**
38
- * 启动检查
39
- * @returns
38
+ * 启动pup检查
39
+ * @returns 是否启动成功
40
40
  */
41
41
  export async function pupStartCheck() {
42
42
  /**
@@ -78,7 +78,7 @@ export async function pupStartCheck() {
78
78
  * @param type 图片类型
79
79
  * @param quality 清晰度
80
80
  * @param timeout 响应检查
81
- * @returns
81
+ * @returns buffer
82
82
  */
83
83
  export async function screenshotByFile(htmlPath, Options) {
84
84
  const T = await pupStartCheck();
@@ -112,9 +112,9 @@ export async function screenshotByFile(htmlPath, Options) {
112
112
  }
113
113
  }
114
114
  /**
115
- * 截图
116
- * @param val
117
- * @returns
115
+ * 对url截图进行截图
116
+ * @param val url地址
117
+ * @returns buffer
118
118
  */
119
119
  export async function screenshotByUrl(val) {
120
120
  const T = await pupStartCheck();
@@ -163,8 +163,8 @@ export async function screenshotByUrl(val) {
163
163
  }
164
164
  }
165
165
  /**
166
- * 启动浏览器
167
- * @returns
166
+ * 启动pup
167
+ * @returns 是否启动
168
168
  */
169
169
  export async function startChrom() {
170
170
  try {
@@ -4,7 +4,7 @@ import { writeFile, readFile } from 'fs';
4
4
  * 链接转化为二维码
5
5
  * @param text 链接
6
6
  * @param localpath 可选,要保存的路径
7
- * @returns
7
+ * @returns buffer
8
8
  */
9
9
  export async function createQrcode(text, localpath) {
10
10
  try {
@@ -36,7 +36,7 @@ export async function createQrcode(text, localpath) {
36
36
  /**
37
37
  * 读取buffer文件
38
38
  * @param localpath 读取地址
39
- * @returns
39
+ * @returns buffer
40
40
  */
41
41
  export const getBuffer = (localpath) => {
42
42
  return new Promise((resolve, reject) => {
@@ -21,7 +21,6 @@ const absolutePathTemplateCache = {};
21
21
  /**
22
22
  * 缓存监听
23
23
  * @param tplFile 模板地址
24
- * @returns
25
24
  */
26
25
  function watchCT(tplFile) {
27
26
  /**
@@ -48,10 +47,10 @@ function watchCT(tplFile) {
48
47
  });
49
48
  }
50
49
  /**
51
- * 如果control为真则需重新重新渲染
52
- * @param AppName
53
- * @param tplFile
54
- * @returns
50
+ * 对指定html进行资源矫正
51
+ * @param AppName 插件名
52
+ * @param tplFile 文件地址
53
+ * @returns 文件地址|模板字符串
55
54
  */
56
55
  export function createHtml(AppName, tplFile) {
57
56
  const appDir = getAppProCoinfg('dir');
@@ -1,9 +1,9 @@
1
1
  import { spawn } from 'child_process';
2
2
  /**
3
- *
4
- * @param name
5
- * @param file
6
- * @param ars
3
+ * 执行脚本文件
4
+ * @param name node | ts-node
5
+ * @param file 脚本文件
6
+ * @param ars 执行参数
7
7
  */
8
8
  export function nodeScripts(name = 'node', file = '', ars = []) {
9
9
  const command = spawn(`${name} ${file} ${ars.join(' ')}`, { shell: true });
@@ -1,9 +1,9 @@
1
1
  import { mkdirSync } from 'fs';
2
2
  import { execSync, exec } from 'child_process';
3
3
  /**
4
- *
5
- * @param cess
6
- * @param cmd
4
+ * 指定指定可执行指令
5
+ * @param cess 执行规则 同步 | 异步
6
+ * @param cmd 指定指令
7
7
  * @returns
8
8
  */
9
9
  export async function command(cess, cmd) {
@@ -10,14 +10,14 @@ import { getPupPath, setBotConfigByKey, getBotConfigByKey } from '../config/inde
10
10
  export const setAuthenticationByNtqq = ClientByNTQQ.setAuthentication;
11
11
  let OptionsCache;
12
12
  /**
13
- * 得到载入配置
13
+ * 得到初始化配置
14
14
  * @returns
15
15
  */
16
16
  export function getAlemonConfig() {
17
17
  return OptionsCache;
18
18
  }
19
19
  /**
20
- * 机器人配置
20
+ * 配置机器人启动规则
21
21
  * @param Options
22
22
  */
23
23
  export async function defineAlemonConfig(Options) {
package/lib/define/map.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * **********
3
- * 启动机器人
3
+ * 机器人启动集
4
4
  * **********
5
5
  */
6
6
  export const rebotMap = {
package/lib/login.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * map登录校验
3
- * @param val
4
- * @returns
3
+ * @param val 校验值
4
+ * @returns 返回校验所得login配置
5
5
  */
6
6
  export function analysis(val) {
7
7
  const ars = process.argv.slice(2);
package/lib/run.js CHANGED
@@ -1,6 +1,10 @@
1
1
  import { spawn } from 'child_process';
2
2
  import { existsSync } from 'fs';
3
3
  import { join } from 'path';
4
+ /**
5
+ * 指令运行队则
6
+ * @param ars 指令参数数组
7
+ */
4
8
  export function commandRun(ars) {
5
9
  const msg = ars.join(' ');
6
10
  const files = msg.match(/(\S+\.js|\S+\.ts)/g) ?? ['alemon.config.ts'];
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "alemonjs",
3
- "version": "1.0.29",
3
+ "version": "1.0.30",
4
4
  "description": "docs https://alemonjs.com/",
5
5
  "author": "ningmengchongshui",
6
6
  "license": "GPL-2.0",
7
7
  "type": "module",
8
8
  "scripts": {
9
9
  "tsc": "npx tsc",
10
+ "doc": "npx typedoc --options typedoc.json",
10
11
  "format": "prettier --write .",
11
12
  "lint": "eslint . --ext .js,.ts --fix --ignore-path .gitignore"
12
13
  },
@@ -35,6 +36,7 @@
35
36
  "eslint-plugin-prettier": "^4.2.1",
36
37
  "prettier": "^2.8.8",
37
38
  "ts-node": "^10.9.1",
39
+ "typedoc": "^0.25.2",
38
40
  "typescript": ">=5.0.4 <5.1.0"
39
41
  },
40
42
  "types": "types",
package/run.js CHANGED
@@ -1,6 +1,10 @@
1
1
  import { spawn } from 'child_process'
2
2
  import { existsSync } from 'fs'
3
3
  import { join } from 'path'
4
+ /**
5
+ * 指令运行队则
6
+ * @param ars 指令参数数组
7
+ */
4
8
  export function commandRun(ars) {
5
9
  const msg = ars.join(' ')
6
10
  const files = msg.match(/(\S+\.js|\S+\.ts)/g) ?? ['alemon.config.ts']
@@ -1,13 +1,13 @@
1
1
  import { ConfigType } from './types.js';
2
2
  /**
3
- * set
4
- * @param key
5
- * @param val
3
+ * 设置机器人基础配置
4
+ * @param key 配置名
5
+ * @param val 配置值
6
6
  */
7
7
  export declare function setBotConfigByKey<T extends keyof ConfigType>(key: T, val: ConfigType[T]): void;
8
8
  /**
9
- * get
10
- * @param key
11
- * @returns
9
+ * g得到机器人基础配置
10
+ * @param key 配置名
11
+ * @returns 得到配置值
12
12
  */
13
13
  export declare function getBotConfigByKey<T extends keyof ConfigType>(key: T): ConfigType[T] | undefined;
@@ -1,5 +1,7 @@
1
1
  /**
2
+ * 得到pup可寻地址
2
3
  * @type {import("puppeteer").Configuration}
4
+ * @returns 得到配置对象
3
5
  */
4
6
  export declare function getPupPath(): {
5
7
  skipDownload: boolean;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * 得到应用
3
3
  * @param key 插件名
4
- * @returns
4
+ * @returns 得到应用集
5
5
  */
6
6
  export declare function getApp(key: any): object;
7
7
  /**
@@ -17,6 +17,6 @@ export declare function setApp(key: any, value: any): void;
17
17
  export declare function delApp(key: any): void;
18
18
  /**
19
19
  * 得到应用
20
- * @returns
20
+ * @returns 得到指定应用值
21
21
  */
22
22
  export declare function getAppKey(): any[];
@@ -1,25 +1,25 @@
1
1
  /**
2
2
  * 得到执行路径
3
- * @param url
4
- * @returns
3
+ * @param url import.meta.url
4
+ * @returns AppName目录名
5
5
  */
6
6
  export declare function getAppPath(url: string | URL): string;
7
7
  /**
8
8
  * 得到执行目录
9
- * @param {} url
10
- * @returns
9
+ * @param {} url import.meta.url
10
+ * @returns AppName目录名
11
11
  */
12
12
  export declare function getAppName(url: string | URL): string;
13
13
  /**
14
14
  * 创建应用对象
15
15
  * @param url import.meta.url
16
- * @returns
16
+ * @returns AppName目录名
17
17
  */
18
18
  export declare function createApps(url: string): {
19
19
  /**
20
20
  * 重定义消息
21
- * @param fnc
22
- * @returns
21
+ * @param fnc 回调函数
22
+ * @returns 是否成功定义
23
23
  */
24
24
  setMessage: (fnc: (...args: any[]) => any) => boolean;
25
25
  /**
@@ -29,20 +29,19 @@ export declare function createApps(url: string): {
29
29
  component: (urlObject?: object) => boolean;
30
30
  /**
31
31
  * 挂起应用
32
- * @returns
33
32
  */
34
33
  mount: () => void;
35
34
  };
36
35
  /**
37
36
  * 创建应用对象
38
- * @param AppName
39
- * @returns
37
+ * @param AppName 目录名 getAppName(import.meta.url)
38
+ * @returns 应用app对象
40
39
  */
41
40
  export declare function createApp(AppName: string): {
42
41
  /**
43
42
  * 重定义消息
44
- * @param fnc
45
- * @returns
43
+ * @param fnc 回调函数
44
+ * @returns 是否成功定义
46
45
  */
47
46
  setMessage: (fnc: (...args: any[]) => any) => boolean;
48
47
  /**
@@ -52,7 +51,6 @@ export declare function createApp(AppName: string): {
52
51
  component: (urlObject?: object) => boolean;
53
52
  /**
54
53
  * 挂起应用
55
- * @returns
56
54
  */
57
55
  mount: () => void;
58
56
  };
@@ -1,13 +1,13 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
2
  /**
3
3
  * 异步请求图片
4
- * @param url
5
- * @returns
4
+ * @param url 网络地址
5
+ * @returns buffer
6
6
  */
7
7
  export declare function getUrlbuffer(url: string): Promise<Buffer>;
8
8
  /**
9
9
  * 读取本地图片
10
- * @param path 根路径
11
- * @returns
10
+ * @param path 本地地址 /public/img/xx.png
11
+ * @returns buffer
12
12
  */
13
13
  export declare function getPathBuffer(path: string): Buffer;
@@ -28,6 +28,16 @@ interface ApplicationProcessingOpsion {
28
28
  */
29
29
  regex: boolean;
30
30
  }
31
+ /**
32
+ * 设置插件解析配置
33
+ * @param key 配置名
34
+ * @param val 配置值
35
+ */
31
36
  export declare function setAppProCoinfg<T extends keyof ApplicationProcessingOpsion>(key: T, val: ApplicationProcessingOpsion[T]): void;
37
+ /**
38
+ * 得到插件解析配置
39
+ * @param key 配置名
40
+ * @returns 配置值
41
+ */
32
42
  export declare function getAppProCoinfg<T extends keyof ApplicationProcessingOpsion>(key: T): ApplicationProcessingOpsion[T];
33
43
  export {};
@@ -2,34 +2,32 @@ import { AMessage } from './typings.js';
2
2
  /**
3
3
  * 得到机器人帮助
4
4
  * @param AppName
5
- * @returns
5
+ * @returns 指令对象
6
6
  */
7
7
  export declare function getPluginHelp(AppName: string): any;
8
8
  /**
9
- * 应用初始化
10
- * @returns
9
+ * 插件初始化
11
10
  */
12
11
  export declare function appsInit(): Promise<void>;
13
12
  /**
14
- * 得到大正则
15
- * @returns
13
+ * 得到指令大正则
14
+ * @returns 正则
16
15
  */
17
16
  export declare function getMergedRegex(): RegExp;
18
17
  /**
19
- * 初始化应用
20
- * @returns
18
+ * 扫描插件
21
19
  */
22
20
  export declare function loadInit(): Promise<void>;
23
21
  /**
24
22
  * 指令匹配
25
- * @param e
26
- * @returns
23
+ * @param e alemonjs message
24
+ * @returns 是否处理完成
27
25
  */
28
26
  export declare function InstructionMatching(e: AMessage): Promise<boolean>;
29
27
  /**
30
28
  * 不匹配指令的方法
31
29
  * 只用匹配类型函数
32
- * @param e
33
- * @returns
30
+ * @param e alemonjs message
31
+ * @returns 是否处理完成
34
32
  */
35
33
  export declare function typeMessage(e: AMessage): Promise<boolean>;
@@ -1,8 +1,8 @@
1
1
  import { type AMessage } from './typings.js';
2
2
  /**
3
- * 对话处理函数类型
3
+ * 对话处理函数集
4
4
  */
5
- export interface SockesType {
5
+ export interface SockesMap {
6
6
  [key: string]: any;
7
7
  }
8
8
  /**
@@ -23,7 +23,7 @@ export type ConversationState = {
23
23
  fnc: (...args: any[]) => any;
24
24
  };
25
25
  /**
26
- * 对话接口
26
+ * 对话接口类型
27
27
  */
28
28
  export type ConversationHandler = (e: AMessage, state: ConversationState) => Promise<void>;
29
29
  /**
@@ -36,20 +36,18 @@ export type conversationHandlersMap = Map<string, ConversationHandler>;
36
36
  export declare const conversationHandlers: conversationHandlersMap;
37
37
  /**
38
38
  * 获取对话状态
39
- * @param userId 根据id获取
40
- * @returns
39
+ * @param userId 用户编号
40
+ * @returns 对话状态值
41
41
  */
42
42
  export declare const getConversationState: (userId: string) => Promise<ConversationState | null>;
43
43
  /**
44
- * 保存对话状态
45
- * @param userId
46
- * @param state
47
- * @returns
44
+ * 设置对话状态
45
+ * @param userId 用户编号
46
+ * @param state 状态记录
48
47
  */
49
48
  export declare const setConversationState: (userId: string, state: ConversationState) => Promise<void>;
50
49
  /**
51
50
  * 删除对话状态
52
- * @param userId
53
- * @returns
51
+ * @param userId 用户编号
54
52
  */
55
53
  export declare const deleteConversationState: (userId: string) => Promise<void>;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * 得到ip地址
3
- * @returns
2
+ * 得到本机IP地址
3
+ * @returns ip
4
4
  */
5
5
  export declare function getIP(): Promise<string | false>;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * 得到消息
3
3
  * @param key 插件名
4
- * @returns
4
+ * @returns 重定义回调函数
5
5
  */
6
6
  export declare function getMessage(key: string): any;
7
7
  /**
@@ -50,7 +50,8 @@ export interface PluginRuleType {
50
50
  priority?: number;
51
51
  }
52
52
  /**
53
- * 插件模板
53
+ * 插件基础类
54
+ * @class
54
55
  */
55
56
  export declare class plugin {
56
57
  /**
@@ -101,16 +102,17 @@ export declare class plugin {
101
102
  * @param content 内容
102
103
  * @param img 图片buffer | 指定图片名
103
104
  * @param name 指定图片名
104
- * @returns
105
+ * @returns 是否处理完成
105
106
  */
106
107
  reply(content?: string | Buffer | string[], img?: string | Buffer, name?: string): boolean;
107
108
  /**
108
109
  * 得到缓存的key
109
110
  * @param isGroup
110
- * @returns
111
+ * @returns key
111
112
  */
112
113
  conKey(isGroup?: boolean): string;
113
114
  /**
115
+ * 设置上下文
114
116
  * @param type 执行方法
115
117
  * @param isGroup 是否群聊
116
118
  * @param time 操作时间,默认120秒
@@ -118,16 +120,17 @@ export declare class plugin {
118
120
  setContext(type: string, isGroup?: boolean, time?: number): void;
119
121
  /**
120
122
  *
121
- * 得到用户缓存
122
- * @returns
123
+ * 得到用户缓存消息对象
124
+ * @returns message
123
125
  */
124
126
  getContext(): any;
125
127
  /**
126
- * 得到频道缓存
127
- * @returns
128
+ * 得到频道缓存消息对象
129
+ * @returns message
128
130
  */
129
131
  getContextGroup(): any;
130
132
  /**
133
+ * 完成上下文
131
134
  * @param type 执行方法
132
135
  * @param isGroup 是否公信
133
136
  */
@@ -4,17 +4,17 @@ import puppeteer, { PuppeteerLaunchOptions, ScreenshotOptions, PuppeteerLifeCycl
4
4
  import queryString from 'querystring';
5
5
  /**
6
6
  * 配置浏览器参数
7
- * @param val
7
+ * @param val 参数值
8
8
  */
9
9
  export declare function setLanchConfig(val: PuppeteerLaunchOptions): void;
10
10
  /**
11
11
  * 得到pup配置
12
- * @returns
12
+ * @returns config
13
13
  */
14
14
  export declare function getLanchConfig(): puppeteer.PuppeteerLaunchOptions;
15
15
  /**
16
- * 启动检查
17
- * @returns
16
+ * 启动pup检查
17
+ * @returns 是否启动成功
18
18
  */
19
19
  export declare function pupStartCheck(): Promise<boolean>;
20
20
  /**
@@ -24,7 +24,7 @@ export declare function pupStartCheck(): Promise<boolean>;
24
24
  * @param type 图片类型
25
25
  * @param quality 清晰度
26
26
  * @param timeout 响应检查
27
- * @returns
27
+ * @returns buffer
28
28
  */
29
29
  export declare function screenshotByFile(htmlPath: string | Buffer | URL, Options: {
30
30
  SOptions: ScreenshotOptions;
@@ -45,13 +45,13 @@ export interface urlScreenshotOptions {
45
45
  waitUntil?: PuppeteerLifeCycleEvent | PuppeteerLifeCycleEvent[];
46
46
  }
47
47
  /**
48
- * 截图
49
- * @param val
50
- * @returns
48
+ * 对url截图进行截图
49
+ * @param val url地址
50
+ * @returns buffer
51
51
  */
52
52
  export declare function screenshotByUrl(val: urlScreenshotOptions): Promise<string | false | Buffer>;
53
53
  /**
54
- * 启动浏览器
55
- * @returns
54
+ * 启动pup
55
+ * @returns 是否启动
56
56
  */
57
57
  export declare function startChrom(): Promise<boolean>;
@@ -3,13 +3,13 @@
3
3
  * 链接转化为二维码
4
4
  * @param text 链接
5
5
  * @param localpath 可选,要保存的路径
6
- * @returns
6
+ * @returns buffer
7
7
  */
8
8
  export declare function createQrcode(text: string, localpath?: string): Promise<false | Buffer>;
9
9
  /**
10
10
  * 读取buffer文件
11
11
  * @param localpath 读取地址
12
- * @returns
12
+ * @returns buffer
13
13
  */
14
14
  export declare const getBuffer: (localpath: string) => Promise<Buffer>;
15
15
  /**
@@ -1,8 +1,8 @@
1
1
  /**
2
- * 如果control为真则需重新重新渲染
3
- * @param AppName
4
- * @param tplFile
5
- * @returns
2
+ * 对指定html进行资源矫正
3
+ * @param AppName 插件名
4
+ * @param tplFile 文件地址
5
+ * @returns 文件地址|模板字符串
6
6
  */
7
7
  export declare function createHtml(AppName: string, tplFile: string): {
8
8
  AdressHtml: string;
@@ -304,7 +304,7 @@ interface replyController {
304
304
  * 消息发送机制
305
305
  * @param content 消息 | buffer
306
306
  * @param img 消息 | buffer
307
- * @returns
307
+ * @returns 是否执行完成
308
308
  */
309
309
  reply(content?: string | string[] | Buffer, img?: Buffer | string, name?: string): Promise<boolean>;
310
310
  /**
@@ -1,7 +1,7 @@
1
1
  /**
2
- *
3
- * @param name
4
- * @param file
5
- * @param ars
2
+ * 执行脚本文件
3
+ * @param name node | ts-node
4
+ * @param file 脚本文件
5
+ * @param ars 执行参数
6
6
  */
7
7
  export declare function nodeScripts(name?: string, file?: string, ars?: any[]): void;
@@ -1,7 +1,7 @@
1
1
  /**
2
- *
3
- * @param cess
4
- * @param cmd
2
+ * 指定指定可执行指令
3
+ * @param cess 执行规则 同步 | 异步
4
+ * @param cmd 指定指令
5
5
  * @returns
6
6
  */
7
7
  export declare function command(cess: 'execSync' | 'exec', cmd: string): Promise<void>;
@@ -2,12 +2,12 @@ import { AlemonOptions } from './types.js';
2
2
  import { ClientAPIByQQ as ClientByNTQQ } from '../ntqq/sdk/index.js';
3
3
  export declare const setAuthenticationByNtqq: typeof ClientByNTQQ.setAuthentication;
4
4
  /**
5
- * 得到载入配置
5
+ * 得到初始化配置
6
6
  * @returns
7
7
  */
8
8
  export declare function getAlemonConfig(): AlemonOptions;
9
9
  /**
10
- * 机器人配置
10
+ * 配置机器人启动规则
11
11
  * @param Options
12
12
  */
13
13
  export declare function defineAlemonConfig(Options?: AlemonOptions): Promise<void>;
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * **********
3
- * 启动机器人
3
+ * 机器人启动集
4
4
  * **********
5
5
  */
6
6
  export declare const rebotMap: {
package/types/login.d.ts CHANGED
@@ -9,7 +9,7 @@ export interface LoginMap {
9
9
  }
10
10
  /**
11
11
  * map登录校验
12
- * @param val
13
- * @returns
12
+ * @param val 校验值
13
+ * @returns 返回校验所得login配置
14
14
  */
15
15
  export declare function analysis(val: LoginMap): import("./default/types.js").LoginOptions;
package/types/run.d.ts CHANGED
@@ -1 +1,5 @@
1
+ /**
2
+ * 指令运行队则
3
+ * @param ars 指令参数数组
4
+ */
1
5
  export declare function commandRun(ars: string[]): void;