forked from StefJohns/Jarvee
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnumsVoiceScript.js
267 lines (238 loc) · 11 KB
/
EnumsVoiceScript.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
// Define Constants & Arrays
onCreateProject(() => {
project.ENUMSCATEGORIES = "set_|macro_|class|plain|operation_|caps|caital letter_|unnamed|underlying type_|value_";
});
// URL Pages Array
const URL_Pages = [
'Renum-macro',
'Renum-set',
'Renum-class',
'Renum-oper',
'Renum-caps',
'Renum-unnamed',
'Renum-underlying',
'Renum-value'
];
// Enumerations Definition
const Interface_Definition = "Enumerations are used to define sets of integer values and for defining types for such sets of values. There are two kind of enumerations, \?plain\? enums and class enums.";
// Rule Descriptions
const Rule_Descriptions = [
'Prefer enumerations over macros.',
'Use enumerations to represent sets of related named constants.',
'Prefer class enums over plain enums.',
'Define operations on enumerations for safe and simple use.',
'Don\'t use ALL_CAPS for enumerators.',
'Avoid unnamed enumerations.',
'Specify the underlying type of an enumeration only when necessary.',
'Specify enumerator values only when necessary.'
];
// Rule Reasons
const Rule_Reasons = [
'Macros do not obey scope and type rules. Also, macro names are removed during preprocessing and so usually don\?t appear in tools like debuggers.',
'An enumeration shows the enumerators to be related and can be a named type.',
'To minimize surprises: traditional enums convert to int too readily.',
'Convenience of use and avoidance of errors.',
'Avoid clashes with macros.',
'If you can?t name an enumeration, the values are not related',
'The default is the easiest to read and write. int is the default integer type. int is compatible with C enums.',
'It?s the simplest. It avoids duplicate enumerator values. The default gives a consecutive set of values that is good for switch-statement implementations.'
];
// Rule Notes
const Notes = [
'No Notes Provided',
'Switching on an enumeration is common and the compiler can warn against unusual patterns of case labels. ',
'No Notes Provided',
'No Notes Provided',
'No Notes Provided',
'No Notes Provided',
'Specifying the underlying type is necessary in forward declarations of enumerations.',
'No Notes Provided'
];
// Class Enforcement
const Enforcements = [
];
// Mutable Variables
let jResponse;
let jFollowUp;
// Play Definition
function playDefinition(jarvee){
let def = Interface_Definition;
if (def) { return Promise.resolve(def);}
else { return Promise.resolve();}
}
// Number of Rules
function numRules(jarvee) {
let numR = 'There are ' + Rule_Descriptions.length + ' available.';
if (Rule_Descriptions.length) { return Promise.resolve(numR); }
else { return Promise.resolve();}
}
// Initial Intents
// Info On C++ Enums
intent('(I would like information on|Do you have information on|Can you tell me about|) $(E Enums|Enumerations|Enumerators)?', async jarvee => {
// Definition ? yes : no ; playDefinition
jFollowUp = 'Would you like to hear the definition first?';
jarvee.play({command: 'jarveeResponse', responseText: jFollowUp});
jarvee.play(jFollowUp);
let defAnswer = await jarvee.then(answerConfirm);
if (defAnswer == "yes") {
let definitionResponse = await playDefinition(jarvee);
if (definitionResponse){
jResponse = definitionResponse;
jarvee.play({command: 'jarveeResponse', responseText: jResponse});
jarvee.play(jResponse);
} else { jarvee.play('Okay!'); }
} else {
jarvee.play('Okay!');
}
// Get Number of Rules ? yes : no ; numRules
jFollowUp = 'Would you like to know the number of rules there are for Enums?';
jarvee.play({command: 'jarveeResponse', responseText: jFollowUp});
jarvee.play(jFollowUp);
let rulesAnswer = await jarvee.then(answerConfirm);
if (rulesAnswer === 'yes')
{
let rulesResponse = await numRules(jarvee);
if (rulesResponse)
{
jResponse = rulesResponse;
jarvee.play({command: 'jarveeResponse', responseText: jResponse});
jarvee.play(jResponse);
} else {
jarvee.play('Okay!');
}
} else {
jarvee.play('Okay!');
}
// Get What The User Wants From Enums
jResponse = 'What would you like to know?';
jarvee.play({command: 'jarveeResponse', responseText: jResponse});
jarvee.play(jResponse);
let topicAnswer = await jarvee.then(getTopic);
jResponse = "Let me grab information on " + topicAnswer + " for you.";
jarvee.play(jResponse);
// macro
if (topicAnswer === 'macro' || topicAnswer === 'macros'){
let page_url = project.COREGUIDELINESURL + URL_Pages[0];
jarvee.play({command: 'showWebPage', page_url});
jResponse = Rule_Descriptions[0];
jarvee.play(jResponse);
jResponse = 'The reason for this is because ' + Rule_Reasons[0];
jarvee.play({ command: 'jarveeResponse', responseText: jResponse});
jarvee.play(jResponse);
}
// set
if (topicAnswer === 'set' || topicAnswer === 'sets'){
let page_url = project.COREGUIDELINESURL + URL_Pages[1];
jarvee.play({command: 'showWebPage', page_url});
jResponse = Rule_Descriptions[1];
jarvee.play(jResponse);
jResponse = 'The reason for this is because ' + Rule_Reasons[1];
jarvee.play({ command: 'jarveeResponse', responseText: jResponse});
jarvee.play(jResponse);
}
// class
if (topicAnswer === 'class' || topicAnswer === 'plain'){
let page_url = project.COREGUIDELINESURL + URL_Pages[2];
jarvee.play({command: 'showWebPage', page_url});
jResponse = Rule_Descriptions[2];
jarvee.play(jResponse);
jResponse = 'The reason for this is because ' + Rule_Reasons[2];
jarvee.play({ command: 'jarveeResponse', responseText: jResponse});
jarvee.play(jResponse);
}
// operation
if (topicAnswer === 'operation' || topicAnswer === 'operations'){
let page_url = project.COREGUIDELINESURL + URL_Pages[3];
jarvee.play({command: 'showWebPage', page_url});
jResponse = Rule_Descriptions[3];
jarvee.play(jResponse);
jResponse = 'The reason for this is because ' + Rule_Reasons[3];
jarvee.play({ command: 'jarveeResponse', responseText: jResponse});
jarvee.play(jResponse);
}
// caps
if (topicAnswer === 'caps' || topicAnswer === 'capital letter' || topicAnswer === 'capital letters'){
let page_url = project.COREGUIDELINESURL + URL_Pages[4];
jarvee.play({command: 'showWebPage', page_url});
jResponse = Rule_Descriptions[4];
jarvee.play(jResponse);
jResponse = 'The reason for this is because ' + Rule_Reasons[4];
jarvee.play({ command: 'jarveeResponse', responseText: jResponse});
jarvee.play(jResponse);
}
// unnamed
if (topicAnswer === 'unnamed'){
let page_url = project.COREGUIDELINESURL + URL_Pages[5];
jarvee.play({command: 'showWebPage', page_url});
jResponse = Rule_Descriptions[5];
jarvee.play(jResponse);
jResponse = 'The reason for this is because ' + Rule_Reasons[5];
jarvee.play({ command: 'jarveeResponse', responseText: jResponse});
jarvee.play(jResponse);
}
// underlying
if (topicAnswer === 'underlying type' || topicAnswer === 'underlying types'){
let page_url = project.COREGUIDELINESURL + URL_Pages[6];
jarvee.play({command: 'showWebPage', page_url});
jResponse = Rule_Descriptions[6];
jarvee.play(jResponse);
jResponse = 'The reason for this is because ' + Rule_Reasons[6];
jarvee.play({ command: 'jarveeResponse', responseText: jResponse});
jarvee.play(jResponse);
}
// values
if (topicAnswer === 'values' || topicAnswer === 'value'){
let page_url = project.COREGUIDELINESURL + URL_Pages[7];
jarvee.play({command: 'showWebPage', page_url});
jResponse = Rule_Descriptions[7];
jarvee.play(jResponse);
jResponse = 'The reason for this is because ' + Rule_Reasons[7];
jarvee.play({ command: 'jarveeResponse', responseText: jResponse});
jarvee.play(jResponse);
}
});
// Show Web Page Intent
intent('(Show|Bring Up|) the main website for $(E Enums|Enumerations|Enumerators)', 'Show me the guidelines for $(E Enums|Enumerations|Enumerators)', async jarvee => {
jarvee.play('Sure thing. Pulling up the guidelines now', 'Absolutely! Showing the webpage now.')
let page_url = project.COREGUIDELINESURL + 'S-enum';
jarvee.play({command: 'showWebPage', page_url});
});
// Get Specific Page Intent
intent('Show me the web(site|page) for enum $(ENUMCAT p:ENUMSCATEGORIES)', 'Can you pull up the web(site|page) for enum $(ENUMCAT p:ENUMSCATEGORIES)', '(Show|Bring Up|) the website for enum $(ENUMCAT p:ENUMSCATEGORIES)','Search for enum $(ENUMCAT p:ENUMSCATEGORIES)', async jarvee => {
jarvee.play(`Sure. Pulling up the guideline on ${jarvee.ENUMCAT.value} now`, `Searching for ${jarvee.ENUMCAT.value.toLowerCase()}...`);
let keyword = jarvee.ENUMCAT.value;
let page_url;
switch (keyword) {
// macros keyword does not register with jarvee, unable to find cause.
case "macros" : page_url = project.COREGUIDELINESURL + URL_Pages[0]; break;
// macro keyword does register with jarvee
case "macro": page_url = project.COREGUIDELINESURL + URL_Pages[0]; break;
case "sets" : page_url = project.COREGUIDELINESURL + URL_Pages[1]; break;
case "set": page_url = project.COREGUIDELINESURL + URL_Pages[1]; break;
case "class" : page_url = project.COREGUIDELINESURL + URL_Pages[2]; break;
case "plain" : page_url = project.COREGUIDELINESURL + URL_Pages[2]; break;
case "operations" : page_url = project.COREGUIDELINESURL + URL_Pages[3]; break;
case "operation": page_url = project.COREGUIDELINESURL + URL_Pages[3]; break;
case "caps" : page_url = project.COREGUIDELINESURL + URL_Pages[4]; break;
case "capital letters": page_url = project.COREGUIDELINESURL + URL_Pages[4]; break;
case "unnamed" : page_url = project.COREGUIDELINESURL + URL_Pages[5]; break;
case "underlying types": page_url = project.COREGUIDELINESURL + URL_Pages[6]; break;
case "underlying type": page_url = project.COREGUIDELINESURL + URL_Pages[6]; break;
case "values" : page_url = project.COREGUIDELINESURL + URL_Pages[7]; break;
case "value": page_url = project.COREGUIDELINESURL + URL_Pages[7]; break;
}
jarvee.play({command: 'showWebPage', page_url});
});
// Contexts
// Confirm Answer Context
let answerConfirm = context(() => {
intent('$(Answer yes|no|)', jarvee => {
return jarvee.resolve(jarvee.Answer.value.toLowerCase());
});
});
// Get Topic
let getTopic = context(() => {
intent('(I would like information on|Do you have information on|Can you tell me about|) $(ENUMCAT p:ENUMSCATEGORIES)', jarvee => {
return jarvee.resolve(jarvee.ENUMCAT.value.toLowerCase());
});
});