mm_os 2.5.0 → 2.5.2

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.
@@ -76,7 +76,7 @@ Cmd.prototype.run = async function(msg, db, table) {
76
76
 
77
77
  var lt = this.list_before;
78
78
  for (var i = 0, o; o = lt[i++];) {
79
- if (o.onOff) {
79
+ if (o.config.state === 1) {
80
80
  try {
81
81
  ret = await o.run_cmd(msg, db);
82
82
  } catch (error) {
@@ -123,7 +123,7 @@ Cmd.prototype.run = async function(msg, db, table) {
123
123
  if (!ret) {
124
124
  var lt = this.list_main;
125
125
  for (var i = 0, o; o = lt[i++];) {
126
- if (o.onOff) {
126
+ if (o.config.state === 1) {
127
127
  try {
128
128
  ret = await o.run_first(msg, db);
129
129
  } catch (error) {
@@ -138,7 +138,7 @@ Cmd.prototype.run = async function(msg, db, table) {
138
138
  if (!ret) {
139
139
  var lt = this.list_after;
140
140
  for (var i = 0, o; o = lt[i++];) {
141
- if (o.onOff) {
141
+ if (o.config.state === 1) {
142
142
  try {
143
143
  ret = await o.run_first(msg, db);
144
144
  } catch (error) {
@@ -126,28 +126,30 @@ MQTT.prototype.update_after = function() {
126
126
  var _this = this;
127
127
  var list = this.list;
128
128
  for (var i = 0, o; o = list[i++];) {
129
- o.send = function(topic, msg, qos = 0, retain = false) {
130
- if (topic) {
131
- _this.send(topic, msg, qos, retain);
132
- }
133
- };
129
+ if (o.config.state === 1) {
130
+ o.send = function(topic, msg, qos = 0, retain = false) {
131
+ if (topic) {
132
+ _this.send(topic, msg, qos, retain);
133
+ }
134
+ };
134
135
 
135
- try {
136
- o.run('init');
137
- } catch (error) {
138
- $.log.error("MQTT类初始化失败", o.config.name, error);
139
- }
140
- var topics = o.config.topic;
141
- if (topics) {
142
- for (var i = 0; i < topics.length; i++) {
143
- var tc = topics[i];
144
- var retain = o.config.retain || false;
145
- var qos = o.config.qos || 0;
146
- if (tc.indexOf("heartbeat") !== -1) {
147
- retain = false;
148
- qos = 0;
136
+ try {
137
+ o.run('init');
138
+ } catch (error) {
139
+ $.log.error("MQTT类初始化失败", o.config.name, error);
140
+ }
141
+ var topics = o.config.topic;
142
+ if (topics) {
143
+ for (var i = 0; i < topics.length; i++) {
144
+ var tc = topics[i];
145
+ var retain = o.config.retain || false;
146
+ var qos = o.config.qos || 0;
147
+ if (tc.indexOf("heartbeat") !== -1) {
148
+ retain = false;
149
+ qos = 0;
150
+ }
151
+ this.subscribe(tc, null, qos, retain);
149
152
  }
150
- this.subscribe(tc, null, qos, retain);
151
153
  }
152
154
  }
153
155
  }
@@ -272,15 +274,17 @@ MQTT.prototype.receive = async function(push_topic, msg) {
272
274
  var ret;
273
275
  var list = this.list;
274
276
  for (var i = 0, o; o = list[i++];) {
275
- var topics = o.config.topic;
276
- if (topics) {
277
- for (var i = 0; i < topics.length; i++) {
278
- var topic = topics[i];
279
- if (this.match(push_topic, topic)) {
280
- try {
281
- ret = await o.run("main", push_topic, msg, topic, i);
282
- } catch (error) {
283
- $.log.error("MQTT执行失败", o.config.name, error);
277
+ if (o.config.state === 1) {
278
+ var topics = o.config.topic;
279
+ if (topics) {
280
+ for (var i = 0; i < topics.length; i++) {
281
+ var topic = topics[i];
282
+ if (this.match(push_topic, topic)) {
283
+ try {
284
+ ret = await o.run("main", push_topic, msg, topic, i);
285
+ } catch (error) {
286
+ $.log.error("MQTT执行失败", o.config.name, error);
287
+ }
284
288
  }
285
289
  }
286
290
  }
@@ -14,7 +14,7 @@ class Drive extends Item {
14
14
  constructor(dir) {
15
15
  super(dir, __dirname);
16
16
  this.default_file = "./plugin.json";
17
-
17
+
18
18
  /**
19
19
  * 当前语言
20
20
  */
@@ -59,11 +59,27 @@ class Drive extends Item {
59
59
  // 是否中断执行
60
60
  "end": true,
61
61
  // 排序
62
- "sort": 10
62
+ "sort": 10,
63
+ // 配置
64
+ "options": []
63
65
  };
64
66
  }
65
67
  }
66
68
 
69
+ /**
70
+ * 获取配置参数
71
+ * @return {Object} 返回配置参数
72
+ */
73
+ Drive.prototype.options = function() {
74
+ var op = this.config.options || [];
75
+ var dict = {};
76
+ for (var i = 0; i < op.length; i++) {
77
+ var o = op[i];
78
+ dict[o.name] = o.value;
79
+ }
80
+ return dict;
81
+ }
82
+
67
83
  /**
68
84
  * 新建脚本
69
85
  * @param {String} 文件
@@ -111,7 +127,8 @@ Drive.prototype.new_config = function(file) {
111
127
  text = text.replaceAll('{0}', name);
112
128
  } else if (file.indexOf('app' + l) !== -1) {
113
129
  name = file.between('app' + l, l);
114
- text = text.replaceAll('{0}', name).replaceAll('\r\n "app": "{1}",', '').replaceAll('插件', '应用').replaceAll('{2}', name);
130
+ text = text.replaceAll('{0}', name).replaceAll('\r\n "app": "{1}",', '').replaceAll('插件', '应用')
131
+ .replaceAll('{2}', name);
115
132
  }
116
133
  file.saveText(text);
117
134
  }
@@ -331,20 +348,4 @@ Drive.prototype.run_chat = async function(from_user, to_user, content, group, ty
331
348
  return ret;
332
349
  };
333
350
 
334
- /**
335
- * 执行程序
336
- * @param {Object} param1 参数1
337
- * @param {Object} param2 参数2
338
- * @return {Object} 返回执行结果
339
- */
340
- Drive.prototype.exec = function(func_name, option) {
341
- var msg = "";
342
- if (this[func_name]) {
343
- msg = this[func_name](option);
344
- } else {
345
- msg = "错误的操作";
346
- }
347
- return msg;
348
- };
349
-
350
- module.exports = Drive;
351
+ module.exports = Drive;
@@ -40,14 +40,16 @@ class Static extends Index {
40
40
  if (path.indexOf('.') !== -1) {
41
41
  for (var i = 0; i < len; i++) {
42
42
  var o = list[i];
43
- try {
44
- done = await o.run(ctx, path, next);
45
- } catch (error) {
46
- $.log.error("静态文件执行错误", o.config.name, error);
47
- }
48
-
49
- if (done) {
50
- break;
43
+ if (o.config.state === 1) {
44
+ try {
45
+ done = await o.run(ctx, path, next);
46
+ } catch (error) {
47
+ $.log.error("静态文件执行错误", o.config.name, error);
48
+ }
49
+
50
+ if (done) {
51
+ break;
52
+ }
51
53
  }
52
54
  }
53
55
  await next();
@@ -56,25 +58,27 @@ class Static extends Index {
56
58
  var q = ctx.request.querystring;
57
59
  for (var i = 0; i < len; i++) {
58
60
  var o = list[i];
59
- var p = o.config.path;
60
- if (path === p) {
61
- done = ' ';
62
- if (ctx.status === 404) {
63
- if (q) {
64
- ctx.redirect(p + '/?' + q);
65
- } else {
66
- ctx.redirect(p + '/');
61
+ if (o.config.state === 1) {
62
+ var p = o.config.path;
63
+ if (path === p) {
64
+ done = ' ';
65
+ if (ctx.status === 404) {
66
+ if (q) {
67
+ ctx.redirect(p + '/?' + q);
68
+ } else {
69
+ ctx.redirect(p + '/');
70
+ }
67
71
  }
68
- }
69
- break;
70
- } else {
71
- try {
72
- done = await o.run(ctx, path, next);
73
- } catch (error) {
74
- $.log.error("静态文件执行错误", o.config.name, error);
75
- }
76
- if (done) {
77
72
  break;
73
+ } else {
74
+ try {
75
+ done = await o.run(ctx, path, next);
76
+ } catch (error) {
77
+ $.log.error("静态文件执行错误", o.config.name, error);
78
+ }
79
+ if (done) {
80
+ break;
81
+ }
78
82
  }
79
83
  }
80
84
  }
@@ -29,7 +29,7 @@ Task.prototype.run = async function(name) {
29
29
  var lt = this.list;
30
30
  if (name) {
31
31
  for (var i = 0, o; o = lt[i++];) {
32
- if (o.name === name) {
32
+ if (o.config.state === 1 && o.config.name === name) {
33
33
  try {
34
34
  o.run();
35
35
  } catch (error) {
@@ -40,10 +40,12 @@ Task.prototype.run = async function(name) {
40
40
  }
41
41
  } else {
42
42
  for (var i = 0, o; o = lt[i++];) {
43
- try {
44
- o.run();
45
- } catch (error) {
46
- $.log.error("定时任务错误", o.name, error);
43
+ if (o.config.state === 1) {
44
+ try {
45
+ o.run();
46
+ } catch (error) {
47
+ $.log.error("定时任务错误", o.name, error);
48
+ }
47
49
  }
48
50
  }
49
51
  }
@@ -14,7 +14,7 @@ async function main(ctx, db) {
14
14
 
15
15
  var user = await this.get_state(ctx, db);
16
16
 
17
- console.log("用户", user);
17
+ // console.log("用户", user);
18
18
  // return "hello world" + JSON.stringify(body);
19
19
 
20
20
  // 操作sql模板
@@ -28,6 +28,9 @@ async function main(ctx, db) {
28
28
  } else {
29
29
 
30
30
  }
31
+ // var plus = $.plugin_admin('test');
32
+ // plus.run("main", "start");
33
+ // plus.run("main", "stop");
31
34
  var ret = await this.sql.run(query, body, db);
32
35
  return ret;
33
36
  };
@@ -56,7 +56,7 @@ module.exports = {
56
56
  */
57
57
  start(option) {
58
58
  var msg = null;
59
- console.log("启动了", this.config);
59
+ console.log("启动了", this.options());
60
60
  return msg;
61
61
  },
62
62
 
@@ -22,5 +22,82 @@
22
22
  // 是否中断执行
23
23
  "end": true,
24
24
  // 排序,表示多个插件时在应用下执行的先后顺序
25
- "sort": 10
25
+ "sort": 10,
26
+ // 配置参数
27
+ "options": [
28
+ {
29
+ "group": "默认",
30
+ "config_id": 0,
31
+ "name": "appId",
32
+ "title": "机器人ID",
33
+ "type": "string",
34
+ "control": "input",
35
+ "tip": "例:102047156",
36
+ "description": "官方申请的QQ机器人ID,详情请查看<a target=\"_blank\" href=\"https://q.qq.com/#/app/bot\">QQ开放平台</a>",
37
+ "display": 100,
38
+ "default": "102047156",
39
+ "min": 0,
40
+ "max": 0,
41
+ "value": "102047156"
42
+ },
43
+ {
44
+ "group": "默认",
45
+ "config_id": 0,
46
+ "name": "AppSecret",
47
+ "title": "机器人密钥",
48
+ "type": "string",
49
+ "control": "input",
50
+ "tip": "例:ufQBwiUG2oaM9wjWJ6tgUI6uiWK9yncR1",
51
+ "description": "用于在 oauth 场景进行请求签名的密钥",
52
+ "display": 100,
53
+ "default": "ufQBwiUG2oaM9wjWJ6tgUI6uiWK9yncR1",
54
+ "min": 0,
55
+ "max": 0,
56
+ "value": "ufQBwiUG2oaM9wjWJ6tgUI6uiWK9yncR1"
57
+ },
58
+ {
59
+ "group": "默认",
60
+ "config_id": 0,
61
+ "name": "token",
62
+ "title": "机器人令牌",
63
+ "type": "string",
64
+ "control": "input",
65
+ "tip": "例:w14e85M4Mj6egshfKc3wADq1KMP87Qi3",
66
+ "description": "用于以机器人身份调用 openapi",
67
+ "display": 100,
68
+ "default": "w14e85M4Mj6egshfKc3wADq1KMP87Qi3",
69
+ "min": 0,
70
+ "max": 0,
71
+ "value": "w14e85M4Mj6egshfKc3wADq1KMP87Qi3"
72
+ },
73
+ {
74
+ "group": "默认",
75
+ "config_id": 0,
76
+ "name": "intents",
77
+ "title": "事件订阅",
78
+ "type": "string",
79
+ "control": "checkbox",
80
+ "tip": "",
81
+ "description": "用于开启可接收的消息类型",
82
+ "display": 100,
83
+ "default": "PUBLIC_GUILD_MESSAGES",
84
+ "min": 1,
85
+ "max": 255,
86
+ "model": "公域消息事件=PUBLIC_GUILD_MESSAGES\n私域消息事件=GUILD_MESSAGES"
87
+ },
88
+ {
89
+ "group": "默认",
90
+ "config_id": 0,
91
+ "name": "sandbox",
92
+ "title": "沙箱",
93
+ "type": "boolean",
94
+ "control": "switch",
95
+ "tip": "",
96
+ "description": "沙箱支持,可选,默认false. v2.7.0+",
97
+ "display": 100,
98
+ "default": "false",
99
+ "min": 0,
100
+ "max": 1
101
+ }
102
+ ]
26
103
  }
package/lib/app.js CHANGED
@@ -28,8 +28,8 @@ App.prototype.fullAction = function(action) {
28
28
  // 创建插件
29
29
  this.plugin = $.plugin_admin(action.key, action.title || action.name);
30
30
  this.plugin.update(action.jsonFile.dirname()).then(() => {
31
- this.plugin.exec(null, 'init').then(() => {
32
- this.plugin.exec(null, 'start');
31
+ this.plugin.run(null, 'init').then(() => {
32
+ this.plugin.run(null, 'start');
33
33
  });
34
34
  });
35
35
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_os",
3
- "version": "2.5.0",
3
+ "version": "2.5.2",
4
4
  "description": "这是超级美眉服务端框架,用于快速构建应用程序。",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -41,7 +41,7 @@
41
41
  "mm_html": "^1.1.6",
42
42
  "mm_koa_proxy": "^1.0.0",
43
43
  "mm_logs": "^1.1.4",
44
- "mm_machine": "^1.7.6",
44
+ "mm_machine": "^1.7.8",
45
45
  "mm_mongodb": "^1.4.2",
46
46
  "mm_mqtt": "^1.0.6",
47
47
  "mm_mysql": "^1.8.1",