@indra.ai/deva 1.2.20 â 1.2.22
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.
- package/config.json +141 -135
- package/index.js +122 -87
- package/package.json +1 -1
package/config.json
CHANGED
|
@@ -30,169 +30,175 @@
|
|
|
30
30
|
"context": false,
|
|
31
31
|
"zone": "deva",
|
|
32
32
|
"zones": {
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"music": "Music",
|
|
54
|
-
"fun": "Fun",
|
|
55
|
-
"party": "Party",
|
|
56
|
-
"adventure": "Adventure",
|
|
57
|
-
"cartoon": "Cartoon",
|
|
58
|
-
"mystery": "Mystery",
|
|
59
|
-
"fantasy": "Fantasy",
|
|
60
|
-
"romance": "Romance",
|
|
61
|
-
"comedy": "Comedy",
|
|
62
|
-
"drama": "Drama",
|
|
63
|
-
"scifi": "SciFi",
|
|
64
|
-
"help": "Help",
|
|
65
|
-
"error": "ERROR!"
|
|
33
|
+
"load": "đ Load",
|
|
34
|
+
"unload": "đģ Unload",
|
|
35
|
+
"init": "đ Initialize",
|
|
36
|
+
"start": "đī¸ Start",
|
|
37
|
+
"stop": "đ Stop",
|
|
38
|
+
"enter": "đĄ Enter",
|
|
39
|
+
"exit": "đĒ Exit",
|
|
40
|
+
"finish": "đ Finish",
|
|
41
|
+
"done": "â
Done",
|
|
42
|
+
"question": "đââī¸ Question",
|
|
43
|
+
"ask": "đĸ Ask",
|
|
44
|
+
"answer": "đââī¸ Answer",
|
|
45
|
+
"deva": "đ§ââī¸ Deva",
|
|
46
|
+
"client": "đ¨âđŧ Client",
|
|
47
|
+
"agent": "đ¤ Agent",
|
|
48
|
+
"security": "đ Security",
|
|
49
|
+
"support": "đŧ Support",
|
|
50
|
+
"services": "đ ī¸ Services",
|
|
51
|
+
"help": "đ Help",
|
|
52
|
+
"error": "â ERROR!"
|
|
66
53
|
},
|
|
67
54
|
"state": "offline",
|
|
68
55
|
"states": {
|
|
69
|
-
"online": "Online",
|
|
70
|
-
"offline": "Offline",
|
|
71
|
-
"active": "Active",
|
|
72
|
-
"inactive": "Inactive",
|
|
73
|
-
"idle": "Idle",
|
|
74
|
-
"talk": "Talk",
|
|
75
|
-
"listen": "Listen",
|
|
76
|
-
"ask": "Ask",
|
|
77
|
-
"question": "Question",
|
|
78
|
-
"cmd": "Command",
|
|
79
|
-
"answer": "Answer",
|
|
80
|
-
"ready": "Ready",
|
|
81
|
-
"wait": "Waiting",
|
|
82
|
-
"pause": "Pause",
|
|
83
|
-
"resume": "Resume",
|
|
84
|
-
"connect": "Connect",
|
|
85
|
-
"disconnect": "Disconnect",
|
|
86
|
-
"send": "Send",
|
|
87
|
-
"receive": "Receive",
|
|
88
|
-
"init": "Initialize",
|
|
89
|
-
"forward": "Forward",
|
|
90
|
-
"backward": "Backward",
|
|
91
|
-
"start": "Start",
|
|
92
|
-
"stop": "Stop",
|
|
93
|
-
"open": "Open",
|
|
94
|
-
"close": "Close",
|
|
95
|
-
"enter": "Enter",
|
|
96
|
-
"exit": "Exit",
|
|
97
|
-
"begin": "Begin",
|
|
98
|
-
"end": "End",
|
|
99
|
-
"load": "Load",
|
|
100
|
-
"unload": "Unload",
|
|
101
|
-
"resolve": "Resolve",
|
|
102
|
-
"reject": "Reject",
|
|
103
|
-
"done": "Done",
|
|
104
|
-
"data": "Data",
|
|
105
|
-
"finish": "Finish",
|
|
106
|
-
"complete": "Complete",
|
|
107
|
-
"create": "Create",
|
|
108
|
-
"destroy": "Destroy",
|
|
109
|
-
"
|
|
110
|
-
"
|
|
111
|
-
"
|
|
112
|
-
"
|
|
113
|
-
"
|
|
114
|
-
"
|
|
115
|
-
"
|
|
116
|
-
"
|
|
117
|
-
"
|
|
118
|
-
"
|
|
119
|
-
"
|
|
120
|
-
"
|
|
56
|
+
"online": "𤊠Online",
|
|
57
|
+
"offline": "đ´ Offline",
|
|
58
|
+
"active": "đ Active",
|
|
59
|
+
"inactive": "đĢĨ Inactive",
|
|
60
|
+
"idle": "đ Idle",
|
|
61
|
+
"talk": "đĸ Talk",
|
|
62
|
+
"listen": "đ Listen",
|
|
63
|
+
"ask": "đŖī¸ Ask",
|
|
64
|
+
"question": "đŦ Question",
|
|
65
|
+
"cmd": "đĒ Command",
|
|
66
|
+
"answer": "đĄ Answer",
|
|
67
|
+
"ready": "đ Ready",
|
|
68
|
+
"wait": "âŗ Waiting",
|
|
69
|
+
"pause": "â¸ī¸ Pause",
|
|
70
|
+
"resume": "đ Resume",
|
|
71
|
+
"connect": "đŗ Connect",
|
|
72
|
+
"disconnect": "đ´ Disconnect",
|
|
73
|
+
"send": "đŦ Send",
|
|
74
|
+
"receive": "đĒ Receive",
|
|
75
|
+
"init": "đ Initialize",
|
|
76
|
+
"forward": "âī¸ Forward",
|
|
77
|
+
"backward": "âŽī¸ Backward",
|
|
78
|
+
"start": "đ Start",
|
|
79
|
+
"stop": "âšī¸ Stop",
|
|
80
|
+
"open": "đĨĢ Open",
|
|
81
|
+
"close": "đĻ Close",
|
|
82
|
+
"enter": "đĄ Enter",
|
|
83
|
+
"exit": "đĒ Exit",
|
|
84
|
+
"begin": "đēī¸ Begin",
|
|
85
|
+
"end": "đŦ End",
|
|
86
|
+
"load": "đ Load",
|
|
87
|
+
"unload": "đģ Unload",
|
|
88
|
+
"resolve": "đŦ Resolve",
|
|
89
|
+
"reject": "đ§ą Reject",
|
|
90
|
+
"done": "â
Done",
|
|
91
|
+
"data": "đĄ Data",
|
|
92
|
+
"finish": "đ Finish",
|
|
93
|
+
"complete": "âī¸ Complete",
|
|
94
|
+
"create": "đ¨ Create",
|
|
95
|
+
"destroy": "đŖ Destroy",
|
|
96
|
+
"write": "đ Write",
|
|
97
|
+
"save": "đž Save",
|
|
98
|
+
"delete": "𧨠Delete",
|
|
99
|
+
"set": "đ Set",
|
|
100
|
+
"get": "đ Get",
|
|
101
|
+
"put": "đ¤ Put",
|
|
102
|
+
"push": "đ̏ Push",
|
|
103
|
+
"pull": "đ Pull",
|
|
104
|
+
"search": "đ Search",
|
|
105
|
+
"memory": "đ Memory",
|
|
106
|
+
"response": "âī¸ Response",
|
|
107
|
+
"invalid": "đ INVALID!",
|
|
108
|
+
"valid": "đ VALID!",
|
|
109
|
+
"abort": "đ ABORT!",
|
|
110
|
+
"error": "â ERROR!",
|
|
111
|
+
"help": "đ Help"
|
|
121
112
|
},
|
|
122
113
|
"action": false,
|
|
123
114
|
"actions": {
|
|
124
|
-
"client": "
|
|
125
|
-
"agent": "
|
|
126
|
-
"wait": "Waiting",
|
|
127
|
-
"start": "Start",
|
|
128
|
-
"enter": "Enter",
|
|
129
|
-
"exit": "Exit",
|
|
130
|
-
"stop": "Stop",
|
|
131
|
-
"load": "Load",
|
|
132
|
-
"unload": "Unload",
|
|
133
|
-
"done": "Done",
|
|
134
|
-
"question": "Question",
|
|
115
|
+
"client": "đ¨âđŧ Client",
|
|
116
|
+
"agent": "đĩī¸ââī¸ Agent",
|
|
117
|
+
"wait": "âŗ Waiting",
|
|
118
|
+
"start": "đŦ Start",
|
|
119
|
+
"enter": "đĄ Enter",
|
|
120
|
+
"exit": "đĒ Exit",
|
|
121
|
+
"stop": "đ Stop",
|
|
122
|
+
"load": "đĻ Load",
|
|
123
|
+
"unload": "đĨĄ Unload",
|
|
124
|
+
"done": "â
Done",
|
|
125
|
+
"question": "đ Question",
|
|
135
126
|
"context": "Context",
|
|
136
|
-
"prompt": "Prompt",
|
|
137
|
-
"issue": "Issue",
|
|
138
|
-
"find": "Find",
|
|
139
|
-
"parse": "Parse",
|
|
140
|
-
"view": "View",
|
|
141
|
-
"insert": "Insert",
|
|
142
|
-
"update": "Update",
|
|
143
|
-
"delete": "Delete",
|
|
144
|
-
"info": "Information",
|
|
145
|
-
"status": "Status",
|
|
146
|
-
"func": "Function",
|
|
147
|
-
"
|
|
148
|
-
"
|
|
149
|
-
"
|
|
150
|
-
"
|
|
151
|
-
"
|
|
127
|
+
"prompt": "đ Prompt",
|
|
128
|
+
"issue": "đĢ Issue",
|
|
129
|
+
"find": "đ Find",
|
|
130
|
+
"parse": "đī¸ Parse",
|
|
131
|
+
"view": "đ View",
|
|
132
|
+
"insert": "đ Insert",
|
|
133
|
+
"update": "đ Update",
|
|
134
|
+
"delete": "đī¸ Delete",
|
|
135
|
+
"info": "đââī¸ Information",
|
|
136
|
+
"status": "đĨ Status",
|
|
137
|
+
"func": "đĻ Function",
|
|
138
|
+
"method": "âĄī¸ Method",
|
|
139
|
+
"list": "đ List items",
|
|
140
|
+
"reply": "đŽ Reply",
|
|
141
|
+
"write": "ī¸đ Write",
|
|
142
|
+
"set": "đŊī¸ Set",
|
|
143
|
+
"get": "đ¤ Get",
|
|
144
|
+
"return": "đ Return",
|
|
145
|
+
"resolve": "âĩī¸ Resolve",
|
|
146
|
+
"reject": "â Reject",
|
|
152
147
|
|
|
153
|
-
"question_ask": "
|
|
154
|
-
"question_ask_answer": "
|
|
155
|
-
"question_cmd": "
|
|
156
|
-
"
|
|
157
|
-
"question_talk": "Question talk",
|
|
158
|
-
"question_answer": "Answer question",
|
|
159
|
-
"question_done": "Question done",
|
|
148
|
+
"question_ask": "đŖī¸ Asked",
|
|
149
|
+
"question_ask_answer": "đī¸ Answered",
|
|
150
|
+
"question_cmd": "đĒ Command",
|
|
151
|
+
"question_answer": "đ Answer",
|
|
160
152
|
|
|
161
|
-
"answer": "Answer",
|
|
162
|
-
"ask": "Ask",
|
|
153
|
+
"answer": "đĄ Answer",
|
|
154
|
+
"ask": "đŖ Ask",
|
|
163
155
|
|
|
164
156
|
"security": "Get Security",
|
|
165
157
|
"support": "Get Support",
|
|
166
158
|
"services": "Get Services",
|
|
167
159
|
|
|
168
|
-
"Client": "Set
|
|
160
|
+
"Client": "Set Client",
|
|
169
161
|
"Security": "Set Security",
|
|
170
162
|
"Support": "Set Support",
|
|
171
163
|
"Systems": "Set Systems",
|
|
172
164
|
"Services": "Set Services",
|
|
173
|
-
"Done": "Done",
|
|
165
|
+
"Done": "â
Done",
|
|
174
166
|
|
|
175
|
-
"invalid": "Invalid",
|
|
176
|
-
"states": "States",
|
|
177
|
-
"actions": "Actions",
|
|
167
|
+
"invalid": "â Invalid",
|
|
168
|
+
"states": "đģ States",
|
|
169
|
+
"actions": "đī¸ Actions",
|
|
178
170
|
"zones": "Zones",
|
|
179
|
-
"
|
|
180
|
-
"
|
|
181
|
-
"
|
|
182
|
-
"
|
|
183
|
-
"
|
|
171
|
+
"feature": "đĨ Feature",
|
|
172
|
+
"features": "đĨ Getting features",
|
|
173
|
+
"contexts": "đ Getting contexts",
|
|
174
|
+
"finish": "đ Finish",
|
|
175
|
+
"help": "đ Help",
|
|
176
|
+
"error": "đ´ ERROR!"
|
|
184
177
|
},
|
|
185
178
|
"feature": false,
|
|
186
179
|
"features": {
|
|
187
|
-
"security": "Security",
|
|
188
|
-
"support": "Support",
|
|
189
|
-
"services": "Services",
|
|
190
|
-
"
|
|
180
|
+
"security": "đ Security",
|
|
181
|
+
"support": "đŧ Support",
|
|
182
|
+
"services": "đ ī¸ Services",
|
|
183
|
+
"cipher": "đ Cipher",
|
|
184
|
+
"decipher": "đ Decipher",
|
|
185
|
+
"promp": "đĒĩ Prompt",
|
|
186
|
+
"getToday": "đ Get Today",
|
|
187
|
+
"formatDate": "đ
Date",
|
|
188
|
+
"formatTime": "đ°ī¸ Time",
|
|
189
|
+
"formatCurrency": "đ° Currency",
|
|
190
|
+
"formatPercent": "đ¯ Percent",
|
|
191
|
+
"trimWords": "đ Trim Words",
|
|
192
|
+
"dupes": "đ Duplicates",
|
|
193
|
+
"info": "đââī¸ Info",
|
|
194
|
+
"status": "â¤ī¸ Status",
|
|
195
|
+
"help": "đ Help"
|
|
191
196
|
},
|
|
192
197
|
"message": "offline",
|
|
193
198
|
"messages": {
|
|
194
199
|
"init": "Initializing Deva",
|
|
195
200
|
"offline": "The Deva is OFFLINE.",
|
|
201
|
+
"noid": "NO ID WAS PROVIDED",
|
|
196
202
|
"notext": "NO TEXT WAS PROVIDED",
|
|
197
203
|
"nopacket": "NO PACKET WAS PROVIDED",
|
|
198
204
|
"method_not_found": "METHOD NOT FOUND",
|
package/index.js
CHANGED
|
@@ -215,11 +215,12 @@ class Deva {
|
|
|
215
215
|
***************/
|
|
216
216
|
Security() {
|
|
217
217
|
this.zone('security');
|
|
218
|
+
this.action('Security'); // set action to Security
|
|
218
219
|
const _cl = this.client(); // set local copy of client data
|
|
219
220
|
try {
|
|
220
221
|
if (!_cl.features.security) return this.Support(); // if no security feature goto Support
|
|
221
222
|
else {
|
|
222
|
-
this.state('
|
|
223
|
+
this.state('set', 'Security');
|
|
223
224
|
const {id, profile, features} = _cl; // make a copy the clinet data.
|
|
224
225
|
const {security} = features; // make a copy the clinet data.
|
|
225
226
|
this._security = { // set this_security with data
|
|
@@ -233,10 +234,11 @@ class Deva {
|
|
|
233
234
|
personal: security.devas[this._agent.key], // Client personal features and rules.
|
|
234
235
|
};
|
|
235
236
|
delete this._client.features.security; // make a copy the clinet data.
|
|
236
|
-
this.
|
|
237
|
+
this.state('resolve', 'Support');
|
|
237
238
|
return this.Support(); // goto Support when done with Security
|
|
238
239
|
}
|
|
239
240
|
} catch (e) {
|
|
241
|
+
this.state('reject', 'Support');
|
|
240
242
|
return this.error(e); // run error handling if an error is caught
|
|
241
243
|
}
|
|
242
244
|
}
|
|
@@ -250,11 +252,12 @@ class Deva {
|
|
|
250
252
|
***************/
|
|
251
253
|
Support() {
|
|
252
254
|
this.zone('support');
|
|
255
|
+
this.action('Support');
|
|
253
256
|
const _cl = this.client(); // set the local client variable
|
|
254
257
|
try {
|
|
255
258
|
if (!_cl.features.support) return this.Services() // move to Services if no support feature
|
|
256
259
|
else {
|
|
257
|
-
this.state('
|
|
260
|
+
this.state('set', 'Support');
|
|
258
261
|
const {id, features, profile} = _cl; // set the local consts from client copy
|
|
259
262
|
const {support} = features; // set support from features const
|
|
260
263
|
this._support = { // set this_support with data
|
|
@@ -266,10 +269,11 @@ class Deva {
|
|
|
266
269
|
personal: support.devas[this._agent.key], // Client personalSecurity features and rules.
|
|
267
270
|
};
|
|
268
271
|
delete this._client.features.support; // delete the support key from the client
|
|
269
|
-
this.
|
|
272
|
+
this.state('resolve', 'Services');
|
|
270
273
|
return this.Services(); // when done move to Services
|
|
271
274
|
}
|
|
272
275
|
} catch (e) {
|
|
276
|
+
this.state('reject', 'Services');
|
|
273
277
|
return this.error(e); // run error handling if an error is caught
|
|
274
278
|
}
|
|
275
279
|
}
|
|
@@ -283,11 +287,12 @@ class Deva {
|
|
|
283
287
|
***************/
|
|
284
288
|
Services() {
|
|
285
289
|
this.zone('services')
|
|
290
|
+
this.action('Services');
|
|
286
291
|
const _cl = this.client(); // set local client
|
|
287
292
|
try {
|
|
288
293
|
if (!_cl.features.services) return this.Done(); // move to Done if no Services feature
|
|
289
294
|
else {
|
|
290
|
-
this.state('
|
|
295
|
+
this.state('set', 'Services');
|
|
291
296
|
const {id, features, profile} = _cl; // set the local consts from client copy
|
|
292
297
|
const {services} = features; // set services from features const
|
|
293
298
|
this._services = { // set this_services with data
|
|
@@ -299,10 +304,11 @@ class Deva {
|
|
|
299
304
|
personal: services.devas[this._agent.key], // Client personal features and rules.
|
|
300
305
|
};
|
|
301
306
|
delete this._client.features.services; // delete the services key for isolation
|
|
302
|
-
this.
|
|
307
|
+
this.state('resolve', 'Services');
|
|
303
308
|
return this.Done(); // go to Done
|
|
304
309
|
}
|
|
305
310
|
} catch (e) {
|
|
311
|
+
this.state('reject', 'Services');
|
|
306
312
|
return this.error(e); // run error handling if an error is caught
|
|
307
313
|
}
|
|
308
314
|
}
|
|
@@ -313,15 +319,15 @@ class Deva {
|
|
|
313
319
|
describe: The end of the workflow Client Feature Workflow
|
|
314
320
|
***************/
|
|
315
321
|
Done(client) {
|
|
316
|
-
this.state('done');
|
|
317
322
|
this.action('done');
|
|
318
323
|
return new Promise((resolve, reject) => {
|
|
319
324
|
try {
|
|
325
|
+
this.state('done');
|
|
320
326
|
delete this._client.features; // delete the features key when done.
|
|
321
|
-
this.state('
|
|
322
|
-
this.action('wait');
|
|
327
|
+
this.state('resolve', 'done');
|
|
323
328
|
return resolve(client); // resolve an empty pr
|
|
324
329
|
} catch (e) {
|
|
330
|
+
this.state('reject', 'done');
|
|
325
331
|
return this.error(e, false, reject);
|
|
326
332
|
}
|
|
327
333
|
});
|
|
@@ -389,9 +395,10 @@ class Deva {
|
|
|
389
395
|
question(TEXT=false, DATA=false) {
|
|
390
396
|
// check the active status
|
|
391
397
|
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
392
|
-
this.
|
|
398
|
+
this.action('question');
|
|
393
399
|
const id = this.uid(); // generate a unique id for transport.
|
|
394
400
|
const t_split = TEXT.split(' '); // split the text on spaces to get words.
|
|
401
|
+
const data = DATA; // set the DATA to data
|
|
395
402
|
|
|
396
403
|
// check to see if the string is an #ask string to talk to the other Deva.
|
|
397
404
|
const isAsk = t_split[0].startsWith(this.askChr);
|
|
@@ -400,7 +407,6 @@ class Deva {
|
|
|
400
407
|
const isCmd = t_split[0].startsWith(this.cmdChr);
|
|
401
408
|
|
|
402
409
|
// Format the packet for return on the request.
|
|
403
|
-
const data = DATA; // set the DATA to data
|
|
404
410
|
const packet = { // create the base q/a packet
|
|
405
411
|
id, // set the id into packet
|
|
406
412
|
q: false, // create empty q object in packet
|
|
@@ -416,64 +422,61 @@ class Deva {
|
|
|
416
422
|
return new Promise((resolve, reject) => {
|
|
417
423
|
// resolve with the no text message if the client says nothing.
|
|
418
424
|
if (!TEXT) return this.finish(this._messages.notext, resolve);
|
|
419
|
-
let _action = 'question'; // set the initial _action to question.
|
|
420
|
-
this.state('question'); // set the state to question
|
|
421
425
|
try { // try to answer the question
|
|
422
426
|
if (isAsk) { // determine if hte question isAsk
|
|
423
|
-
this.state('ask');
|
|
424
|
-
_action = 'question_ask';
|
|
425
427
|
// if:isAsk split the agent key and remove first command character
|
|
426
428
|
key = t_split[0].substring(1);
|
|
427
429
|
//if:isAsk use text split index 1 as the parameter block
|
|
428
430
|
params = t_split[1] ? t_split[1].split(':') : false;
|
|
429
431
|
method = params[0]; // the method to check is then params index 0
|
|
430
432
|
text = t_split.slice(2).join(' ').trim(); // rejoin the text with space
|
|
433
|
+
this.state('ask', `${key} ${method}`);
|
|
431
434
|
}
|
|
432
435
|
else if (isCmd) { // determine if the question is a command
|
|
433
|
-
this.state('cmd'); // set the state to cmd.
|
|
434
|
-
_action = 'question_cmd';
|
|
435
436
|
//if:isCmd use text split index 1 as the parameter block
|
|
436
437
|
params = t_split[0] ? t_split[0].split(':').slice(1) : false;
|
|
437
438
|
method = t_split[0].substring(1); // if:isCmd use the 0 index as the command
|
|
438
439
|
text = t_split.slice(1).join(' ').trim(); // if:isCmd rejoin the string on the space after removing first index
|
|
440
|
+
this.state('cmd', method); // set the state to cmd.
|
|
439
441
|
}
|
|
440
442
|
|
|
441
|
-
this.state('
|
|
443
|
+
this.state('set', `question:${method}`)
|
|
442
444
|
packet.q = { // build packet.q container
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
445
|
+
id: this.uid(), // set the transport id for the question.
|
|
446
|
+
agent: this.agent(), // set the agent
|
|
447
|
+
client: this.client(), // set the client
|
|
448
|
+
meta: { // build the meta container
|
|
449
|
+
key, // set the key variable
|
|
450
|
+
method, // set method to track function use
|
|
451
|
+
params, // set any params that are associated
|
|
452
|
+
},
|
|
453
|
+
text, // set the text for the packet.
|
|
454
|
+
data, // set the data object
|
|
455
|
+
created: Date.now(), // timestamp the question
|
|
454
456
|
}
|
|
455
457
|
|
|
456
458
|
// hash the question
|
|
457
459
|
packet.q.meta.hash = this.hash(packet.q);
|
|
458
460
|
|
|
459
|
-
this.
|
|
461
|
+
this.state('talk', config.events.question); // set current action to what was defined by _action variable.
|
|
460
462
|
this.talk(config.events.question, this.copy(packet)); // global question event make sure to copy data.
|
|
461
463
|
|
|
462
464
|
if (isAsk) { // isAsk check if the question isAsk and talk
|
|
463
465
|
// if: isAsk wait for the once event which is key'd to the packet ID for specified responses
|
|
464
466
|
this.talk(`${key}:ask`, packet);
|
|
465
467
|
this.once(`${key}:ask:${packet.id}`, answer => {
|
|
466
|
-
this.
|
|
468
|
+
this.state('talk', config.events.ask);
|
|
467
469
|
this.talk(config.events.ask, this.copy(answer));
|
|
468
470
|
return this.finish(answer, resolve); // if:isAsk resolve the answer from the call
|
|
469
471
|
});
|
|
470
472
|
}
|
|
471
473
|
else { // else: answer tue question locally
|
|
472
|
-
this.
|
|
474
|
+
this.state('answer', `question:${method}`);
|
|
473
475
|
return this.answer(packet, resolve, reject);
|
|
474
476
|
}
|
|
475
477
|
}
|
|
476
478
|
catch(e) {
|
|
479
|
+
this.state('reject', 'question');
|
|
477
480
|
return this.error(e); // if a overall error happens this witll call this.error
|
|
478
481
|
}
|
|
479
482
|
});
|
|
@@ -491,7 +494,6 @@ class Deva {
|
|
|
491
494
|
***************/
|
|
492
495
|
answer(packet, resolve, reject) {
|
|
493
496
|
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
494
|
-
this.zone('answer');
|
|
495
497
|
const agent = this.agent();
|
|
496
498
|
const client = this.client();
|
|
497
499
|
// check if method exists and is of type function
|
|
@@ -501,8 +503,8 @@ class Deva {
|
|
|
501
503
|
return resolve(this._methodNotFound(packet)); // resolve method not found if check if check fails
|
|
502
504
|
}
|
|
503
505
|
// Call the local method to process the question based the extracted parameters
|
|
504
|
-
|
|
505
|
-
|
|
506
|
+
this.action('answer', method);
|
|
507
|
+
this.methods[method](packet).then(result => {
|
|
506
508
|
// check the result for the text, html, and data object.
|
|
507
509
|
// this is for when answers are returned from nested Devas.
|
|
508
510
|
const text = typeof result === 'object' ? result.text : result;
|
|
@@ -510,6 +512,7 @@ class Deva {
|
|
|
510
512
|
// if the data passed is NOT an object it will FALSE
|
|
511
513
|
const data = typeof result === 'object' ? result.data : false;
|
|
512
514
|
|
|
515
|
+
this.state('set', 'answer')
|
|
513
516
|
const packet_answer = { // setup the packet.a container
|
|
514
517
|
id: this.uid(),
|
|
515
518
|
agent, // set the agent who answered the question
|
|
@@ -528,10 +531,12 @@ class Deva {
|
|
|
528
531
|
// create a hash for the answer and insert into answer meta.
|
|
529
532
|
packet_answer.meta.hash = this.hash(packet_answer);
|
|
530
533
|
packet.a = packet_answer; // set the packet.a to the packet_answer
|
|
531
|
-
this.
|
|
534
|
+
this.state('talk', config.events.answer);
|
|
532
535
|
this.talk(config.events.answer, this.copy(packet)); // global talk event
|
|
536
|
+
this.state('resovle', 'answer')
|
|
533
537
|
return this.finish(packet, resolve); // resolve the packet to the caller.
|
|
534
538
|
}).catch(err => { // catch any errors in the method
|
|
539
|
+
this.state('reject', 'answer');
|
|
535
540
|
return this.error(err, packet, reject); // return this.error with err, packet, reject
|
|
536
541
|
});
|
|
537
542
|
}
|
|
@@ -553,8 +558,8 @@ class Deva {
|
|
|
553
558
|
***************/
|
|
554
559
|
ask(packet) {
|
|
555
560
|
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
556
|
-
|
|
557
|
-
this.
|
|
561
|
+
const {method, params} = packet.q.meta;
|
|
562
|
+
this.action('ask', method);
|
|
558
563
|
|
|
559
564
|
const agent = this.agent();
|
|
560
565
|
const client = this.client();
|
|
@@ -565,8 +570,8 @@ class Deva {
|
|
|
565
570
|
client,
|
|
566
571
|
meta: {
|
|
567
572
|
key: agent.key,
|
|
568
|
-
method
|
|
569
|
-
params
|
|
573
|
+
method,
|
|
574
|
+
params,
|
|
570
575
|
},
|
|
571
576
|
text: false,
|
|
572
577
|
html: false,
|
|
@@ -575,17 +580,16 @@ class Deva {
|
|
|
575
580
|
};
|
|
576
581
|
|
|
577
582
|
try {
|
|
578
|
-
if (typeof this.methods[
|
|
583
|
+
if (typeof this.methods[method] !== 'function') {
|
|
579
584
|
return setImmediate(() => {
|
|
580
|
-
this.
|
|
585
|
+
this.state('invalid', method);
|
|
581
586
|
this.talk(`${this._agent.key}:ask:${packet.id}`, this._methodNotFound(packet));
|
|
582
587
|
});
|
|
583
588
|
}
|
|
584
589
|
|
|
585
|
-
this.state('ask');
|
|
586
590
|
// The method is parsed and depending on what method is asked for it returns
|
|
587
591
|
// the response based on the passed through packet.
|
|
588
|
-
this.methods[
|
|
592
|
+
this.methods[method](packet).then(result => {
|
|
589
593
|
if (typeof result === 'object') {
|
|
590
594
|
packet_answer.text = result.text || false;
|
|
591
595
|
packet_answer.html = result.html || false;
|
|
@@ -594,9 +598,11 @@ class Deva {
|
|
|
594
598
|
else {
|
|
595
599
|
packet_answer.text = result;
|
|
596
600
|
}
|
|
601
|
+
|
|
602
|
+
this.state('set', `ask:${method}`);
|
|
597
603
|
packet_answer.meta.hash = this.hash(packet_answer);
|
|
598
|
-
this.action('ask');
|
|
599
604
|
packet.a = packet_answer;
|
|
605
|
+
this.state('talk', config.events.answer);
|
|
600
606
|
this.talk(config.events.answer, this.copy(packet)); // global talk event
|
|
601
607
|
this.talk(`${agent.key}:ask:${packet.id}`, packet);
|
|
602
608
|
}).catch(err => {
|
|
@@ -631,6 +637,7 @@ class Deva {
|
|
|
631
637
|
// set client
|
|
632
638
|
this._active = Date.now();
|
|
633
639
|
const agent = this.agent();
|
|
640
|
+
|
|
634
641
|
const _data = {
|
|
635
642
|
id: this.uid(true),
|
|
636
643
|
key: 'init',
|
|
@@ -655,7 +662,9 @@ class Deva {
|
|
|
655
662
|
}).then(() => {
|
|
656
663
|
this.zone('init');
|
|
657
664
|
const hasOnInit = this.onInit && typeof this.onInit === 'function';
|
|
658
|
-
return hasOnInit ? this.onInit(_data) : this.start(_data)
|
|
665
|
+
return hasOnInit ? this.onInit(_data) : this.start(_data);
|
|
666
|
+
}).then(done => {
|
|
667
|
+
return resolve(done);
|
|
659
668
|
}).catch(err => {
|
|
660
669
|
return this.error(err, client, reject);
|
|
661
670
|
});
|
|
@@ -675,12 +684,12 @@ class Deva {
|
|
|
675
684
|
start(data) {
|
|
676
685
|
this.zone('start');
|
|
677
686
|
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
678
|
-
this.
|
|
687
|
+
this.action('start');
|
|
679
688
|
data.value = 'start';
|
|
680
689
|
delete data.hash;
|
|
681
690
|
data.hash = this.hash(data);
|
|
682
691
|
const hasOnStart = this.onStart && typeof this.onStart === 'function' ? true : false;
|
|
683
|
-
this.
|
|
692
|
+
this.state('start');
|
|
684
693
|
return hasOnStart ? this.onStart(data) : this.enter(data)
|
|
685
694
|
}
|
|
686
695
|
|
|
@@ -698,11 +707,11 @@ class Deva {
|
|
|
698
707
|
enter(data) {
|
|
699
708
|
this.zone('enter');
|
|
700
709
|
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
701
|
-
this.
|
|
710
|
+
this.action('enter');
|
|
702
711
|
data.value = 'enter';
|
|
703
712
|
delete data.hash;
|
|
704
713
|
data.hash = this.hash(data);
|
|
705
|
-
this.
|
|
714
|
+
this.state('enter');
|
|
706
715
|
const hasOnEnter = this.onEnter && typeof this.onEnter === 'function' ? true : false;
|
|
707
716
|
return hasOnEnter ? this.onEnter(data) : this.done(data)
|
|
708
717
|
}
|
|
@@ -721,12 +730,12 @@ class Deva {
|
|
|
721
730
|
done(data) {
|
|
722
731
|
this.zone('done');
|
|
723
732
|
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
724
|
-
this.
|
|
733
|
+
this.action('done');
|
|
725
734
|
data.value = 'done';
|
|
726
735
|
delete data.hash;
|
|
727
736
|
data.hash = this.hash(data);
|
|
728
737
|
const hasOnDone = this.onDone && typeof this.onDone === 'function' ? true : false;
|
|
729
|
-
this.
|
|
738
|
+
this.state('done');
|
|
730
739
|
return hasOnDone ? this.onDone(data) : Promise.resolve(data);
|
|
731
740
|
}
|
|
732
741
|
|
|
@@ -740,18 +749,15 @@ class Deva {
|
|
|
740
749
|
usage: this.finish(data, resolve)
|
|
741
750
|
***************/
|
|
742
751
|
finish(packet, resolve) {
|
|
743
|
-
this.zone('finish'); // set the zone to finish
|
|
744
752
|
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
753
|
+
this.action('finish'); // set the finish action
|
|
745
754
|
|
|
746
|
-
this.state('finish'); // set the finish state
|
|
747
755
|
packet.hash = this.hash(packet);// hash the entire packet before finishing.
|
|
748
756
|
// check for agent on finish function in agent
|
|
749
757
|
const hasOnFinish = this.onFinish && typeof this.onFinish === 'function';
|
|
750
758
|
|
|
751
|
-
this.action('finish'); // set the finish action
|
|
752
759
|
// if: agent has on finish then return on finish
|
|
753
|
-
|
|
754
|
-
this.context('finish'); // set the context to finish
|
|
760
|
+
this.state('finish'); // set the finish state
|
|
755
761
|
if (hasOnFinish) return this.onFinish(packet, resolve);
|
|
756
762
|
// return the provided resolve function or a promise resolve.
|
|
757
763
|
return resolve ? resolve(packet) : Promise.resolve(packet);
|
|
@@ -807,10 +813,10 @@ class Deva {
|
|
|
807
813
|
exit() {
|
|
808
814
|
this.zone('exit');
|
|
809
815
|
|
|
810
|
-
this.state('exit');
|
|
811
816
|
const agent = this.agent();
|
|
812
817
|
const client = this.client();
|
|
813
818
|
|
|
819
|
+
this.action('exit');
|
|
814
820
|
const data = {
|
|
815
821
|
id: this.uid(true),
|
|
816
822
|
key: 'exit',
|
|
@@ -828,7 +834,7 @@ class Deva {
|
|
|
828
834
|
this._support = false;
|
|
829
835
|
this._services = false;
|
|
830
836
|
|
|
831
|
-
this.
|
|
837
|
+
this.state('exit');
|
|
832
838
|
const hasOnExit = this.onExit && typeof this.onExit === 'function';
|
|
833
839
|
return hasOnExit ? this.onExit(data) : Promise.resolve(data)
|
|
834
840
|
}
|
|
@@ -870,7 +876,8 @@ class Deva {
|
|
|
870
876
|
describe: returns the avaiable staets values.
|
|
871
877
|
***************/
|
|
872
878
|
states() {
|
|
873
|
-
this.action('states');
|
|
879
|
+
this.action('func', 'states');
|
|
880
|
+
this.state('return', 'states');
|
|
874
881
|
return {
|
|
875
882
|
id: this.uid(true),
|
|
876
883
|
key: 'states',
|
|
@@ -915,7 +922,8 @@ class Deva {
|
|
|
915
922
|
describe: returns a listing of zones currently in the system.
|
|
916
923
|
***************/
|
|
917
924
|
zones() {
|
|
918
|
-
this.action('zones');
|
|
925
|
+
this.action('func', 'zones');
|
|
926
|
+
this.state('return', 'zones');
|
|
919
927
|
return {
|
|
920
928
|
id: this.uid(true), // set the uuid of the data
|
|
921
929
|
agent: this.agent(), // set the agent value
|
|
@@ -965,7 +973,8 @@ class Deva {
|
|
|
965
973
|
describe: Returns a list of available actions in the system.
|
|
966
974
|
***************/
|
|
967
975
|
actions() {
|
|
968
|
-
this.action('actions');
|
|
976
|
+
this.action('func', 'actions');
|
|
977
|
+
this.state('return', 'actions');
|
|
969
978
|
return {
|
|
970
979
|
id: this.uid(true), // set the id with a uuid
|
|
971
980
|
agent: this.agent(), // set the agent value
|
|
@@ -1000,6 +1009,7 @@ class Deva {
|
|
|
1000
1009
|
created: Date.now(), // set the creation date
|
|
1001
1010
|
};
|
|
1002
1011
|
data.hash = this.hash(data); // generate the hash value of the data packet
|
|
1012
|
+
this.state('talk', 'feature');
|
|
1003
1013
|
this.talk(config.events.feature, data); // talk the feature event with data
|
|
1004
1014
|
} catch (e) { // catch any errors
|
|
1005
1015
|
return this.error(e); // retun this.error when an error is caught.
|
|
@@ -1012,7 +1022,7 @@ class Deva {
|
|
|
1012
1022
|
describe: return a list of features that are available to the system.
|
|
1013
1023
|
***************/
|
|
1014
1024
|
features() {
|
|
1015
|
-
this.
|
|
1025
|
+
this.state('return', 'features');
|
|
1016
1026
|
return { // return the data object
|
|
1017
1027
|
id: this.uid(true), // set the object id
|
|
1018
1028
|
agent: this.agent(), // set the agent value.
|
|
@@ -1046,7 +1056,9 @@ class Deva {
|
|
|
1046
1056
|
text,
|
|
1047
1057
|
created: Date.now(),
|
|
1048
1058
|
};
|
|
1059
|
+
|
|
1049
1060
|
data.hash = this.hash(data);
|
|
1061
|
+
this.state('talk', 'context');
|
|
1050
1062
|
this.talk(config.events.context, data);
|
|
1051
1063
|
} catch (e) {
|
|
1052
1064
|
return this.error(e);
|
|
@@ -1054,7 +1066,8 @@ class Deva {
|
|
|
1054
1066
|
}
|
|
1055
1067
|
|
|
1056
1068
|
contexts() {
|
|
1057
|
-
this.
|
|
1069
|
+
if (!this._active) return this._messages.offline; // check the active status
|
|
1070
|
+
this.state('return', 'contexts');
|
|
1058
1071
|
return {
|
|
1059
1072
|
id: this.uid(true),
|
|
1060
1073
|
agent: this.agent(),
|
|
@@ -1097,11 +1110,11 @@ class Deva {
|
|
|
1097
1110
|
usage: this.security()
|
|
1098
1111
|
***************/
|
|
1099
1112
|
security() {
|
|
1100
|
-
this.feature('security'); // set the security state
|
|
1101
1113
|
if (!this._active) return this._messages.offline; // check the active status
|
|
1102
|
-
this.
|
|
1114
|
+
this.zone('security');
|
|
1115
|
+
this.feature('security'); // set the security state
|
|
1103
1116
|
try {
|
|
1104
|
-
this.
|
|
1117
|
+
this.state('return', 'security'); // set the security state
|
|
1105
1118
|
return this.copy(this._security); // return the security feature
|
|
1106
1119
|
} catch (e) {return this.error(e);}
|
|
1107
1120
|
}
|
|
@@ -1113,11 +1126,11 @@ class Deva {
|
|
|
1113
1126
|
usage: this.support()
|
|
1114
1127
|
***************/
|
|
1115
1128
|
support() {
|
|
1116
|
-
this.feature('support'); // set the support state
|
|
1117
1129
|
if (!this._active) return this._messages.offline; // check the active status
|
|
1118
|
-
this.
|
|
1130
|
+
this.zone('support');
|
|
1131
|
+
this.feature('support'); // set the support state
|
|
1119
1132
|
try {
|
|
1120
|
-
this.
|
|
1133
|
+
this.state('return', 'support'); // set the action to support.
|
|
1121
1134
|
return this.copy(this._support); // return the support feature
|
|
1122
1135
|
} catch (e) {
|
|
1123
1136
|
return this.error(e); // return this.error when error catch
|
|
@@ -1131,11 +1144,11 @@ class Deva {
|
|
|
1131
1144
|
usage: this.services()
|
|
1132
1145
|
***************/
|
|
1133
1146
|
services(opts) {
|
|
1134
|
-
this.feature('services'); // set the support state
|
|
1135
1147
|
if (!this._active) return this._messages.offline; // check the active status
|
|
1136
|
-
this.
|
|
1148
|
+
this.zone('services');
|
|
1149
|
+
this.feature('services'); // set the support state
|
|
1137
1150
|
try {
|
|
1138
|
-
this.
|
|
1151
|
+
this.state('return', 'services'); // set the services state
|
|
1139
1152
|
return this.copy(this._services); // return the services feature
|
|
1140
1153
|
} catch (e) {
|
|
1141
1154
|
return this.error(e); // return this.error when error catch
|
|
@@ -1149,7 +1162,9 @@ class Deva {
|
|
|
1149
1162
|
describe: This function will enable fast loading of Deva into the system.
|
|
1150
1163
|
***************/
|
|
1151
1164
|
load(key, client) {
|
|
1152
|
-
this.
|
|
1165
|
+
this.zone('load', key);
|
|
1166
|
+
this.action('load', key);
|
|
1167
|
+
this.state('load', key);
|
|
1153
1168
|
return this.devas[key].init(client);
|
|
1154
1169
|
}
|
|
1155
1170
|
|
|
@@ -1160,13 +1175,15 @@ class Deva {
|
|
|
1160
1175
|
describe: Unload a currently loaded Deva.
|
|
1161
1176
|
***************/
|
|
1162
1177
|
unload(key) {
|
|
1178
|
+
this.zone('unload', key);
|
|
1163
1179
|
return new Promise((resolve, reject) => {
|
|
1164
1180
|
try {
|
|
1165
|
-
this.
|
|
1181
|
+
this.action('uload', key);
|
|
1166
1182
|
this.devas[key].stop().then(exit => {
|
|
1167
1183
|
delete this.devas[key];
|
|
1168
1184
|
this.talk(config.events.unload, key);
|
|
1169
1185
|
});
|
|
1186
|
+
this.state('unload', key)
|
|
1170
1187
|
return resolve(this._states.unload);
|
|
1171
1188
|
} catch (e) {
|
|
1172
1189
|
return this.error(e, this.devas[key], reject)
|
|
@@ -1227,6 +1244,7 @@ class Deva {
|
|
|
1227
1244
|
defined client security settings.
|
|
1228
1245
|
***************/
|
|
1229
1246
|
cipher(str) {
|
|
1247
|
+
this.feature('cipher');
|
|
1230
1248
|
// this.action('cipher');
|
|
1231
1249
|
const security = this._security;
|
|
1232
1250
|
const {password, algorithm} = security.cipher;
|
|
@@ -1237,6 +1255,7 @@ class Deva {
|
|
|
1237
1255
|
const _cipher = createCipheriv(algorithm, key_in_bytes, iv);
|
|
1238
1256
|
const encrypted = _cipher.update(String(str), 'utf8', 'hex') + _cipher.final('hex');
|
|
1239
1257
|
|
|
1258
|
+
this.state('return', 'cipher');
|
|
1240
1259
|
return {
|
|
1241
1260
|
iv: iv.toString('base64'),
|
|
1242
1261
|
key,
|
|
@@ -1245,6 +1264,7 @@ class Deva {
|
|
|
1245
1264
|
}
|
|
1246
1265
|
|
|
1247
1266
|
decipher(opt) {
|
|
1267
|
+
this.feature('decipher');
|
|
1248
1268
|
// this.action('decipher');
|
|
1249
1269
|
const iv = Buffer.from(opt.iv, 'base64');
|
|
1250
1270
|
const encrypted = Buffer.from(opt.encrypted, 'hex');
|
|
@@ -1255,6 +1275,7 @@ class Deva {
|
|
|
1255
1275
|
const decrypted = decipher.update(encrypted);
|
|
1256
1276
|
const final = Buffer.concat([decrypted, decipher.final()]);
|
|
1257
1277
|
return final.toString();
|
|
1278
|
+
this.state('return', 'decipher');
|
|
1258
1279
|
}
|
|
1259
1280
|
|
|
1260
1281
|
/**************
|
|
@@ -1267,7 +1288,7 @@ class Deva {
|
|
|
1267
1288
|
usage: this.prompt('text')
|
|
1268
1289
|
***************/
|
|
1269
1290
|
prompt(text) {
|
|
1270
|
-
this.
|
|
1291
|
+
this.feature('prompt');
|
|
1271
1292
|
// Talk a global prompt event for the client
|
|
1272
1293
|
const agent = this.agent();
|
|
1273
1294
|
const client = this.client();
|
|
@@ -1280,6 +1301,7 @@ class Deva {
|
|
|
1280
1301
|
text,
|
|
1281
1302
|
created: Date.now(),
|
|
1282
1303
|
}
|
|
1304
|
+
this.state('talk', 'prompt')
|
|
1283
1305
|
return this.talk(config.events.prompt, _data);
|
|
1284
1306
|
}
|
|
1285
1307
|
|
|
@@ -1307,13 +1329,14 @@ class Deva {
|
|
|
1307
1329
|
with no time value for the current day.
|
|
1308
1330
|
***************/
|
|
1309
1331
|
getToday(d) {
|
|
1310
|
-
this.
|
|
1332
|
+
this.feature('getToday');
|
|
1311
1333
|
d = d ? d : Date.now();
|
|
1312
1334
|
const today = new Date(d);
|
|
1313
1335
|
today.setHours(0);
|
|
1314
1336
|
today.setMinutes(0);
|
|
1315
1337
|
today.setSeconds(0);
|
|
1316
1338
|
today.setMilliseconds(0);
|
|
1339
|
+
this.state('return', 'getToday');
|
|
1317
1340
|
return today.getTime();
|
|
1318
1341
|
}
|
|
1319
1342
|
|
|
@@ -1330,6 +1353,7 @@ class Deva {
|
|
|
1330
1353
|
system based on the language and locale in the client profile.
|
|
1331
1354
|
***************/
|
|
1332
1355
|
formatDate(d, format='milli', time=false) {
|
|
1356
|
+
this.feature('formatDate');
|
|
1333
1357
|
if (!d) d = Date.now();
|
|
1334
1358
|
d = new Date(d);
|
|
1335
1359
|
|
|
@@ -1348,6 +1372,7 @@ class Deva {
|
|
|
1348
1372
|
};
|
|
1349
1373
|
const theDate = d.toLocaleDateString(this._client.locale, formats[format]);
|
|
1350
1374
|
const theTime = this.formatTime(d);
|
|
1375
|
+
this.state('return', 'formatDate');
|
|
1351
1376
|
return !theTime ? theDate : `${theDate} - ${theTime}`;
|
|
1352
1377
|
}
|
|
1353
1378
|
|
|
@@ -1360,6 +1385,7 @@ class Deva {
|
|
|
1360
1385
|
parameter based on the locale setting in the client profile..
|
|
1361
1386
|
***************/
|
|
1362
1387
|
formatTime(t) {
|
|
1388
|
+
this.feature('formatTime');
|
|
1363
1389
|
return t.toLocaleTimeString(this._client.locale); // return the formatted time string
|
|
1364
1390
|
}
|
|
1365
1391
|
|
|
@@ -1372,6 +1398,7 @@ class Deva {
|
|
|
1372
1398
|
in the client profile.
|
|
1373
1399
|
***************/
|
|
1374
1400
|
formatCurrency(n) {
|
|
1401
|
+
this.feature('formatCurrency');
|
|
1375
1402
|
return new Intl.NumberFormat(this._client.locale, { style: 'currency', currency: this._client.currency }).format(n);
|
|
1376
1403
|
}
|
|
1377
1404
|
|
|
@@ -1383,6 +1410,7 @@ class Deva {
|
|
|
1383
1410
|
describe:
|
|
1384
1411
|
***************/
|
|
1385
1412
|
formatPercent(n, dec=2) {
|
|
1413
|
+
this.feature('formatPercent');
|
|
1386
1414
|
return parseFloat(n).toFixed(dec) + '%';
|
|
1387
1415
|
}
|
|
1388
1416
|
|
|
@@ -1395,8 +1423,10 @@ class Deva {
|
|
|
1395
1423
|
A utility function to trimText intput to a specific word count.
|
|
1396
1424
|
***************/
|
|
1397
1425
|
trimWords(text, maxwords) {
|
|
1426
|
+
this.feature('trimWords');
|
|
1398
1427
|
const splitter = text.split(' ');
|
|
1399
1428
|
if (splitter < maxwords) return text;
|
|
1429
|
+
this.state('return', 'trimmed words');
|
|
1400
1430
|
return splitter.slice(0, maxwords).join(' ');
|
|
1401
1431
|
}
|
|
1402
1432
|
|
|
@@ -1406,9 +1436,10 @@ class Deva {
|
|
|
1406
1436
|
describe: remove duplicees from an array.
|
|
1407
1437
|
***************/
|
|
1408
1438
|
dupes(dupers) {
|
|
1409
|
-
this.
|
|
1439
|
+
this.feature('dupes');
|
|
1410
1440
|
if (!Array.isArray(dupers)) return dupers;
|
|
1411
1441
|
const check = [];
|
|
1442
|
+
this.state('return', 'duplicates removed');
|
|
1412
1443
|
return dupers.filter(dupe => {
|
|
1413
1444
|
if (!check.includes(dupe)) {
|
|
1414
1445
|
check.push(dupe);
|
|
@@ -1425,7 +1456,7 @@ class Deva {
|
|
|
1425
1456
|
info() {
|
|
1426
1457
|
// check the active status
|
|
1427
1458
|
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
1428
|
-
this.
|
|
1459
|
+
this.feature('info');
|
|
1429
1460
|
return this._info;
|
|
1430
1461
|
}
|
|
1431
1462
|
|
|
@@ -1442,11 +1473,12 @@ class Deva {
|
|
|
1442
1473
|
***************/
|
|
1443
1474
|
status(msg=false) {
|
|
1444
1475
|
// check the active status
|
|
1445
|
-
if (!this._active) return Promise.resolve(this._messages.
|
|
1476
|
+
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
1477
|
+
this.feature('status');
|
|
1478
|
+
|
|
1446
1479
|
// format the date since active for output.
|
|
1447
1480
|
const dateFormat = this.formatDate(this._active, 'long', true);
|
|
1448
1481
|
// create the text msg string
|
|
1449
|
-
this.action('status');
|
|
1450
1482
|
let text = `${this._agent.profile.name} active since ${dateFormat}`;
|
|
1451
1483
|
if (msg) text = text + `\n${msg}`; // append the msg string if msg true.
|
|
1452
1484
|
return text; // return final text string
|
|
@@ -1463,19 +1495,21 @@ class Deva {
|
|
|
1463
1495
|
one exists it will then present it based on the users request text input.
|
|
1464
1496
|
***************/
|
|
1465
1497
|
help(msg, help_dir) {
|
|
1466
|
-
this.zone('help');
|
|
1467
1498
|
return new Promise((resolve, reject) => {
|
|
1468
|
-
if (!this._active) return resolve(this._messages.
|
|
1469
|
-
this.
|
|
1499
|
+
if (!this._active) return resolve(this._messages.offline);
|
|
1500
|
+
this.feature('help');
|
|
1501
|
+
this.zone('help');
|
|
1502
|
+
|
|
1470
1503
|
const params = msg.split(' ');
|
|
1471
1504
|
let helpFile = 'main';
|
|
1472
1505
|
if (params[0]) helpFile = params[0];
|
|
1473
1506
|
if (params[1]) helpFile = `${params[0]}_${params[1]}`;
|
|
1474
1507
|
helpFile = path.join(help_dir, 'help', `${helpFile}.feecting`);
|
|
1475
1508
|
try {
|
|
1476
|
-
this.
|
|
1509
|
+
this.state('resolve', 'help');
|
|
1477
1510
|
return resolve(fs.readFileSync(helpFile, 'utf8'));
|
|
1478
1511
|
} catch (e) {
|
|
1512
|
+
this.state('reject', 'helpFile');
|
|
1479
1513
|
return reject(e)
|
|
1480
1514
|
}
|
|
1481
1515
|
});
|
|
@@ -1494,7 +1528,7 @@ class Deva {
|
|
|
1494
1528
|
error(err,data=false,reject=false) {
|
|
1495
1529
|
this.zone('error');
|
|
1496
1530
|
|
|
1497
|
-
this.
|
|
1531
|
+
this.action('error')
|
|
1498
1532
|
const agent = this.agent();
|
|
1499
1533
|
const client = this.client();
|
|
1500
1534
|
const _data = {
|
|
@@ -1509,7 +1543,8 @@ class Deva {
|
|
|
1509
1543
|
}
|
|
1510
1544
|
this.talk(config.events.error, this.copy(_data));
|
|
1511
1545
|
const hasOnError = this.onError && typeof this.onError === 'function' ? true : false;
|
|
1512
|
-
|
|
1546
|
+
|
|
1547
|
+
this.state('error');
|
|
1513
1548
|
if (hasOnError) return this.onError(err, data, reject);
|
|
1514
1549
|
else return reject ? reject(err) : err;
|
|
1515
1550
|
}
|