mm_os 3.3.1 → 4.0.0

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 (380) hide show
  1. package/LICENSE +21 -201
  2. package/README.md +491 -99
  3. package/README_EN.md +498 -0
  4. package/adapter/adapter.js +431 -0
  5. package/adapter/custom_persistence.js +660 -0
  6. package/adapter/mqtt.js +273 -0
  7. package/adapter/socket.js +113 -0
  8. package/adapter/web.js +67 -0
  9. package/adapter/websocket.js +146 -0
  10. package/com/api/com.json +5 -0
  11. package/{core/com → com}/api/config.tpl.json +8 -8
  12. package/com/api/drive.js +708 -0
  13. package/com/api/index.js +198 -0
  14. package/com/api/oauth.js +200 -0
  15. package/com/api/script.tpl.js +32 -0
  16. package/com/cmd/README.md +11 -0
  17. package/com/cmd/com.json +5 -0
  18. package/com/cmd/config.tpl.json +122 -0
  19. package/com/cmd/drive.js +1548 -0
  20. package/com/cmd/index.js +1066 -0
  21. package/com/cmd/msg.json +48 -0
  22. package/com/cmd/nlp.js +525 -0
  23. package/com/cmd/script.tpl.js +32 -0
  24. package/com/db/com.json +5 -0
  25. package/com/db/drive.js +1999 -0
  26. package/com/db/index.js +242 -0
  27. package/{core/com → com}/event/README.md +4 -4
  28. package/com/event/com.json +5 -0
  29. package/{core/com → com}/event/config.tpl.json +18 -18
  30. package/com/event/drive.js +59 -0
  31. package/com/event/index.js +409 -0
  32. package/com/event/script.tpl.js +23 -0
  33. package/com/mqtt/com.json +5 -0
  34. package/{core/com → com}/mqtt/config.tpl.json +3 -5
  35. package/com/mqtt/drive.js +676 -0
  36. package/com/mqtt/index.js +822 -0
  37. package/com/mqtt/mm_mqtt.js +425 -0
  38. package/com/mqtt/script.tpl.js +723 -0
  39. package/com/nav/com.json +5 -0
  40. package/com/nav/config.tpl.json +84 -0
  41. package/com/nav/drive.js +702 -0
  42. package/com/nav/index.js +231 -0
  43. package/{core/com → com}/nav/tpl/admin_pc/page_config.vue +280 -280
  44. package/{core/com → com}/nav/tpl/admin_pc/page_config_form.vue +194 -194
  45. package/com/nav/tpl/admin_pc/page_form.vue +180 -0
  46. package/com/nav/tpl/admin_pc/page_view.vue +124 -0
  47. package/com/nav/tpl/dev_pc/page_default.vue +247 -0
  48. package/com/nav/tpl/dev_pc/page_type.vue +313 -0
  49. package/com/nav/tpl/home_pc/page_default.vue +234 -0
  50. package/com/nav/tpl/home_pc/page_form.vue +137 -0
  51. package/com/nav/tpl/home_pc/page_list.vue +234 -0
  52. package/com/nav/tpl/home_pc/page_nav.vue +221 -0
  53. package/com/nav/tpl/home_pc/page_type.vue +234 -0
  54. package/com/nav/tpl/home_pc/page_view.vue +125 -0
  55. package/com/nav/tpl/home_phone/page_channel.vue +234 -0
  56. package/com/nav/tpl/home_phone/page_default.vue +234 -0
  57. package/com/nav/tpl/home_phone/page_form.vue +137 -0
  58. package/com/nav/tpl/home_phone/page_nav.vue +237 -0
  59. package/com/nav/tpl/home_phone/page_type.vue +234 -0
  60. package/com/nav/tpl/home_phone/page_view.vue +125 -0
  61. package/com/nav/viewmodel.js +446 -0
  62. package/com/param/com.json +5 -0
  63. package/{core/com → com}/param/config.tpl.json +7 -1
  64. package/com/param/drive.js +502 -0
  65. package/com/param/index.js +155 -0
  66. package/com/param/script.tpl.js +12 -0
  67. package/com/pendant/com.json +5 -0
  68. package/{core/com/component → com/pendant}/config.tpl.json +15 -13
  69. package/com/pendant/drive.js +204 -0
  70. package/com/pendant/index.js +441 -0
  71. package/com/pendant/pendant.html +16 -0
  72. package/com/pendant/script.tpl.js +18 -0
  73. package/com/socket/com.json +5 -0
  74. package/com/socket/config.tpl.json +12 -0
  75. package/com/socket/drive.js +651 -0
  76. package/com/socket/index.js +351 -0
  77. package/com/socket/script.tpl.js +41 -0
  78. package/com/sql/com.json +5 -0
  79. package/{core/com → com}/sql/config.tpl.json +13 -9
  80. package/com/sql/drive.js +1259 -0
  81. package/com/sql/index.js +150 -0
  82. package/com/sql/script.tpl.js +47 -0
  83. package/com/static/com.json +5 -0
  84. package/{core/com → com}/static/config.tpl.json +10 -6
  85. package/com/static/drive.js +194 -0
  86. package/com/static/index.js +226 -0
  87. package/com/static/script.tpl.js +28 -0
  88. package/com/task/com.json +5 -0
  89. package/{core/com → com}/task/config.tpl.json +4 -6
  90. package/com/task/drive.js +405 -0
  91. package/com/task/index.js +148 -0
  92. package/com/task/script.tpl.js +37 -0
  93. package/com/template/com.json +5 -0
  94. package/com/template/config.tpl.json +16 -0
  95. package/com/template/drive.js +80 -0
  96. package/com/template/index.js +141 -0
  97. package/com.js +156 -0
  98. package/common/README.md +2 -0
  99. package/common/handler/msg/handler.json +22 -0
  100. package/common/handler/msg/index.js +23 -0
  101. package/common/handler/player/handler.json +22 -0
  102. package/common/handler/player/index.js +287 -0
  103. package/common/handler/user/handler.json +22 -0
  104. package/common/handler/user/index.js +23 -0
  105. package/common/middleware/web_after/index.js +29 -0
  106. package/common/middleware/web_after/middleware.json +9 -0
  107. package/common/middleware/web_base/index.js +113 -0
  108. package/common/middleware/web_base/middleware.json +19 -0
  109. package/common/middleware/web_before/index.js +33 -0
  110. package/common/middleware/web_before/middleware.json +9 -0
  111. package/common/middleware/web_cors/index.js +87 -0
  112. package/common/middleware/web_cors/middleware.json +24 -0
  113. package/common/middleware/web_error/index.js +119 -0
  114. package/common/middleware/web_error/middleware.json +18 -0
  115. package/common/middleware/web_ip/index.js +15 -0
  116. package/common/middleware/web_ip/middleware.json +14 -0
  117. package/common/middleware/web_logger/index.js +156 -0
  118. package/common/middleware/web_logger/middleware.json +14 -0
  119. package/common/middleware/web_main/index.js +24 -0
  120. package/common/middleware/web_main/middleware.json +9 -0
  121. package/common/middleware/web_static/index.js +73 -0
  122. package/common/middleware/web_static/middleware.json +54 -0
  123. package/common/middleware/web_waf/index.js +385 -0
  124. package/common/middleware/web_waf/middleware.json +13 -0
  125. package/common/model/msg/index.js +88 -0
  126. package/common/model/msg/model.json +401 -0
  127. package/common/model/player/index.js +63 -0
  128. package/common/model/player/model.json +185 -0
  129. package/common/model/user/index.js +11 -0
  130. package/common/model/user/model.json +219 -0
  131. package/core/app/config.tpl.json +67 -0
  132. package/core/app/index.js +632 -0
  133. package/core/app/script.tpl.js +52 -0
  134. package/core/channel/index.js +899 -0
  135. package/core/channel/matcher.js +585 -0
  136. package/core/com/config.tpl.json +16 -0
  137. package/core/com/index.js +74 -0
  138. package/core/com/script.tpl.js +5 -0
  139. package/core/component/component.js +42 -0
  140. package/core/component/config.tpl.json +63 -0
  141. package/core/component/index.js +273 -0
  142. package/core/component/script.tpl.js +19 -0
  143. package/core/controller/config.tpl.json +14 -0
  144. package/core/controller/index.js +373 -0
  145. package/core/controller/script.tpl.js +27 -0
  146. package/core/factory/config.tpl.json +14 -0
  147. package/core/factory/entity.js +275 -0
  148. package/core/factory/index.js +241 -0
  149. package/core/factory/script.tpl.js +16 -0
  150. package/core/game/bat/index.js +137 -0
  151. package/core/game/bat/world.js +622 -0
  152. package/core/game/config.tpl.json +16 -0
  153. package/core/game/entity_admin.js +230 -0
  154. package/core/game/index.js +186 -0
  155. package/core/handler/config.tpl.json +22 -0
  156. package/core/handler/index.js +181 -0
  157. package/core/handler/script.tpl.js +23 -0
  158. package/core/logic/config.tpl.json +14 -0
  159. package/core/logic/index.js +59 -0
  160. package/core/logic/script.tpl.js +19 -0
  161. package/core/middleware/config.tpl.json +16 -0
  162. package/core/middleware/index.js +125 -0
  163. package/core/middleware/script.tpl.js +37 -0
  164. package/core/mod/config.tpl.json +22 -0
  165. package/core/mod/index.js +130 -0
  166. package/core/mod/script.tpl.js +34 -0
  167. package/core/model/config.tpl.json +219 -0
  168. package/core/model/index.js +272 -0
  169. package/core/model/model.js +27 -0
  170. package/core/model/script.tpl.js +20 -0
  171. package/core/notifier/config.tpl.json +14 -0
  172. package/core/notifier/index.js +77 -0
  173. package/core/notifier/script.tpl.js +20 -0
  174. package/core/plugin/config.tpl.json +24 -0
  175. package/core/plugin/index.js +232 -0
  176. package/core/plugin/script.tpl.js +51 -0
  177. package/core/pusher/config.tpl.json +14 -0
  178. package/core/pusher/index.js +161 -0
  179. package/core/pusher/script.tpl.js +20 -0
  180. package/core/room/bat/index.js +170 -0
  181. package/core/room/bat/room.js +524 -0
  182. package/core/room/config.tpl.json +20 -0
  183. package/core/room/index.js +249 -0
  184. package/core/room/room.js +61 -0
  185. package/core/scene/config.tpl.json +14 -0
  186. package/core/scene/index.js +466 -0
  187. package/core/scene/loop.js +1255 -0
  188. package/core/scene/map.js +28 -0
  189. package/core/scene/script.tpl.js +22 -0
  190. package/core/sender/config.tpl.json +14 -0
  191. package/core/sender/index.js +79 -0
  192. package/core/sender/script.tpl.js +20 -0
  193. package/core/service/config.tpl.json +14 -0
  194. package/core/service/index.js +100 -0
  195. package/core/service/script.tpl.js +25 -0
  196. package/core/store/config.tpl.json +26 -0
  197. package/core/store/index.js +1755 -0
  198. package/core/store/script.tpl.js +22 -0
  199. package/core/store/sql.js +1464 -0
  200. package/core/system/config.tpl.json +18 -0
  201. package/core/system/index.js +312 -0
  202. package/core/system/script.tpl.js +77 -0
  203. package/core/view/config.tpl.json +14 -0
  204. package/core/view/index.js +91 -0
  205. package/core/view/script.tpl.js +20 -0
  206. package/core/zone/bat/index.js +725 -0
  207. package/core/zone/config.tpl.json +54 -0
  208. package/core/zone/index.js +614 -0
  209. package/core/zone/script.tpl.js +10 -0
  210. package/core/zone/zone_bat.js +136 -0
  211. package/core//345/237/272/347/261/273/346/250/241/345/235/227/346/270/205/345/215/225.md +24 -0
  212. package/index.js +17 -333
  213. package/os.js +57 -0
  214. package/package.json +58 -58
  215. package/server.js +598 -0
  216. package/README.en.md +0 -36
  217. package/conf.json +0 -3
  218. package/core/base/mqtt/index.js +0 -1110
  219. package/core/base/mqtt/lib.js +0 -40
  220. package/core/base/web/index.js +0 -245
  221. package/core/com/api/com.json +0 -4
  222. package/core/com/api/drive.js +0 -668
  223. package/core/com/api/index.js +0 -108
  224. package/core/com/api/oauth.js +0 -158
  225. package/core/com/api/script.js +0 -32
  226. package/core/com/app/README.md +0 -3
  227. package/core/com/app/com.json +0 -4
  228. package/core/com/app/config.tpl.json +0 -16
  229. package/core/com/app/drive.js +0 -309
  230. package/core/com/app/index.js +0 -211
  231. package/core/com/app/script.js +0 -155
  232. package/core/com/cmd/com.json +0 -4
  233. package/core/com/cmd/config.tpl.json +0 -66
  234. package/core/com/cmd/drive.js +0 -513
  235. package/core/com/cmd/index.js +0 -354
  236. package/core/com/cmd/old/5w2h.js +0 -54
  237. package/core/com/cmd/old/drive.js +0 -423
  238. package/core/com/cmd/script.js +0 -11
  239. package/core/com/component/README.md +0 -3
  240. package/core/com/component/com.json +0 -4
  241. package/core/com/component/component.html +0 -16
  242. package/core/com/component/drive.js +0 -197
  243. package/core/com/component/index.js +0 -312
  244. package/core/com/component/script.js +0 -18
  245. package/core/com/db/com.json +0 -4
  246. package/core/com/db/drive.js +0 -1160
  247. package/core/com/db/index.js +0 -176
  248. package/core/com/event/com.json +0 -4
  249. package/core/com/event/drive.js +0 -133
  250. package/core/com/event/index.js +0 -345
  251. package/core/com/event/script.js +0 -26
  252. package/core/com/eventer/com.js +0 -477
  253. package/core/com/eventer/com.json +0 -4
  254. package/core/com/middleware/com.js +0 -154
  255. package/core/com/middleware/com.json +0 -4
  256. package/core/com/middleware/config.tpl.json +0 -8
  257. package/core/com/middleware/script.js +0 -9
  258. package/core/com/mqtt/com.json +0 -4
  259. package/core/com/mqtt/drive.js +0 -600
  260. package/core/com/mqtt/index.js +0 -572
  261. package/core/com/mqtt/mm_mqtt.js +0 -330
  262. package/core/com/mqtt/script.js +0 -604
  263. package/core/com/msg/com.js +0 -296
  264. package/core/com/msg/com.json +0 -4
  265. package/core/com/nav/com.json +0 -4
  266. package/core/com/nav/config.tpl.json +0 -75
  267. package/core/com/nav/drive.js +0 -549
  268. package/core/com/nav/index.js +0 -182
  269. package/core/com/nav/tpl/admin_pc/page_form.vue +0 -180
  270. package/core/com/nav/tpl/admin_pc/page_view.vue +0 -124
  271. package/core/com/nav/tpl/dev_pc/page_default.vue +0 -247
  272. package/core/com/nav/tpl/dev_pc/page_type.vue +0 -313
  273. package/core/com/nav/tpl/home_pc/page_default.vue +0 -234
  274. package/core/com/nav/tpl/home_pc/page_form.vue +0 -137
  275. package/core/com/nav/tpl/home_pc/page_list.vue +0 -234
  276. package/core/com/nav/tpl/home_pc/page_nav.vue +0 -221
  277. package/core/com/nav/tpl/home_pc/page_type.vue +0 -234
  278. package/core/com/nav/tpl/home_pc/page_view.vue +0 -125
  279. package/core/com/nav/tpl/home_phone/page_channel.vue +0 -234
  280. package/core/com/nav/tpl/home_phone/page_default.vue +0 -234
  281. package/core/com/nav/tpl/home_phone/page_form.vue +0 -137
  282. package/core/com/nav/tpl/home_phone/page_nav.vue +0 -237
  283. package/core/com/nav/tpl/home_phone/page_type.vue +0 -234
  284. package/core/com/nav/tpl/home_phone/page_view.vue +0 -125
  285. package/core/com/nav/viewmodel.js +0 -296
  286. package/core/com/param/drive.js +0 -366
  287. package/core/com/param/index.js +0 -80
  288. package/core/com/param/script.js +0 -12
  289. package/core/com/param/test.js +0 -98
  290. package/core/com/plugin/README.md +0 -3
  291. package/core/com/plugin/com.json +0 -4
  292. package/core/com/plugin/config.tpl.json +0 -26
  293. package/core/com/plugin/drive.js +0 -536
  294. package/core/com/plugin/index.js +0 -259
  295. package/core/com/plugin/script.js +0 -213
  296. package/core/com/rpc/com.json +0 -4
  297. package/core/com/rpc/drive.js +0 -160
  298. package/core/com/rpc/index.js +0 -87
  299. package/core/com/rpc/rpc.js +0 -118
  300. package/core/com/socket/com.json +0 -4
  301. package/core/com/socket/config.tpl.json +0 -14
  302. package/core/com/socket/drive.js +0 -403
  303. package/core/com/socket/index.js +0 -62
  304. package/core/com/socket/script.js +0 -42
  305. package/core/com/sql/drive.js +0 -1087
  306. package/core/com/sql/index.js +0 -83
  307. package/core/com/sql/script.js +0 -48
  308. package/core/com/static/com.json +0 -4
  309. package/core/com/static/drive.js +0 -220
  310. package/core/com/static/index.js +0 -149
  311. package/core/com/static/script.js +0 -28
  312. package/core/com/task/com.json +0 -4
  313. package/core/com/task/drive.js +0 -403
  314. package/core/com/task/index.js +0 -110
  315. package/core/com/task/script.js +0 -37
  316. package/core/com/timer/com.js +0 -217
  317. package/core/com/timer/com.json +0 -4
  318. package/core/com/tpl/com.js +0 -19
  319. package/core/com/tpl/com.json +0 -4
  320. package/lib/actions.js +0 -50
  321. package/lib/base.js +0 -361
  322. package/lib/com.js +0 -29
  323. package/lib/ref.js +0 -121
  324. package/middleware/cors/index.js +0 -119
  325. package/middleware/cors/middleware.json +0 -20
  326. package/middleware/csrf/index.js +0 -202
  327. package/middleware/csrf/middleware.json +0 -24
  328. package/middleware/ip_firewall/index.js +0 -476
  329. package/middleware/ip_firewall/middleware.json +0 -109
  330. package/middleware/mqtt_base/index.js +0 -10
  331. package/middleware/mqtt_base/middleware.json +0 -11
  332. package/middleware/security_audit/index.js +0 -543
  333. package/middleware/security_audit/middleware.json +0 -48
  334. package/middleware/waf/index.js +0 -343
  335. package/middleware/waf/middleware.json +0 -10
  336. package/middleware/waf_ddos/index.js +0 -520
  337. package/middleware/waf_ddos/middleware.json +0 -38
  338. package/middleware/waf_xss/index.js +0 -269
  339. package/middleware/waf_xss/middleware.json +0 -18
  340. package/middleware/web_after/index.js +0 -33
  341. package/middleware/web_after/middleware.json +0 -10
  342. package/middleware/web_base/index.js +0 -90
  343. package/middleware/web_base/middleware.json +0 -10
  344. package/middleware/web_before/index.js +0 -27
  345. package/middleware/web_before/middleware.json +0 -10
  346. package/middleware/web_check/index.js +0 -28
  347. package/middleware/web_check/middleware.json +0 -10
  348. package/middleware/web_main/index.js +0 -28
  349. package/middleware/web_main/middleware.json +0 -10
  350. package/middleware/web_proxy/index.js +0 -37
  351. package/middleware/web_proxy/middleware.json +0 -10
  352. package/middleware/web_render/index.js +0 -87
  353. package/middleware/web_render/middleware.json +0 -10
  354. package/middleware/web_socket/index.js +0 -34
  355. package/middleware/web_socket/middleware.json +0 -10
  356. package/middleware/web_static/index.js +0 -115
  357. package/middleware/web_static/middleware.json +0 -10
  358. /package/{core/com → com}/api/README.md +0 -0
  359. /package/{core/com → com}/db/README.md +0 -0
  360. /package/{core/com → com}/mqtt/README.md +0 -0
  361. /package/{core/com → com}/nav/README.md +0 -0
  362. /package/{core/com → com}/nav/tpl/admin_pc/page_channel.vue +0 -0
  363. /package/{core/com → com}/nav/tpl/admin_pc/page_default.vue +0 -0
  364. /package/{core/com → com}/nav/tpl/admin_pc/page_lang.vue +0 -0
  365. /package/{core/com → com}/nav/tpl/admin_pc/page_nav.vue +0 -0
  366. /package/{core/com → com}/nav/tpl/admin_pc/page_table.vue +0 -0
  367. /package/{core/com → com}/nav/tpl/admin_pc/page_type.vue +0 -0
  368. /package/{core/com → com}/nav/tpl/dev_pc/page_channel.vue +0 -0
  369. /package/{core/com → com}/nav/tpl/dev_pc/page_config.vue +0 -0
  370. /package/{core/com → com}/nav/tpl/dev_pc/page_form.vue +0 -0
  371. /package/{core/com → com}/nav/tpl/dev_pc/page_nav.vue +0 -0
  372. /package/{core/com → com}/nav/tpl/dev_pc/page_table.vue +0 -0
  373. /package/{core/com → com}/nav/tpl/home_pc/page_channel.vue +0 -0
  374. /package/{core/com → com}/nav/tpl/home_phone/page_list.vue +0 -0
  375. /package/{core/com → com}/param/README.md +0 -0
  376. /package/{core/com/cmd → com/pendant}/README.md +0 -0
  377. /package/{core/com → com}/socket/README.md +0 -0
  378. /package/{core/com → com}/sql/README.md +0 -0
  379. /package/{core/com → com}/static/README.md +0 -0
  380. /package/{core/com → com}/task/README.md +0 -0
@@ -1,423 +0,0 @@
1
- const Item = require('mm_machine').Item;
2
- const Param = require('../param/drive.js');
3
-
4
- /**
5
- * 指令驱动类
6
- * @extends {Item}
7
- * @class
8
- */
9
- class Drive extends Item {
10
- /**
11
- * 构造函数
12
- * @param {String} dir 当前目录
13
- * @constructor
14
- */
15
- constructor(dir) {
16
- super(dir, __dirname);
17
- this.default_file = "./cmd.json";
18
-
19
- // 开关 true为开启, false为关闭
20
- this.onOff = true;
21
-
22
- /* 通用项 */
23
- // 配置参数
24
- this.config = {
25
- // 标识名
26
- "name": "demo",
27
- // 分组名
28
- "title": "指令标题",
29
- // 描述, 用于描述该接口有什么用的
30
- "description": "暂无描述",
31
- // 文件名
32
- "func_file": "./index.js",
33
- // 加载顺序,数字越大越后面加载
34
- "sort": 1000,
35
- // 分组
36
- "group": "default",
37
- // 类型: query便民查询,action执行,game游戏,orther其他,为空表示未分类
38
- "type": "",
39
- // 匹配关键词
40
- "match": [],
41
- // 不含关键词
42
- "not_match": [],
43
- // 过滤关键词
44
- "filter": [],
45
- // 摘取
46
- "extract": [],
47
- // 验证参数集
48
- "param": [
49
- // {
50
- // // 参数名
51
- // "name": "name",
52
- // // 参数介绍名
53
- // "title": "名称",
54
- // // 参数格式
55
- // "format": "",
56
- // // 缺少参数提示语,传键值对,例如:{ number: "快递单号多少?" }
57
- // "not_tip": "",
58
- // // 错误提示
59
- // "error_tip": ""
60
- // },
61
- ]
62
- }
63
- }
64
- };
65
-
66
- /**
67
- * 创建一个参数模型
68
- */
69
- Drive.prototype.model = function() {
70
- return {
71
- // 参数名
72
- "name": "name",
73
- // 参数介绍名
74
- "title": "名称",
75
- // 参数格式
76
- "format": "",
77
- // 缺少参数提示语,传键值对,例如:{ number: "快递单号多少?" }
78
- "not_tip": "",
79
- // 错误提示
80
- "error_tip": ""
81
- };
82
- };
83
-
84
- /**
85
- * 为什么要这样做(疑问)
86
- * @param {Object} param 状态参数
87
- */
88
- Drive.prototype.why = async function(param, db) {
89
- return true;
90
- };
91
-
92
- /**
93
- * 什么时候(时间)
94
- * @param {Object} param 状态参数
95
- * @param {Object} db 数据管理器
96
- * @return {Boolean} 条件满足返回true, 否则返回false
97
- */
98
- Drive.prototype.when = async function(param, db) {
99
- return true;
100
- };
101
-
102
- /**
103
- * 什么地方(地点)
104
- * @param {Object} param 状态参数
105
- * @param {Object} db 数据管理器
106
- * @return {Boolean} 条件满足返回true, 否则返回false
107
- */
108
- Drive.prototype.where = async function(param, db) {
109
- return true;
110
- };
111
-
112
- /**
113
- * 什么人(人物)
114
- * @param {Object} param 状态参数
115
- * @param {Object} db 数据管理器
116
- * @return {Boolean} 条件满足返回true, 否则返回false
117
- */
118
- Drive.prototype.who = async function(param, db) {
119
- return true;
120
- };
121
-
122
- /**
123
- * 做什么(事件)
124
- * @param {Object} param 状态参数
125
- * @param {Object} db 数据管理器
126
- * @return {Boolean} 条件满足返回true, 否则返回false
127
- */
128
- Drive.prototype.what = async function(param, db) {
129
- return true;
130
- };
131
-
132
- /**
133
- * 怎么做(方法), 对行为做决策
134
- * @param {Object} param 状态参数
135
- * @param {Object} db 数据管理器
136
- * @return {String} 返回执行函数
137
- */
138
- Drive.prototype.how = async function(param, db) {
139
- var obj = {
140
- name: "main"
141
- };
142
- var cg = this.config;
143
- var lt = cg.condition.how;
144
- var content = param.content;
145
- var len = lt.length;
146
- for (var i = 0; i < len; i++) {
147
- var o = lt[i];
148
- var str = o.not_match;
149
- if (str) {
150
- if (str.startWith('/')) {
151
- try {
152
- var rx = eval(str);
153
- if (rx.test(content) === false) {
154
- var ct = db.msg_log.content;
155
- if (ct) {
156
- var mh = ct.match(rx);
157
- var txt = "";
158
- if (mh) {
159
- var value = mh[mh.length - 1];
160
- var keyword = db.msg_log.keyword + "\r\n" + value;
161
- db.msg_log.keyword = keyword.trim();
162
- param.content = content.trim() + "\r\n" + value;
163
- } else {
164
- obj = o;
165
- break;
166
- }
167
- } else {
168
- obj = o;
169
- break;
170
- }
171
- } else {
172
- db.msg_log.keyword = content.trim();
173
- }
174
- } catch (e) {
175
- $.log.error('正则表达式错误:' + str);
176
- }
177
- } else if (!content.has(str)) {
178
- obj = o;
179
- break;
180
- }
181
- } else if (o.func_name) {
182
- var func = this[o.func_name];
183
- if (func) {
184
- var bl = await func(param, db);
185
- if (!bl) {
186
- obj = o;
187
- }
188
- }
189
- }
190
- }
191
- return obj;
192
- };
193
-
194
- /**
195
- * 做到什么程度(结束条件)
196
- * @param {Object} param 状态参数
197
- * @param {Object} ret 执行结果
198
- * @param {Object} db 数据管理器
199
- * @return {Boolean} 返回执行结果判断 true表示已完成一个行为周期,false为未完成,未完成则继续缓存
200
- */
201
- Drive.prototype.how_much = async function(param, db, ret) {
202
- if (param.content.length > 255) {
203
- return true;
204
- }
205
- return false;
206
- };
207
-
208
- /**
209
- * 补全参数
210
- * @param {Object} content 正文
211
- * @param {Object} db 数据管理器
212
- * @return {Object} 返回参数表单
213
- */
214
- Drive.prototype.supply = async function(content, db) {
215
- var form = {};
216
- if (db.msg_log.form) {
217
- form = db.msg_log.form.toJson();
218
- } else {
219
- var ct = content + "";
220
- var cg = this.config;
221
- var post = cg.post;
222
- var arr = [];
223
- arr.addList(post.body);
224
- arr.addList(post.body_required);
225
- var list = cg.list;
226
- for (var i = 0; i < arr.length; i++) {
227
- var k = arr[i];
228
- var o = list[k];
229
- if (o.string) {
230
- var str = o.string.regex;
231
- if (str) {
232
- try {
233
- var rx = eval(str);
234
- var mh = str.match(rx);
235
- if (mh) {
236
- var value = mh[0];
237
- form[k] = value;
238
- ct = ct.replace(value, '');
239
- }
240
- } catch (e) {
241
- $.log.error('正则表达式错误:' + str);
242
- }
243
- } else {
244
- form[k] = "";
245
- }
246
- } else {
247
- form[k] = 0;
248
- }
249
- }
250
- }
251
- return form;
252
- };
253
-
254
- /**
255
- * 检验条件是否满足
256
- * @param {Object} form 表单
257
- * @param {Object} db 数据管理器
258
- * @param {Boolean} first 是否第一次验证,第一次验证时会将错误参数清空,提示填写。而非第一次验证则提示错误重填
259
- * @return {String} 验证失败返回错误提示
260
- */
261
- Drive.prototype.check = async function(form, db, first) {
262
- var func = new Param();
263
- db.msg_log.form = JSON.stringify(form);
264
- };
265
-
266
- /**
267
- * 执行
268
- * @param {Object} param 状态参数
269
- * @param {Object} db 数据管理器
270
- * @return {Object} 返回执行结果
271
- */
272
- Drive.prototype.main = async function(param, db) {
273
- return "你好";
274
- };
275
-
276
- /**
277
- * 执行
278
- * @param {Object} param 状态参数
279
- * @param {Object} db 数据管理器
280
- * @return {Object} 返回执行结果
281
- */
282
- Drive.prototype.run = async function(param, db) {
283
- var content = await this.extract(param.content);
284
- content = await this.filter(content);
285
- param.content = content;
286
-
287
- var bl = true;
288
- bl = await this.what(param, db);
289
- if (!bl) {
290
- return null;
291
- }
292
- bl = await this.who(param, db);
293
- if (!bl) {
294
- return null;
295
- }
296
- bl = await this.where(param, db);
297
- if (!bl) {
298
- return null;
299
- }
300
- bl = await this.when(param, db);
301
- if (!bl) {
302
- return null;
303
- }
304
- var ret = "";
305
- var o = await this.how(param, db);
306
- if (o.question) {
307
- ret = o.question;
308
- } else if (o.name) {
309
- var func = this[o.name];
310
- if (func) {
311
- ret = await func(param, db);
312
- if (ret) {
313
- bl = this.how_much(param, db, ret);
314
- // if (bl && db.msg_log) {
315
- // db.msg_log.end = 1;
316
- // }
317
- }
318
- }
319
- }
320
- return ret;
321
- };
322
-
323
- /**
324
- * 校验是否匹配指令
325
- * @param {Object} content 请求的正文
326
- * @param {Object} db 数据管理器
327
- * @return {Boolean} 匹配返回true,不匹配返回false
328
- */
329
- Drive.prototype.match = function(content, db) {
330
- var cg = this.config;
331
- var lt = cg.match;
332
- var bl = false;
333
- for (var i = 0, o; o = lt[i++];) {
334
- if (content.matchs(o)) {
335
- bl = true;
336
- break;
337
- }
338
- }
339
- return bl;
340
- };
341
-
342
- /**
343
- * 校验是否不含关键词
344
- * @param {Object} content 请求的正文
345
- * @param {Object} db 数据管理器
346
- * @return {Boolean} 不含返回true,含有返回false
347
- */
348
- Drive.prototype.not_match = function(content, db) {
349
- var cg = this.config;
350
- var lt = cg.not_match;
351
- var bl = true;
352
- for (var i = 0, o; o = lt[i++];) {
353
- if (content.matchs(o)) {
354
- bl = false;
355
- break;
356
- }
357
- }
358
- return bl;
359
- };
360
-
361
- /**
362
- * 过滤正文
363
- * @param {String} content 正文
364
- * @param {Object} db 数据管理器
365
- * @return {Object} 返回过滤后的参数
366
- */
367
- Drive.prototype.filter = async function(content, db) {
368
- var cg = this.config;
369
- var lt = cg.filter;
370
- var bl = false;
371
- for (var i = 0, str; str = lt[i++];) {
372
- if (str.startWith('/')) {
373
- try {
374
- var rx = eval(str);
375
- content = content.replace(rx, '');
376
- } catch (e) {
377
- $.log.error('正则表达式错误:' + str);
378
- }
379
- } else {
380
- content = content.replace(str, '');
381
- }
382
- }
383
- return content;
384
- };
385
-
386
- /**
387
- * 抽取正文
388
- * @param {String} content 正文
389
- * @param {Object} db 数据管理器
390
- * @return {Object} 返回过滤后的参数
391
- */
392
- Drive.prototype.extract = async function(content, db) {
393
- var cg = this.config;
394
- var lt = cg.extract;
395
- var bl = false;
396
- for (var i = 0, str; str = lt[i++];) {
397
- if (str.startWith('/')) {
398
- try {
399
- var rx = eval(str);
400
- var mh = content.match(rx);
401
- var ct = "";
402
- if (mh) {
403
- for (var n = 0; n < mh.length; n++) {
404
- ct += "\r\n" + mh[0];
405
- }
406
- content = ct;
407
- }
408
- } catch (e) {
409
- $.log.error('正则表达式错误:' + str);
410
- }
411
- } else if (str.startWith('*')) {
412
- content = content.left(str.replace('*', ''), true)
413
- } else if (str.endWith('*')) {
414
- content = content.right(str.replace('*', ''), true)
415
- } else if (str.indexOf('*') !== -1) {
416
- var arr = str.split('*');
417
- content = content.between(arr[0], arr[1], true);
418
- }
419
- }
420
- return content;
421
- };
422
-
423
- module.exports = Drive;
@@ -1,11 +0,0 @@
1
- module.exports = {
2
- /**
3
- * 指令行为主函数
4
- * @param {Object} msg 消息
5
- * @param {Object} db 数据管理器,如: { next: async function{}, ret: {} }
6
- * @return {Object} 执行结果
7
- */
8
- async main(msg, db) {
9
- return "你好, 请问有什么能帮到你?";
10
- }
11
- };
@@ -1,3 +0,0 @@
1
- ## 指令框架
2
- 用于以聊天的方式操作程序。
3
- 前端发送字符串,后端通过字符串判断是否为指令进而执行程序。提高工作效率。
@@ -1,4 +0,0 @@
1
- {
2
- "name": "组件管理器",
3
- "script": "./index.js"
4
- }
@@ -1,16 +0,0 @@
1
- <div class="mm_col ${' ' + config.layout}">
2
- <div id="${config.id}" class="component_demo ${' ' + config.class}">
3
- <div class="title">${@config.options.xxx}</div>
4
- <div class="description">示例组件描述</div>
5
- </div>
6
- </div>
7
-
8
- <style scoped>
9
- /*[config.style]*/
10
-
11
- .component_demo {}
12
-
13
- .component_demo .title {}
14
-
15
- .component_demo .description {}
16
- </style>
@@ -1,197 +0,0 @@
1
- const compressing = require('compressing');
2
- const Item = require('mm_machine').Item;
3
-
4
- /**
5
- * 指令驱动类
6
- * @extends {Item}
7
- * @class
8
- */
9
- class Drive extends Item {
10
- /**
11
- * 构造函数
12
- * @param {String} dir 当前目录
13
- * @constructor
14
- */
15
- constructor(dir) {
16
- super(dir, __dirname);
17
- this.default_file = "./component.json";
18
- // 默认启用热更新
19
- this.mode = 3;
20
- /* 通用项 */
21
- // 配置参数
22
- this.config = {
23
- // 应用于,根据应用而判断使用
24
- "app": "home",
25
- // 名称, 用于动态增删改配置
26
- "name": "demo",
27
- // 标题, 用于查询时
28
- "title": "示例组件",
29
- // 描述, 用于介绍该组件的作用
30
- "description": "暂无描述",
31
- // 执行顺序, 数值越小的越优先显示
32
- "sort": 100,
33
- // 分组, 可以将特有的分一个组, 方便用户查询
34
- "group": "default",
35
- // 分类, 例如: 查询生活类、监测类、便民类
36
- "type": "默认",
37
- // 脚本文件
38
- "func_file": "./component.js",
39
- // 渲染
40
- "template": "./component.html",
41
- // 状态, 0为未开启 1为开启
42
- "state": 1,
43
- // 配置
44
- "options": [],
45
- // 定位 由后台指定的展示位置
46
- "location": []
47
- }
48
- }
49
- };
50
-
51
- /**
52
- * 创建一个参数模型
53
- */
54
- Drive.prototype.model = function() {
55
- return {
56
- // 应用于,根据应用而判断使用
57
- "app": "home",
58
- // 名称, 用于动态增删改配置
59
- "name": "demo",
60
- // 标题, 用于查询时
61
- "title": "示例组件",
62
- // 描述, 用于介绍该组件的作用
63
- "description": "暂无描述",
64
- // 执行顺序, 数值越小的越优先显示
65
- "sort": 100,
66
- // 分组, 可以将特有的分一个组, 方便用户查询
67
- "group": "default",
68
- // 分类, 例如: 查询生活类、监测类、便民类
69
- "type": "监测",
70
- // 脚本文件, 非必传,可和渲染文件二选一传
71
- "func_file": "./component.js",
72
- // 渲染, 非必传,可和脚本文件二选一传
73
- "template": "./component.html",
74
- // 状态, 0为未开启 1为开启
75
- "state": 1,
76
- // 配置
77
- "options": [],
78
- // 定位 由后台指定的展示位置
79
- "location": [{
80
- "path": "/admin/index",
81
- "position": "main",
82
- "available": 1
83
- }]
84
- }
85
- };
86
-
87
- /**
88
- * 新建配置文件
89
- * @param {String} 文件
90
- */
91
- Drive.prototype.new_config = function(file) {
92
- var fl = __dirname + "/config.tpl.json";
93
- if (fl.hasFile()) {
94
- var text = fl.loadText();
95
- if (text) {
96
- var l = $.slash;
97
- var arr = file.split(l);
98
- arr = arr.slice(arr.indexOf('app'));
99
- var app = arr[1];
100
- var name = file.dirname();
101
- text = text.replaceAll('{0}', name);
102
- text = text.replaceAll('{1}', app);
103
- file.saveText(text);
104
- }
105
- }
106
- };
107
-
108
- /**
109
- * 新建脚本
110
- * @param {String} file 文件
111
- */
112
- Drive.prototype.new_script = function(file) {
113
- var fl = __dirname + "/script.js";
114
- if (fl.hasFile()) {
115
- var text = fl.loadText();
116
- if (text) {
117
- var l = $.slash;
118
- var arr = file.split(l);
119
- var name = arr[arr.length - 2];
120
- text = text.replaceAll('{0}', name);
121
- file.saveText(text);
122
- }
123
- }
124
-
125
- var file_html = "./component.html".fullname(file.dirname());
126
- if (!file_html.hasFile()) {
127
- var flh = __dirname + "/component.html";
128
- if (flh.hasFile()) {
129
- var html = flh.loadText();
130
- file_html.saveText(html);
131
- }
132
- }
133
- };
134
-
135
- /**
136
- * 获取配置参数
137
- * @param {Object} 设置配置
138
- * @return {Object} 返回配置参数
139
- */
140
- Drive.prototype.design_option = function(body) {
141
- var cg = this.config;
142
- if (Array.isArray(body)) {
143
- cg.options = body;
144
- } else {
145
- var options = cg.options || [];
146
- var option = options.getObj({
147
- name: body.name
148
- });
149
- if (option) {
150
- Object.assign(option, body);
151
- } else {
152
- options.push(body);
153
- }
154
- cg.options = options;
155
- }
156
- }
157
-
158
- /**
159
- * 挂件模板
160
- * @param {Object} ctx 请求上下文
161
- * @param {Object} db 数据管理器,如: { next: async function{}, ret: {} }
162
- * @return {Object} 执行结果
163
- */
164
- Drive.prototype.tpl = async function(ctx, db) {
165
- var html_file = this.config.template || "./component.html";
166
- return html_file.fullname(this.dir).loadText();
167
- };
168
-
169
- /**
170
- * 组件主函数
171
- * @param {Object} ctx 请求上下文
172
- * @param {Object} db 数据管理器,如: { next: async function{}, ret: {} }
173
- * @return {Object} 执行结果
174
- */
175
- Drive.prototype.main = async function(ctx, db) {
176
- var model = {};
177
- var html_file = this.config.template || "./component.html";
178
- return db.tpl.view(html_file.fullname(this.dir), model);
179
- };
180
-
181
- /**
182
- * 压缩主题模板
183
- * @param {String} 要压缩的目录
184
- * @returns {String} 打包成功返回压缩包文件地址
185
- */
186
- Drive.prototype.zip = async function(zip_dir = "/static/file/zip/") {
187
- var dir = this.filename.dirname();
188
- var file = ("./" + this.config.name + '.zip').fullname(zip_dir);
189
- file.addDir();
190
- var done = await compressing.zip.compressDir(dir, file);
191
- if (file.hasFile()) {
192
- return file;
193
- }
194
- return null;
195
- }
196
-
197
- module.exports = Drive;