mm_os 3.3.0 → 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/com/event/com.json +5 -0
  28. package/{core/com → com}/event/config.tpl.json +8 -8
  29. package/com/event/drive.js +59 -0
  30. package/com/event/index.js +409 -0
  31. package/com/event/script.tpl.js +23 -0
  32. package/com/mqtt/com.json +5 -0
  33. package/{core/com → com}/mqtt/config.tpl.json +3 -5
  34. package/com/mqtt/drive.js +676 -0
  35. package/com/mqtt/index.js +822 -0
  36. package/com/mqtt/mm_mqtt.js +425 -0
  37. package/com/mqtt/script.tpl.js +723 -0
  38. package/com/nav/com.json +5 -0
  39. package/com/nav/config.tpl.json +84 -0
  40. package/com/nav/drive.js +702 -0
  41. package/com/nav/index.js +231 -0
  42. package/{core/com → com}/nav/tpl/admin_pc/page_config.vue +280 -280
  43. package/{core/com → com}/nav/tpl/admin_pc/page_config_form.vue +194 -194
  44. package/com/nav/tpl/admin_pc/page_form.vue +180 -0
  45. package/com/nav/tpl/admin_pc/page_view.vue +124 -0
  46. package/com/nav/tpl/dev_pc/page_default.vue +247 -0
  47. package/com/nav/tpl/dev_pc/page_type.vue +313 -0
  48. package/com/nav/tpl/home_pc/page_default.vue +234 -0
  49. package/com/nav/tpl/home_pc/page_form.vue +137 -0
  50. package/com/nav/tpl/home_pc/page_list.vue +234 -0
  51. package/com/nav/tpl/home_pc/page_nav.vue +221 -0
  52. package/com/nav/tpl/home_pc/page_type.vue +234 -0
  53. package/com/nav/tpl/home_pc/page_view.vue +125 -0
  54. package/com/nav/tpl/home_phone/page_channel.vue +234 -0
  55. package/com/nav/tpl/home_phone/page_default.vue +234 -0
  56. package/com/nav/tpl/home_phone/page_form.vue +137 -0
  57. package/com/nav/tpl/home_phone/page_nav.vue +237 -0
  58. package/com/nav/tpl/home_phone/page_type.vue +234 -0
  59. package/com/nav/tpl/home_phone/page_view.vue +125 -0
  60. package/com/nav/viewmodel.js +446 -0
  61. package/com/param/com.json +5 -0
  62. package/{core/com → com}/param/config.tpl.json +7 -1
  63. package/com/param/drive.js +502 -0
  64. package/com/param/index.js +155 -0
  65. package/com/param/script.tpl.js +12 -0
  66. package/com/pendant/com.json +5 -0
  67. package/{core/com/component → com/pendant}/config.tpl.json +15 -13
  68. package/com/pendant/drive.js +204 -0
  69. package/com/pendant/index.js +441 -0
  70. package/com/pendant/pendant.html +16 -0
  71. package/com/pendant/script.tpl.js +18 -0
  72. package/com/socket/com.json +5 -0
  73. package/com/socket/config.tpl.json +12 -0
  74. package/com/socket/drive.js +651 -0
  75. package/com/socket/index.js +351 -0
  76. package/com/socket/script.tpl.js +41 -0
  77. package/com/sql/com.json +5 -0
  78. package/{core/com → com}/sql/config.tpl.json +13 -9
  79. package/com/sql/drive.js +1259 -0
  80. package/com/sql/index.js +150 -0
  81. package/com/sql/script.tpl.js +47 -0
  82. package/com/static/com.json +5 -0
  83. package/{core/com → com}/static/config.tpl.json +10 -6
  84. package/com/static/drive.js +194 -0
  85. package/com/static/index.js +226 -0
  86. package/com/static/script.tpl.js +28 -0
  87. package/com/task/com.json +5 -0
  88. package/{core/com → com}/task/config.tpl.json +4 -6
  89. package/com/task/drive.js +405 -0
  90. package/com/task/index.js +148 -0
  91. package/com/task/script.tpl.js +37 -0
  92. package/com/template/com.json +5 -0
  93. package/com/template/config.tpl.json +16 -0
  94. package/com/template/drive.js +80 -0
  95. package/com/template/index.js +141 -0
  96. package/com.js +156 -0
  97. package/common/README.md +2 -0
  98. package/common/handler/msg/handler.json +22 -0
  99. package/common/handler/msg/index.js +23 -0
  100. package/common/handler/player/handler.json +22 -0
  101. package/common/handler/player/index.js +287 -0
  102. package/common/handler/user/handler.json +22 -0
  103. package/common/handler/user/index.js +23 -0
  104. package/common/middleware/web_after/index.js +29 -0
  105. package/common/middleware/web_after/middleware.json +9 -0
  106. package/common/middleware/web_base/index.js +113 -0
  107. package/common/middleware/web_base/middleware.json +19 -0
  108. package/common/middleware/web_before/index.js +33 -0
  109. package/common/middleware/web_before/middleware.json +9 -0
  110. package/common/middleware/web_cors/index.js +87 -0
  111. package/common/middleware/web_cors/middleware.json +24 -0
  112. package/common/middleware/web_error/index.js +119 -0
  113. package/common/middleware/web_error/middleware.json +18 -0
  114. package/common/middleware/web_ip/index.js +15 -0
  115. package/common/middleware/web_ip/middleware.json +14 -0
  116. package/common/middleware/web_logger/index.js +156 -0
  117. package/common/middleware/web_logger/middleware.json +14 -0
  118. package/common/middleware/web_main/index.js +24 -0
  119. package/common/middleware/web_main/middleware.json +9 -0
  120. package/common/middleware/web_static/index.js +73 -0
  121. package/common/middleware/web_static/middleware.json +54 -0
  122. package/common/middleware/web_waf/index.js +385 -0
  123. package/common/middleware/web_waf/middleware.json +13 -0
  124. package/common/model/msg/index.js +88 -0
  125. package/common/model/msg/model.json +401 -0
  126. package/common/model/player/index.js +63 -0
  127. package/common/model/player/model.json +185 -0
  128. package/common/model/user/index.js +11 -0
  129. package/common/model/user/model.json +219 -0
  130. package/core/app/config.tpl.json +67 -0
  131. package/core/app/index.js +632 -0
  132. package/core/app/script.tpl.js +52 -0
  133. package/core/channel/index.js +899 -0
  134. package/core/channel/matcher.js +585 -0
  135. package/core/com/config.tpl.json +16 -0
  136. package/core/com/index.js +74 -0
  137. package/core/com/script.tpl.js +5 -0
  138. package/core/component/component.js +42 -0
  139. package/core/component/config.tpl.json +63 -0
  140. package/core/component/index.js +273 -0
  141. package/core/component/script.tpl.js +19 -0
  142. package/core/controller/config.tpl.json +14 -0
  143. package/core/controller/index.js +373 -0
  144. package/core/controller/script.tpl.js +27 -0
  145. package/core/factory/config.tpl.json +14 -0
  146. package/core/factory/entity.js +275 -0
  147. package/core/factory/index.js +241 -0
  148. package/core/factory/script.tpl.js +16 -0
  149. package/core/game/bat/index.js +137 -0
  150. package/core/game/bat/world.js +622 -0
  151. package/core/game/config.tpl.json +16 -0
  152. package/core/game/entity_admin.js +230 -0
  153. package/core/game/index.js +186 -0
  154. package/core/handler/config.tpl.json +22 -0
  155. package/core/handler/index.js +181 -0
  156. package/core/handler/script.tpl.js +23 -0
  157. package/core/logic/config.tpl.json +14 -0
  158. package/core/logic/index.js +59 -0
  159. package/core/logic/script.tpl.js +19 -0
  160. package/core/middleware/config.tpl.json +16 -0
  161. package/core/middleware/index.js +125 -0
  162. package/core/middleware/script.tpl.js +37 -0
  163. package/core/mod/config.tpl.json +22 -0
  164. package/core/mod/index.js +130 -0
  165. package/core/mod/script.tpl.js +34 -0
  166. package/core/model/config.tpl.json +219 -0
  167. package/core/model/index.js +272 -0
  168. package/core/model/model.js +27 -0
  169. package/core/model/script.tpl.js +20 -0
  170. package/core/notifier/config.tpl.json +14 -0
  171. package/core/notifier/index.js +77 -0
  172. package/core/notifier/script.tpl.js +20 -0
  173. package/core/plugin/config.tpl.json +24 -0
  174. package/core/plugin/index.js +232 -0
  175. package/core/plugin/script.tpl.js +51 -0
  176. package/core/pusher/config.tpl.json +14 -0
  177. package/core/pusher/index.js +161 -0
  178. package/core/pusher/script.tpl.js +20 -0
  179. package/core/room/bat/index.js +170 -0
  180. package/core/room/bat/room.js +524 -0
  181. package/core/room/config.tpl.json +20 -0
  182. package/core/room/index.js +249 -0
  183. package/core/room/room.js +61 -0
  184. package/core/scene/config.tpl.json +14 -0
  185. package/core/scene/index.js +466 -0
  186. package/core/scene/loop.js +1255 -0
  187. package/core/scene/map.js +28 -0
  188. package/core/scene/script.tpl.js +22 -0
  189. package/core/sender/config.tpl.json +14 -0
  190. package/core/sender/index.js +79 -0
  191. package/core/sender/script.tpl.js +20 -0
  192. package/core/service/config.tpl.json +14 -0
  193. package/core/service/index.js +100 -0
  194. package/core/service/script.tpl.js +25 -0
  195. package/core/store/config.tpl.json +26 -0
  196. package/core/store/index.js +1755 -0
  197. package/core/store/script.tpl.js +22 -0
  198. package/core/store/sql.js +1464 -0
  199. package/core/system/config.tpl.json +18 -0
  200. package/core/system/index.js +312 -0
  201. package/core/system/script.tpl.js +77 -0
  202. package/core/view/config.tpl.json +14 -0
  203. package/core/view/index.js +91 -0
  204. package/core/view/script.tpl.js +20 -0
  205. package/core/zone/bat/index.js +725 -0
  206. package/core/zone/config.tpl.json +54 -0
  207. package/core/zone/index.js +614 -0
  208. package/core/zone/script.tpl.js +10 -0
  209. package/core/zone/zone_bat.js +136 -0
  210. package/core//345/237/272/347/261/273/346/250/241/345/235/227/346/270/205/345/215/225.md +24 -0
  211. package/index.js +17 -314
  212. package/os.js +57 -0
  213. package/package.json +60 -58
  214. package/server.js +598 -0
  215. package/README.en.md +0 -36
  216. package/conf.json +0 -3
  217. package/core/base/mqtt/index.js +0 -1107
  218. package/core/base/mqtt/lib.js +0 -40
  219. package/core/base/web/index.js +0 -243
  220. package/core/com/api/com.json +0 -4
  221. package/core/com/api/drive.js +0 -668
  222. package/core/com/api/index.js +0 -108
  223. package/core/com/api/oauth.js +0 -158
  224. package/core/com/api/script.js +0 -32
  225. package/core/com/app/README.md +0 -3
  226. package/core/com/app/com.json +0 -4
  227. package/core/com/app/config.tpl.json +0 -16
  228. package/core/com/app/drive.js +0 -309
  229. package/core/com/app/index.js +0 -211
  230. package/core/com/app/script.js +0 -155
  231. package/core/com/cmd/com.json +0 -4
  232. package/core/com/cmd/config.tpl.json +0 -66
  233. package/core/com/cmd/drive.js +0 -513
  234. package/core/com/cmd/index.js +0 -354
  235. package/core/com/cmd/old/5w2h.js +0 -54
  236. package/core/com/cmd/old/drive.js +0 -423
  237. package/core/com/cmd/script.js +0 -11
  238. package/core/com/component/README.md +0 -3
  239. package/core/com/component/com.json +0 -4
  240. package/core/com/component/component.html +0 -16
  241. package/core/com/component/drive.js +0 -197
  242. package/core/com/component/index.js +0 -312
  243. package/core/com/component/script.js +0 -18
  244. package/core/com/db/com.json +0 -4
  245. package/core/com/db/drive.js +0 -1160
  246. package/core/com/db/index.js +0 -176
  247. package/core/com/event/com.json +0 -4
  248. package/core/com/event/drive.js +0 -133
  249. package/core/com/event/index.js +0 -345
  250. package/core/com/event/script.js +0 -26
  251. package/core/com/eventer/com.js +0 -477
  252. package/core/com/eventer/com.json +0 -4
  253. package/core/com/middleware/com.js +0 -153
  254. package/core/com/middleware/com.json +0 -4
  255. package/core/com/middleware/config.tpl.json +0 -8
  256. package/core/com/middleware/script.js +0 -9
  257. package/core/com/mqtt/com.json +0 -4
  258. package/core/com/mqtt/drive.js +0 -600
  259. package/core/com/mqtt/index.js +0 -572
  260. package/core/com/mqtt/mm_mqtt.js +0 -330
  261. package/core/com/mqtt/script.js +0 -604
  262. package/core/com/msg/com.js +0 -296
  263. package/core/com/msg/com.json +0 -4
  264. package/core/com/nav/com.json +0 -4
  265. package/core/com/nav/config.tpl.json +0 -75
  266. package/core/com/nav/drive.js +0 -549
  267. package/core/com/nav/index.js +0 -182
  268. package/core/com/nav/tpl/admin_pc/page_form.vue +0 -180
  269. package/core/com/nav/tpl/admin_pc/page_view.vue +0 -124
  270. package/core/com/nav/tpl/dev_pc/page_default.vue +0 -247
  271. package/core/com/nav/tpl/dev_pc/page_type.vue +0 -313
  272. package/core/com/nav/tpl/home_pc/page_default.vue +0 -234
  273. package/core/com/nav/tpl/home_pc/page_form.vue +0 -137
  274. package/core/com/nav/tpl/home_pc/page_list.vue +0 -234
  275. package/core/com/nav/tpl/home_pc/page_nav.vue +0 -221
  276. package/core/com/nav/tpl/home_pc/page_type.vue +0 -234
  277. package/core/com/nav/tpl/home_pc/page_view.vue +0 -125
  278. package/core/com/nav/tpl/home_phone/page_channel.vue +0 -234
  279. package/core/com/nav/tpl/home_phone/page_default.vue +0 -234
  280. package/core/com/nav/tpl/home_phone/page_form.vue +0 -137
  281. package/core/com/nav/tpl/home_phone/page_nav.vue +0 -237
  282. package/core/com/nav/tpl/home_phone/page_type.vue +0 -234
  283. package/core/com/nav/tpl/home_phone/page_view.vue +0 -125
  284. package/core/com/nav/viewmodel.js +0 -296
  285. package/core/com/param/drive.js +0 -366
  286. package/core/com/param/index.js +0 -80
  287. package/core/com/param/script.js +0 -12
  288. package/core/com/param/test.js +0 -98
  289. package/core/com/plugin/README.md +0 -3
  290. package/core/com/plugin/com.json +0 -4
  291. package/core/com/plugin/config.tpl.json +0 -26
  292. package/core/com/plugin/drive.js +0 -536
  293. package/core/com/plugin/index.js +0 -259
  294. package/core/com/plugin/script.js +0 -213
  295. package/core/com/rpc/com.json +0 -4
  296. package/core/com/rpc/drive.js +0 -160
  297. package/core/com/rpc/index.js +0 -87
  298. package/core/com/rpc/rpc.js +0 -118
  299. package/core/com/socket/com.json +0 -4
  300. package/core/com/socket/config.tpl.json +0 -14
  301. package/core/com/socket/drive.js +0 -403
  302. package/core/com/socket/index.js +0 -62
  303. package/core/com/socket/script.js +0 -42
  304. package/core/com/sql/drive.js +0 -1087
  305. package/core/com/sql/index.js +0 -83
  306. package/core/com/sql/script.js +0 -48
  307. package/core/com/static/com.json +0 -4
  308. package/core/com/static/drive.js +0 -220
  309. package/core/com/static/index.js +0 -149
  310. package/core/com/static/script.js +0 -28
  311. package/core/com/task/com.json +0 -4
  312. package/core/com/task/drive.js +0 -403
  313. package/core/com/task/index.js +0 -110
  314. package/core/com/task/script.js +0 -37
  315. package/core/com/timer/com.js +0 -217
  316. package/core/com/timer/com.json +0 -4
  317. package/core/com/tpl/com.js +0 -19
  318. package/core/com/tpl/com.json +0 -4
  319. package/lib/actions.js +0 -50
  320. package/lib/base.js +0 -361
  321. package/lib/com.js +0 -29
  322. package/lib/ref.js +0 -121
  323. package/middleware/mqtt_base/index.js +0 -10
  324. package/middleware/mqtt_base/middleware.json +0 -10
  325. package/middleware/performance/index.js +0 -151
  326. package/middleware/performance/middleware.json +0 -16
  327. package/middleware/security_audit/index.js +0 -549
  328. package/middleware/security_audit/middleware.json +0 -48
  329. package/middleware/security_headers/index.js +0 -487
  330. package/middleware/security_headers/middleware.json +0 -45
  331. package/middleware/waf/index.js +0 -348
  332. package/middleware/waf/middleware.json +0 -10
  333. package/middleware/waf_ddos/index.js +0 -520
  334. package/middleware/waf_ddos/middleware.json +0 -38
  335. package/middleware/waf_ip/index.js +0 -379
  336. package/middleware/waf_ip/middleware.json +0 -49
  337. package/middleware/waf_xss/index.js +0 -269
  338. package/middleware/waf_xss/middleware.json +0 -18
  339. package/middleware/web_after/index.js +0 -33
  340. package/middleware/web_after/middleware.json +0 -9
  341. package/middleware/web_base/index.js +0 -90
  342. package/middleware/web_base/middleware.json +0 -9
  343. package/middleware/web_before/index.js +0 -27
  344. package/middleware/web_before/middleware.json +0 -9
  345. package/middleware/web_check/index.js +0 -28
  346. package/middleware/web_check/middleware.json +0 -9
  347. package/middleware/web_main/index.js +0 -28
  348. package/middleware/web_main/middleware.json +0 -9
  349. package/middleware/web_proxy/index.js +0 -37
  350. package/middleware/web_proxy/middleware.json +0 -9
  351. package/middleware/web_render/index.js +0 -87
  352. package/middleware/web_render/middleware.json +0 -9
  353. package/middleware/web_socket/index.js +0 -34
  354. package/middleware/web_socket/middleware.json +0 -9
  355. package/middleware/web_static/index.js +0 -115
  356. package/middleware/web_static/middleware.json +0 -9
  357. /package/{core/com → com}/api/README.md +0 -0
  358. /package/{core/com → com}/db/README.md +0 -0
  359. /package/{core/com → com}/event/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,513 +0,0 @@
1
- const Item = require('mm_machine').Item;
2
-
3
- /**
4
- * 指令驱动类
5
- * @extends {Item}
6
- * @class
7
- */
8
- class Drive extends Item {
9
- /**
10
- * 构造函数
11
- * @param {String} dir 当前目录
12
- * @constructor
13
- */
14
- constructor(dir) {
15
- super(dir, __dirname);
16
- this.default_file = "./cmd.json";
17
- // 默认启用热更新
18
- this.mode = 3;
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
- // 时态, 分before之前、main主要、after之后三个时态,
34
- "tense": "main",
35
- // 加载顺序,数字越大越后面加载
36
- "sort": 1000,
37
- // 结束会话 当值为1时,指令触发并返回了内容后不再执行其他指令。为0时,指令触发仍继续执行其他指令
38
- "end": 1,
39
- // 分组
40
- "group": "default",
41
- // 类型: query便民查询,action执行,game游戏,orther其他,为空表示未分类
42
- "type": "",
43
- // 匹配关键词
44
- "match": [],
45
- // 不含关键词
46
- "not_match": [],
47
- // 去除关键词
48
- "remove": [],
49
- // 摘取
50
- "extract": [],
51
- // 阶段
52
- "stage": [
53
- // 第一阶段
54
- {
55
- // 方式
56
- "mode": "fill",
57
- // 验证参数集
58
- "param": [
59
- // {
60
- // // 参数名
61
- // "name": "name",
62
- // // 参数介绍名
63
- // "title": "名称",
64
- // // 参数格式
65
- // "format": "",
66
- // // 缺少参数提示语,传键值对,例如:{ number: "快递单号多少?" }
67
- // "not_tip": "",
68
- // // 错误提示
69
- // "error_tip": "",
70
- // // 监听语法
71
- // "listen": "",
72
- // // 校验函数明
73
- // "func_name": ""
74
- // },
75
- ]
76
- },
77
- // 第二阶段
78
- {
79
- // 方式
80
- "mode": "update",
81
- // 验证参数集
82
- "param": []
83
- },
84
- // 第三阶段
85
- {
86
- // 方式
87
- "mode": "fill",
88
- // 验证参数集
89
- "param": []
90
- }
91
- ]
92
- }
93
- }
94
- };
95
-
96
-
97
- /**
98
- * 创建一个参数模型
99
- */
100
- Drive.prototype.model = function() {
101
- return {
102
- // 参数名
103
- "name": "name",
104
- // 参数介绍名
105
- "title": "名称",
106
- // 排序
107
- "sort": 10,
108
- // 监听语法
109
- "listen": "",
110
- // 参数格式
111
- "format": "",
112
- // 缺少参数提示语
113
- "not_tip": "",
114
- // 更新提示
115
- "update_tip": "",
116
- // 错误提示
117
- "error_tip": ""
118
- };
119
- };
120
-
121
- /**
122
- * 校验是否匹配指令
123
- * @param {Object} content 请求的正文
124
- * @param {Object} db 数据管理器
125
- * @return {Boolean} 匹配返回true,不匹配返回false
126
- */
127
- Drive.prototype.match = function(content, db) {
128
- var word;
129
- var arr = this.config.match;
130
- for (var i = 0; i < arr.length; i++) {
131
- var format = arr[i];
132
- var str = content.matchs(format);
133
- if (str) {
134
- word = str;
135
- break;
136
- }
137
- }
138
- return word;
139
- };
140
-
141
- /**
142
- * 校验是否不含关键词
143
- * @param {Object} content 请求的正文
144
- * @param {Object} db 数据管理器
145
- * @return {Boolean} 不含返回true,含有返回false
146
- */
147
- Drive.prototype.not_match = function(content, db) {
148
- var bl = true;
149
- var arr = this.config.not_match;
150
- for (var i = 0; i < arr.length; i++) {
151
- var format = arr[i];
152
- if (content.matchs(format)) {
153
- bl = false;
154
- break;
155
- }
156
- }
157
- return bl;
158
- };
159
-
160
-
161
- /**
162
- * 抽取主要内容
163
- * @param {String} content 正文
164
- * @param {Object} db 数据管理器
165
- * @return {Object} 返回过滤后的参数
166
- */
167
- Drive.prototype.extract = async function(content, db) {
168
- var list = this.config.extract;
169
- if (!list.length) {
170
- return content
171
- }
172
- for (var i = 0; i < list.length; i++) {
173
- var format = list[i];
174
- var ret = content.matchs(format);
175
- if (ret) {
176
- content = ret;
177
- }
178
- }
179
- return content;
180
- };
181
-
182
- /**
183
- * 移除关键词
184
- * @param {Array} content 内容
185
- * @param {Object} db 数据管理器
186
- * @return {Object} 返回过滤后的参数
187
- */
188
- Drive.prototype.remove = async function(content, db) {
189
- var list = this.config.remove;
190
- for (var i = 0; i < list.length; i++) {
191
- var format = list[i];
192
- if (format.indexOf("/") === 0) {
193
- var fmt = format.replace(/\//g, '\\/').replace(/\r/g, '\\r').replace(/\n/g, '\\n')
194
- .replace(/\*/g, '.*').replace(
195
- /\{[a-zA-Z\u4e00-\u9fa5_]+\}/g, '[\\s\\S]*');
196
- var rx = eval(fmt);
197
- content = content.replace(rx, "").trim();
198
- } else {
199
- content = content.replace(format, "").trim();
200
- }
201
- }
202
- return content;
203
- };
204
-
205
- /**
206
- * 修改提示
207
- * @param {Object} msg 消息上下文
208
- * @param {Object} db 数据管理器
209
- * @return {Object} 返回过滤后的参数
210
- */
211
- Drive.prototype.view_tip = async function(msg, db, tip) {
212
- var form = this.view(msg, db);
213
- tip = tip.replace("{form}", form);
214
- return tip;
215
- };
216
-
217
- /**
218
- * 1. 检验阶段, 判断条件是否满足
219
- * @param {Object} msg 消息上下文
220
- * @param {Object} db 数据管理器
221
- * @return {String} 验证失败返回错误提示
222
- */
223
- Drive.prototype.check = async function(msg, db) {
224
- // 校验是否匹配指令
225
- var word = await this.match(msg.content, db);
226
- if (word) {
227
- var bl = await this.not_match(msg.content, db);
228
- if (!bl) {
229
- return
230
- }
231
- }
232
- return word;
233
- };
234
-
235
- /**
236
- * 2. 过滤阶段, 抽出主要的内容
237
- * @param {Object} msg 消息上下文
238
- * @param {Object} db 数据管理器
239
- * @return {Object} 返回过滤后的参数
240
- */
241
- Drive.prototype.filter = async function(msg, db) {
242
- var content = await this.extract(msg.content);
243
- content = await this.remove(content);
244
- if (content) {
245
- msg.keyword = content;
246
- }
247
- return content;
248
- };
249
-
250
- /**
251
- * 3.1 信息补全阶段 用于通知用户补全执行的必要条件
252
- * @param {Object} msg 消息上下文
253
- * @param {Object} db 数据管理器
254
- * @param {Object} stage 阶段参数
255
- * @return {Object} 返回参数表单
256
- */
257
- Drive.prototype.fill = async function(msg, db, stage) {
258
- if (!stage) {
259
- return "";
260
- }
261
- var list = stage.param;
262
- if (!list || list.length === 0) {
263
- return "";
264
- }
265
- var keyword = "";
266
- var tip = "";
267
-
268
- // 获取已有参数
269
- var form = {};
270
- if (msg.form) {
271
- form = msg.form.toJson();
272
- }
273
- // 补全内容
274
- var ct = msg.content_last || "";
275
- var len = list.length;
276
- for (var i = 0; i < len; i++) {
277
- var o = list[i];
278
- var k = o.name;
279
- if (!form[k]) {
280
- if (ct) {
281
- var value = ct;
282
- if (o.format) {
283
- value = value.matchs(o.format);
284
- }
285
- if (value) {
286
- form[k] = value;
287
- } else if (o.error_tip) {
288
- tip = await this.view_tip(msg, db, o.error_tip);
289
- break;
290
- } else if (o.not_tip) {
291
- tip = await this.view_tip(msg, db, o.not_tip);
292
- break;
293
- }
294
- ct = "";
295
- } else {
296
- keyword = k;
297
- tip = await this.view_tip(msg, db, o.not_tip);
298
- break;
299
- }
300
- }
301
- }
302
- msg.form = JSON.stringify(form);
303
- db.form = form;
304
- return tip;
305
- };
306
-
307
- /**
308
- * 3.2 更新信息 用于用户更改完善
309
- * @param {Object} msg 消息上下文
310
- * @param {Object} db 数据管理器
311
- * @param {Object} stage 阶段参数
312
- * @return {Object} 返回参数表单
313
- */
314
- Drive.prototype.update = async function(msg, db, stage) {
315
- if (!stage) {
316
- return "";
317
- }
318
- var list = stage.param;
319
- if (!list || list.length === 0) {
320
- return "";
321
- }
322
- var tip = "";
323
-
324
- // 获取已有参数
325
- var form = {};
326
- if (msg.form) {
327
- form = msg.form.toJson();
328
- }
329
- // 补全内容
330
- var ct = msg.content_last || "";
331
- var form = msg.form.toJson();
332
- for (var i = 0; i < list.length; i++) {
333
- var o = list[i];
334
- var k = o.name;
335
- if (form[k]) {
336
- var value = ct.matchs(o.listen);
337
- if (value) {
338
- if (o.update_tip) {
339
- tip = o.update_tip;
340
- } else {
341
- tip = "那" + value.replace(value.matchs("{不对}"), '是?');
342
- }
343
- msg.note = k;
344
- break;
345
- } else if (msg.note == k && o.format) {
346
- value = ct.matchs(o.format);
347
- if (value) {
348
- form[k] = value;
349
- ct = ct.replace(value, '');
350
- break;
351
- }
352
- }
353
- }
354
- }
355
- msg.form = JSON.stringify(form);
356
- db.form = form;
357
- return tip;
358
- };
359
-
360
- /**
361
- * 4. 执行阶段
362
- * @param {Object} msg 消息上下文
363
- * @param {Object} db 数据管理器
364
- * @return {Object} 返回执行结果
365
- */
366
- Drive.prototype.main = async function(msg, db) {
367
- return "你好";
368
- };
369
-
370
- /**
371
- * 5. 结束阶段 用来判断是否结束会话
372
- * @param {Object} msg 消息上下文
373
- * @param {Object} db 数据管理器
374
- * @param {Object} ret 执行结果
375
- * @return {Boolean} 返回会话结果
376
- */
377
- Drive.prototype.end = async function(msg, db, ret) {
378
- if (ret) {
379
- var txt = "";
380
- if (typeof(ret) == "object") {
381
- txt = JSON.stringify(ret);
382
- } else {
383
- txt = ret;
384
- }
385
- if (this.config.tense == "main") {
386
- if (txt.indexOf('?') === -1 && txt.indexOf('?') === -1) {
387
- msg.end = 0;
388
- }
389
- }
390
- }
391
- return ret;
392
- };
393
-
394
- /**
395
- * 执行前 用于有历史信息时,直接获取,不重复询问
396
- * @param {Object} msg 消息上下文
397
- * @param {Object} db 数据管理器
398
- * @return {Object} 执行结果, 如果有结果则直接跳过其他步骤,并返回
399
- */
400
- Drive.prototype.run_before = async function(msg, db) {
401
- return null;
402
- };
403
-
404
- /**
405
- * 执行后, 用于特殊情况下的不结束会话
406
- * @param {Object} msg 消息上下文
407
- * @param {Object} db 数据管理器
408
- * @param {Object} ret 执行结果
409
- * @return {Object}
410
- */
411
- Drive.prototype.run_after = async function(msg, db, ret) {
412
- return ret;
413
- };
414
-
415
- /**
416
- * 执行
417
- * @param {Object} param 状态参数
418
- * @param {Object} db 数据管理器
419
- * @return {Object} 返回执行结果
420
- */
421
- Drive.prototype.run = async function(msg, db) {
422
- var ret;
423
- try {
424
- // 第一步, 验证阶段
425
- var match = await this.check(msg, db);
426
- if (!match) {
427
- return
428
- }
429
- msg.match = match.substring(0, 255);
430
- // 第二步, 过滤阶段
431
- await this.filter(msg, db);
432
-
433
- // 执行前
434
- ret = await this.run_before(msg, db);
435
- if (!ret) {
436
- // 第三步, 信息补全或更新阶段
437
- var stages = this.config.stage;
438
- if (stages.length >= msg.stage) {
439
- var stage = stages[msg.stage - 1];
440
- if (stage) {
441
- var mode = stage.mode ? stage.mode : "fill";
442
- if (this[mode]) {
443
- ret = await this[mode](msg, db, stage);
444
- }
445
- }
446
- }
447
-
448
- if (!ret) {
449
- // 第五步, 执行阶段
450
- ret = await this.main(msg, db);
451
-
452
- // 第六步, 结束会话阶段
453
- ret = this.end(msg, db, ret);
454
- }
455
- }
456
- // 执行后
457
- ret = await this.run_after(msg, db, ret);
458
- } catch (error) {
459
- $.log.error("指令执行失败!", this.config.name, error);
460
- }
461
- return ret;
462
- };
463
-
464
- /**
465
- * 查看参数
466
- * @param {Object} param 状态参数
467
- * @param {Object} db 数据管理器
468
- * @return {Object} 返回结构化参数
469
- */
470
- Drive.prototype.view = function(msg, db) {
471
- var ret = "";
472
- if (msg.form) {
473
- var json = msg.form.toJson();
474
- var stage = this.config.stage;
475
- if (stage && stage.length >= msg.stage) {
476
- var list = stage[msg.stage - 1].param;
477
- if (list) {
478
- for (var i = 0; i < list.length; i++) {
479
- var o = list[i];
480
- var value = json[o.name];
481
- if (value) {
482
- ret += o.title + ": " + value + "\r\n";
483
- }
484
- }
485
- }
486
- }
487
- }
488
- return ret.trim();
489
- };
490
-
491
- /**
492
- * 获取插件
493
- * @param {String} app 应用名称
494
- * @param {String} name 插件名称
495
- * @returns {Object} 返回获取到的插件
496
- */
497
- Drive.prototype.plugin = function(app, name) {
498
- var plus;
499
- var l = $.slash;
500
- if (!app) {
501
- app = this.filename.between("app" + l, l);
502
- }
503
- if (!name) {
504
- name = this.filename.between("plugin" + l, l);
505
- }
506
- var plugins = $.pool.plugin[app];
507
- if (plugins) {
508
- plus = plugins.get(name);
509
- }
510
- return plus
511
- }
512
-
513
- module.exports = Drive;