-
Notifications
You must be signed in to change notification settings - Fork 123
/
intentparam.go
executable file
·719 lines (713 loc) · 30 KB
/
intentparam.go
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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
package wirepod_ttr
import (
"encoding/json"
"strconv"
"strings"
"github.com/fforchino/vector-go-sdk/pkg/vector"
"github.com/kercre123/wire-pod/chipper/pkg/logger"
"github.com/kercre123/wire-pod/chipper/pkg/vars"
lcztn "github.com/kercre123/wire-pod/chipper/pkg/wirepod/localization"
)
// stt
func ParamChecker(req interface{}, intent string, speechText string, botSerial string) {
var intentParam string
var intentParamValue string
var newIntent string
var isParam bool
var intentParams map[string]string
var botLocation string = "San Francisco"
var botUnits string = "F"
var botPlaySpecific bool = false
var botIsEarlyOpus bool = false
var DoWeatherError bool = false
// see if jdoc exists
botJdoc, jdocExists := vars.GetJdoc("vic:"+botSerial, "vic.RobotSettings")
if jdocExists {
type robotSettingsJson struct {
ButtonWakeword int `json:"button_wakeword"`
Clock24Hour bool `json:"clock_24_hour"`
CustomEyeColor struct {
Enabled bool `json:"enabled"`
Hue float64 `json:"hue"`
Saturation float64 `json:"saturation"`
} `json:"custom_eye_color"`
DefaultLocation string `json:"default_location"`
DistIsMetric bool `json:"dist_is_metric"`
EyeColor int `json:"eye_color"`
Locale string `json:"locale"`
MasterVolume int `json:"master_volume"`
TempIsFahrenheit bool `json:"temp_is_fahrenheit"`
TimeZone string `json:"time_zone"`
}
var robotSettings robotSettingsJson
err := json.Unmarshal([]byte(botJdoc.JsonDoc), &robotSettings)
if err != nil {
logger.Println("Error unmarshaling json in paramchecker")
logger.Println(err)
} else {
botLocation = robotSettings.DefaultLocation
if robotSettings.TempIsFahrenheit {
botUnits = "F"
} else {
botUnits = "C"
}
}
}
if botPlaySpecific {
if strings.Contains(intent, "intent_play_blackjack") {
isParam = true
newIntent = "intent_play_specific_extend"
intentParam = "entity_behavior"
intentParamValue = "blackjack"
intentParams = map[string]string{intentParam: intentParamValue}
} else if strings.Contains(intent, "intent_play_fistbump") {
isParam = true
newIntent = "intent_play_specific_extend"
intentParam = "entity_behavior"
intentParamValue = "fist_bump"
intentParams = map[string]string{intentParam: intentParamValue}
} else if strings.Contains(intent, "intent_play_rollcube") {
isParam = true
newIntent = "intent_play_specific_extend"
intentParam = "entity_behavior"
intentParamValue = "roll_cube"
intentParams = map[string]string{intentParam: intentParamValue}
} else if strings.Contains(intent, "intent_play_popawheelie") {
isParam = true
newIntent = "intent_play_specific_extend"
intentParam = "entity_behavior"
intentParamValue = "pop_a_wheelie"
intentParams = map[string]string{intentParam: intentParamValue}
} else if strings.Contains(intent, "intent_play_pickupcube") {
isParam = true
newIntent = "intent_play_specific_extend"
intentParam = "entity_behavior"
intentParamValue = "pick_up_cube"
intentParams = map[string]string{intentParam: intentParamValue}
} else if strings.Contains(intent, "intent_play_keepaway") {
isParam = true
newIntent = "intent_play_specific_extend"
intentParam = "entity_behavior"
intentParamValue = "keep_away"
intentParams = map[string]string{intentParam: intentParamValue}
} else {
newIntent = intent
intentParam = ""
intentParamValue = ""
isParam = false
intentParams = map[string]string{intentParam: intentParamValue}
}
}
logger.Println("Checking params for candidate intent " + intent)
if strings.Contains(intent, "intent_photo_take_extend") {
isParam = true
newIntent = intent
if strings.Contains(speechText, lcztn.GetText(lcztn.STR_ME)) || strings.Contains(speechText, lcztn.GetText(lcztn.STR_SELF)) {
intentParam = "entity_photo_selfie"
intentParamValue = "photo_selfie"
} else {
intentParam = "entity_photo_selfie"
intentParamValue = ""
}
intentParams = map[string]string{intentParam: intentParamValue}
} else if strings.Contains(intent, "intent_imperative_eyecolor") {
isParam = true
newIntent = "intent_imperative_eyecolor_specific_extend"
intentParam = "eye_color"
if strings.Contains(speechText, lcztn.GetText(lcztn.STR_EYE_COLOR_PURPLE)) {
intentParamValue = "COLOR_PURPLE"
} else if strings.Contains(speechText, lcztn.GetText(lcztn.STR_EYE_COLOR_BLUE)) || strings.Contains(speechText, lcztn.GetText(lcztn.STR_EYE_COLOR_SAPPHIRE)) {
intentParamValue = "COLOR_BLUE"
} else if strings.Contains(speechText, lcztn.GetText(lcztn.STR_EYE_COLOR_YELLOW)) {
intentParamValue = "COLOR_YELLOW"
} else if strings.Contains(speechText, lcztn.GetText(lcztn.STR_EYE_COLOR_TEAL)) || strings.Contains(speechText, lcztn.GetText(lcztn.STR_EYE_COLOR_TEAL2)) {
intentParamValue = "COLOR_TEAL"
} else if strings.Contains(speechText, lcztn.GetText(lcztn.STR_EYE_COLOR_GREEN)) {
intentParamValue = "COLOR_GREEN"
} else if strings.Contains(speechText, lcztn.GetText(lcztn.STR_EYE_COLOR_ORANGE)) {
intentParamValue = "COLOR_ORANGE"
} else {
newIntent = intent
intentParamValue = ""
isParam = false
}
intentParams = map[string]string{intentParam: intentParamValue}
} else if strings.Contains(intent, "intent_weather_extend") {
isParam = true
newIntent = intent
condition, is_forecast, local_datetime, speakable_location_string, temperature, temperature_unit := weatherParser(speechText, botLocation, botUnits)
if local_datetime == "test" {
newIntent = "intent_system_unmatched"
isParam = false
DoWeatherError = true
} else {
intentParams = map[string]string{"condition": condition, "is_forecast": is_forecast, "local_datetime": local_datetime, "speakable_location_string": speakable_location_string, "temperature": temperature, "temperature_unit": temperature_unit}
}
} else if strings.Contains(intent, "intent_imperative_volumelevel_extend") {
isParam = true
newIntent = intent
if strings.Contains(speechText, lcztn.GetText(lcztn.STR_VOLUME_MEDIUM_LOW)) {
intentParam = "volume_level"
intentParamValue = "VOLUME_2"
} else if strings.Contains(speechText, lcztn.GetText(lcztn.STR_VOLUME_LOW)) || strings.Contains(speechText, lcztn.GetText(lcztn.STR_VOLUME_QUIET)) {
intentParam = "volume_level"
intentParamValue = "VOLUME_1"
} else if strings.Contains(speechText, lcztn.GetText(lcztn.STR_VOLUME_MEDIUM_HIGH)) {
intentParam = "volume_level"
intentParamValue = "VOLUME_4"
} else if strings.Contains(speechText, lcztn.GetText(lcztn.STR_VOLUME_MEDIUM)) || strings.Contains(speechText, lcztn.GetText(lcztn.STR_VOLUME_NORMAL)) || strings.Contains(speechText, lcztn.GetText(lcztn.STR_VOLUME_REGULAR)) {
intentParam = "volume_level"
intentParamValue = "VOLUME_3"
} else if strings.Contains(speechText, lcztn.GetText(lcztn.STR_VOLUME_HIGH)) || strings.Contains(speechText, lcztn.GetText(lcztn.STR_VOLUME_LOUD)) {
intentParam = "volume_level"
intentParamValue = "VOLUME_5"
} else if strings.Contains(speechText, lcztn.GetText(lcztn.STR_VOLUME_MUTE)) || strings.Contains(speechText, lcztn.GetText(lcztn.STR_VOLUME_NOTHING)) || strings.Contains(speechText, lcztn.GetText(lcztn.STR_VOLUME_SILENT)) || strings.Contains(speechText, lcztn.GetText(lcztn.STR_VOLUME_OFF)) || strings.Contains(speechText, lcztn.GetText(lcztn.STR_VOLUME_ZERO)) {
// there is no VOLUME_0 :(
intentParam = "volume_level"
intentParamValue = "VOLUME_1"
} else {
intentParam = "volume_level"
intentParamValue = "VOLUME_1"
}
intentParams = map[string]string{intentParam: intentParamValue}
} else if strings.Contains(intent, "intent_names_username_extend") {
if vars.VoskGrammerEnable {
var guid string
var target string
matched := false
for _, bot := range vars.BotInfo.Robots {
if botSerial == bot.Esn {
guid = bot.GUID
target = bot.IPAddress + ":443"
matched = true
break
}
}
if matched {
vec, err := vector.New(vector.WithSerialNo(botSerial), vector.WithToken(guid), vector.WithTarget(target))
if err != nil {
logger.Println("error connecting to vector:", err)
} else {
sayText(vec, "You must add a face in the web interface. It cannot be done via voice by default.")
}
}
logger.Println("You must add a face via the web interface (Bot Settings -> Connect -> Faces).")
logger.LogUI("You must add a face via the web interface (Bot Settings -> Connect -> Faces).")
}
var username string
var nameSplitter string = ""
isParam = true
newIntent = intent
if strings.Contains(speechText, lcztn.GetText(lcztn.STR_NAME_IS)) {
nameSplitter = lcztn.GetText(lcztn.STR_NAME_IS)
} else if strings.Contains(speechText, lcztn.GetText(lcztn.STR_NAME_IS2)) {
nameSplitter = lcztn.GetText(lcztn.STR_NAME_IS2)
} else if strings.Contains(speechText, lcztn.GetText(lcztn.STR_NAME_IS3)) {
nameSplitter = lcztn.GetText(lcztn.STR_NAME_IS3)
}
if nameSplitter != "" {
splitPhrase := strings.SplitAfter(speechText, nameSplitter)
username = strings.TrimSpace(splitPhrase[1])
if len(splitPhrase) == 3 {
username = username + " " + strings.TrimSpace(splitPhrase[2])
} else if len(splitPhrase) == 4 {
username = username + " " + strings.TrimSpace(splitPhrase[2]) + " " + strings.TrimSpace(splitPhrase[3])
} else if len(splitPhrase) > 4 {
username = username + " " + strings.TrimSpace(splitPhrase[2]) + " " + strings.TrimSpace(splitPhrase[3])
}
logger.Println("Name parsed from speech: " + "`" + username + "`")
intentParam = "username"
intentParamValue = username
intentParams = map[string]string{intentParam: intentParamValue}
} else {
logger.Println("No name parsed from speech")
intentParam = "username"
intentParamValue = ""
intentParams = map[string]string{intentParam: intentParamValue}
}
} else if strings.Contains(intent, "intent_clock_settimer_extend") {
isParam = true
newIntent = intent
timerSecs := words2num(speechText)
logger.Println("Seconds parsed from speech: " + timerSecs)
intentParam = "timer_duration"
intentParamValue = timerSecs
intentParams = map[string]string{intentParam: intentParamValue}
} else if strings.Contains(intent, "intent_global_stop_extend") {
isParam = true
newIntent = intent
intentParam = "what_to_stop"
intentParamValue = "timer"
intentParams = map[string]string{intentParam: intentParamValue}
} else if strings.Contains(intent, "intent_message_playmessage_extend") {
var given_name string
isParam = true
newIntent = intent
intentParam = "given_name"
if strings.Contains(speechText, lcztn.GetText(lcztn.STR_FOR)) {
splitPhrase := strings.SplitAfter(speechText, lcztn.GetText(lcztn.STR_FOR))
given_name = strings.TrimSpace(splitPhrase[1])
if len(splitPhrase) == 3 {
given_name = given_name + " " + strings.TrimSpace(splitPhrase[2])
} else if len(splitPhrase) == 4 {
given_name = given_name + " " + strings.TrimSpace(splitPhrase[2]) + " " + strings.TrimSpace(splitPhrase[3])
} else if len(splitPhrase) > 4 {
given_name = given_name + " " + strings.TrimSpace(splitPhrase[2]) + " " + strings.TrimSpace(splitPhrase[3])
}
intentParamValue = given_name
} else {
intentParamValue = ""
}
intentParams = map[string]string{intentParam: intentParamValue}
} else if strings.Contains(intent, "intent_message_recordmessage_extend") {
var given_name string
isParam = true
newIntent = intent
intentParam = "given_name"
if strings.Contains(speechText, lcztn.GetText(lcztn.STR_FOR)) {
splitPhrase := strings.SplitAfter(speechText, lcztn.GetText(lcztn.STR_FOR))
given_name = strings.TrimSpace(splitPhrase[1])
if len(splitPhrase) == 3 {
given_name = given_name + " " + strings.TrimSpace(splitPhrase[2])
} else if len(splitPhrase) == 4 {
given_name = given_name + " " + strings.TrimSpace(splitPhrase[2]) + " " + strings.TrimSpace(splitPhrase[3])
} else if len(splitPhrase) > 4 {
given_name = given_name + " " + strings.TrimSpace(splitPhrase[2]) + " " + strings.TrimSpace(splitPhrase[3])
}
intentParamValue = given_name
} else {
intentParamValue = ""
}
intentParams = map[string]string{intentParam: intentParamValue}
} else {
if intentParam == "" {
newIntent = intent
intentParam = ""
intentParamValue = ""
isParam = false
intentParams = map[string]string{intentParam: intentParamValue}
}
}
if botIsEarlyOpus {
if strings.Contains(intent, "intent_imperative_praise") {
isParam = false
newIntent = "intent_imperative_affirmative"
intentParam = ""
intentParamValue = ""
intentParams = map[string]string{intentParam: intentParamValue}
} else if strings.Contains(intent, "intent_imperative_abuse") {
isParam = false
newIntent = "intent_imperative_negative"
intentParam = ""
intentParamValue = ""
intentParams = map[string]string{intentParam: intentParamValue}
} else if strings.Contains(intent, "intent_imperative_love") {
isParam = false
newIntent = "intent_greeting_hello"
intentParam = ""
intentParamValue = ""
intentParams = map[string]string{intentParam: intentParamValue}
}
}
IntentPass(req, newIntent, speechText, intentParams, isParam)
if DoWeatherError {
if vars.APIConfig.Weather.Enable {
logger.Println("The weather API is not configured properly.")
KGSim(botSerial, "The weather API is not configured properly. Please check the wire pod logs for more details.")
} else {
logger.Println("The weather API is not configured.")
KGSim(botSerial, "The weather API is not configured.")
}
}
}
// stintent
func ParamCheckerSlotsEnUS(req interface{}, intent string, slots map[string]string, isOpus bool, botSerial string) {
var intentParam string
var intentParamValue string
var newIntent string
var isParam bool
var intentParams map[string]string
var botLocation string = "San Francisco"
var botUnits string = "F"
var botPlaySpecific bool = false
var botIsEarlyOpus bool = false
// see if jdoc exists
botJdoc, jdocExists := vars.GetJdoc("vic:"+botSerial, "vic.RobotSettings")
if jdocExists {
type robotSettingsJson struct {
ButtonWakeword int `json:"button_wakeword"`
Clock24Hour bool `json:"clock_24_hour"`
CustomEyeColor struct {
Enabled bool `json:"enabled"`
Hue float64 `json:"hue"`
Saturation float64 `json:"saturation"`
} `json:"custom_eye_color"`
DefaultLocation string `json:"default_location"`
DistIsMetric bool `json:"dist_is_metric"`
EyeColor int `json:"eye_color"`
Locale string `json:"locale"`
MasterVolume int `json:"master_volume"`
TempIsFahrenheit bool `json:"temp_is_fahrenheit"`
TimeZone string `json:"time_zone"`
}
var robotSettings robotSettingsJson
err := json.Unmarshal([]byte(botJdoc.JsonDoc), &robotSettings)
if err != nil {
logger.Println("Error unmarshaling json in paramchecker")
logger.Println(err)
} else {
botLocation = robotSettings.DefaultLocation
if robotSettings.TempIsFahrenheit {
botUnits = "F"
} else {
botUnits = "C"
}
}
}
if strings.Contains(intent, "volume") {
if slots["volume"] != "" {
newIntent = "intent_imperative_volumelevel_extend"
isParam = true
intentParam = "volume_level"
if strings.Contains(slots["volume"], "medium low") {
intentParamValue = "VOLUME_2"
} else if strings.Contains(slots["volume"], "low") {
intentParamValue = "VOLUME_1"
} else if strings.Contains(slots["volume"], "medium high") {
intentParamValue = "VOLUME_4"
} else if strings.Contains(slots["volume"], "high") {
intentParamValue = "VOLUME_5"
} else if strings.Contains(slots["volume"], "medium") {
intentParamValue = "VOLUME_3"
} else {
intentParamValue = "VOLUME_1"
}
} else {
isParam = false
intentParam = ""
intentParamValue = ""
}
intentParams = map[string]string{intentParam: intentParamValue}
} else if strings.Contains(intent, "eyecolor") {
isParam = true
newIntent = "intent_imperative_eyecolor_specific_extend"
intentParam = "eye_color"
if strings.Contains(slots["eye_color"], "purple") {
intentParamValue = "COLOR_PURPLE"
} else if strings.Contains(slots["eye_color"], "blue") || strings.Contains(slots["eye_color"], "sapphire") {
intentParamValue = "COLOR_BLUE"
} else if strings.Contains(slots["eye_color"], "yellow") {
intentParamValue = "COLOR_YELLOW"
} else if strings.Contains(slots["eye_color"], "teal") || strings.Contains(slots["eye_color"], "tell") {
intentParamValue = "COLOR_TEAL"
} else if strings.Contains(slots["eye_color"], "green") {
intentParamValue = "COLOR_GREEN"
} else if strings.Contains(slots["eye_color"], "orange") {
intentParamValue = "COLOR_ORANGE"
} else {
newIntent = intent
intentParamValue = ""
isParam = false
}
intentParams = map[string]string{intentParam: intentParamValue}
} else if strings.Contains(intent, "_selfie") {
newIntent = "intent_photo_take_extend"
intentParam = "entity_photo_selfie"
intentParamValue = "photo_selfie"
isParam = true
intentParams = map[string]string{intentParam: intentParamValue}
} else if strings.Contains(intent, "_noselfie") {
newIntent = "intent_photo_take_extend"
intentParam = "entity_photo_selfie"
intentParamValue = ""
isParam = true
intentParams = map[string]string{intentParam: intentParamValue}
} else if strings.Contains(intent, "settimer") {
isParam = true
newIntent = intent
slotNum := slots["num"]
slotUnit := slots["unit"]
timerSecs, err := strconv.Atoi(slotNum)
if err != nil {
logger.Println(err)
}
if slotNum != "" && slotUnit != "" {
if strings.Contains(slotUnit, "minute") {
timerSecs = timerSecs * 60
} else if strings.Contains(slotUnit, "hour") {
timerSecs = timerSecs * 60 * 60
}
}
logger.Println("Seconds parsed from speech: " + strconv.Itoa(timerSecs))
intentParam = "timer_duration"
intentParamValue = strconv.Itoa(timerSecs)
intentParams = map[string]string{intentParam: intentParamValue}
} else if strings.Contains(intent, "global_stop_extend") {
isParam = true
newIntent = intent
intentParam = "what_to_stop"
intentParamValue = "timer"
intentParams = map[string]string{intentParam: intentParamValue}
} else if strings.Contains(intent, "intent_knowledgegraph_prompt") {
isParam = false
newIntent = "intent_knowledge_promptquestion"
intentParam = ""
intentParamValue = ""
intentParams = map[string]string{intentParam: intentParamValue}
} else if strings.Contains(intent, "intent_weather_extend") {
isParam = true
newIntent = intent
condition, is_forecast, local_datetime, speakable_location_string, temperature, temperature_unit := weatherParser("what's the weather", botLocation, botUnits)
intentParams = map[string]string{"condition": condition, "is_forecast": is_forecast, "local_datetime": local_datetime, "speakable_location_string": speakable_location_string, "temperature": temperature, "temperature_unit": temperature_unit}
} else {
if intentParam == "" {
newIntent = intent
intentParam = ""
intentParamValue = ""
isParam = false
intentParams = map[string]string{intentParam: intentParamValue}
}
}
if isOpus || botIsEarlyOpus || botPlaySpecific {
if strings.Contains(intent, "intent_play_blackjack") {
isParam = true
newIntent = "intent_play_specific_extend"
intentParam = "entity_behavior"
intentParamValue = "blackjack"
intentParams = map[string]string{intentParam: intentParamValue}
} else if strings.Contains(intent, "intent_play_fistbump") {
isParam = true
newIntent = "intent_play_specific_extend"
intentParam = "entity_behavior"
intentParamValue = "fist_bump"
intentParams = map[string]string{intentParam: intentParamValue}
} else if strings.Contains(intent, "intent_play_rollcube") {
isParam = true
newIntent = "intent_play_specific_extend"
intentParam = "entity_behavior"
intentParamValue = "roll_cube"
intentParams = map[string]string{intentParam: intentParamValue}
} else if strings.Contains(intent, "intent_imperative_praise") {
isParam = false
newIntent = "intent_imperative_affirmative"
intentParam = ""
intentParamValue = ""
intentParams = map[string]string{intentParam: intentParamValue}
} else if strings.Contains(intent, "intent_imperative_love") {
isParam = false
newIntent = "intent_greeting_hello"
intentParam = ""
intentParamValue = ""
intentParams = map[string]string{intentParam: intentParamValue}
} else if strings.Contains(intent, "intent_imperative_abuse") {
isParam = false
newIntent = "intent_imperative_negative"
intentParam = ""
intentParamValue = ""
intentParams = map[string]string{intentParam: intentParamValue}
}
}
IntentPass(req, newIntent, intent, intentParams, isParam)
}
func prehistoricParamChecker(req interface{}, intent string, speechText string, botSerial string) {
// intent.go detects if the stream uses opus or PCM.
// If the stream is PCM, it is likely a bot with 0.10.
// This accounts for the newer 0.10.1### builds.
var intentParam string
var intentParamValue string
var newIntent string
var isParam bool
var intentParams map[string]string
var botLocation string = "San Francisco"
var botUnits string = "F"
if strings.Contains(intent, "intent_photo_take_extend") {
isParam = true
newIntent = intent
if strings.Contains(speechText, lcztn.GetText(lcztn.STR_ME)) || strings.Contains(speechText, lcztn.GetText(lcztn.STR_SELF)) {
intentParam = "entity_photo_selfie"
intentParamValue = "photo_selfie"
} else {
intentParam = "entity_photo_selfie"
intentParamValue = ""
}
intentParams = map[string]string{intentParam: intentParamValue}
} else if strings.Contains(intent, "intent_imperative_eyecolor") {
// leaving stuff like this in case someone wants to add features like this to older software
isParam = true
newIntent = "intent_imperative_eyecolor_specific_extend"
intentParam = "eye_color"
if strings.Contains(speechText, lcztn.GetText(lcztn.STR_EYE_COLOR_PURPLE)) {
intentParamValue = "COLOR_PURPLE"
} else if strings.Contains(speechText, lcztn.GetText(lcztn.STR_EYE_COLOR_BLUE)) || strings.Contains(speechText, lcztn.GetText(lcztn.STR_EYE_COLOR_SAPPHIRE)) {
intentParamValue = "COLOR_BLUE"
} else if strings.Contains(speechText, lcztn.GetText(lcztn.STR_EYE_COLOR_YELLOW)) {
intentParamValue = "COLOR_YELLOW"
} else if strings.Contains(speechText, lcztn.GetText(lcztn.STR_EYE_COLOR_TEAL)) || strings.Contains(speechText, lcztn.GetText(lcztn.STR_EYE_COLOR_TEAL2)) {
intentParamValue = "COLOR_TEAL"
} else if strings.Contains(speechText, lcztn.GetText(lcztn.STR_EYE_COLOR_GREEN)) {
intentParamValue = "COLOR_GREEN"
} else if strings.Contains(speechText, lcztn.GetText(lcztn.STR_EYE_COLOR_ORANGE)) {
intentParamValue = "COLOR_ORANGE"
} else {
newIntent = intent
intentParamValue = ""
isParam = false
}
intentParams = map[string]string{intentParam: intentParamValue}
} else if strings.Contains(intent, "intent_weather_extend") {
isParam = true
newIntent = intent
condition, is_forecast, local_datetime, speakable_location_string, temperature, temperature_unit := weatherParser(speechText, botLocation, botUnits)
intentParams = map[string]string{"condition": condition, "is_forecast": is_forecast, "local_datetime": local_datetime, "speakable_location_string": speakable_location_string, "temperature": temperature, "temperature_unit": temperature_unit}
} else if strings.Contains(intent, "intent_imperative_volumelevel_extend") {
isParam = true
newIntent = intent
if strings.Contains(speechText, lcztn.GetText(lcztn.STR_VOLUME_MEDIUM_LOW)) {
intentParam = "volume_level"
intentParamValue = "VOLUME_2"
} else if strings.Contains(speechText, lcztn.GetText(lcztn.STR_VOLUME_LOW)) || strings.Contains(speechText, lcztn.GetText(lcztn.STR_VOLUME_QUIET)) {
intentParam = "volume_level"
intentParamValue = "VOLUME_1"
} else if strings.Contains(speechText, lcztn.GetText(lcztn.STR_VOLUME_MEDIUM_HIGH)) {
intentParam = "volume_level"
intentParamValue = "VOLUME_4"
} else if strings.Contains(speechText, lcztn.GetText(lcztn.STR_VOLUME_MEDIUM)) || strings.Contains(speechText, lcztn.GetText(lcztn.STR_VOLUME_NORMAL)) || strings.Contains(speechText, lcztn.GetText(lcztn.STR_VOLUME_REGULAR)) {
intentParam = "volume_level"
intentParamValue = "VOLUME_3"
} else if strings.Contains(speechText, lcztn.GetText(lcztn.STR_VOLUME_HIGH)) || strings.Contains(speechText, lcztn.GetText(lcztn.STR_VOLUME_LOUD)) {
intentParam = "volume_level"
intentParamValue = "VOLUME_5"
} else if strings.Contains(speechText, lcztn.GetText(lcztn.STR_VOLUME_MUTE)) || strings.Contains(speechText, lcztn.GetText(lcztn.STR_VOLUME_NOTHING)) || strings.Contains(speechText, lcztn.GetText(lcztn.STR_VOLUME_SILENT)) || strings.Contains(speechText, lcztn.GetText(lcztn.STR_VOLUME_OFF)) || strings.Contains(speechText, lcztn.GetText(lcztn.STR_VOLUME_ZERO)) {
// there is no VOLUME_0 :(
intentParam = "volume_level"
intentParamValue = "VOLUME_1"
} else {
intentParam = "volume_level"
intentParamValue = "VOLUME_1"
}
intentParams = map[string]string{intentParam: intentParamValue}
} else if strings.Contains(intent, "intent_names_username_extend") {
var username string
var nameSplitter string = ""
isParam = true
newIntent = "intent_names_username"
if strings.Contains(speechText, lcztn.GetText(lcztn.STR_NAME_IS)) {
nameSplitter = lcztn.GetText(lcztn.STR_NAME_IS)
} else if strings.Contains(speechText, lcztn.GetText(lcztn.STR_NAME_IS2)) {
nameSplitter = lcztn.GetText(lcztn.STR_NAME_IS2)
} else if strings.Contains(speechText, lcztn.GetText(lcztn.STR_NAME_IS3)) {
nameSplitter = lcztn.GetText(lcztn.STR_NAME_IS3)
}
if nameSplitter != "" {
splitPhrase := strings.SplitAfter(speechText, nameSplitter)
username = strings.TrimSpace(splitPhrase[1])
if len(splitPhrase) == 3 {
username = username + " " + strings.TrimSpace(splitPhrase[2])
} else if len(splitPhrase) == 4 {
username = username + " " + strings.TrimSpace(splitPhrase[2]) + " " + strings.TrimSpace(splitPhrase[3])
} else if len(splitPhrase) > 4 {
username = username + " " + strings.TrimSpace(splitPhrase[2]) + " " + strings.TrimSpace(splitPhrase[3])
}
logger.Println("Name parsed from speech: " + "`" + username + "`")
intentParam = "username"
intentParamValue = username
intentParams = map[string]string{intentParam: intentParamValue}
} else {
logger.Println("No name parsed from speech")
intentParam = "username"
intentParamValue = ""
intentParams = map[string]string{intentParam: intentParamValue}
}
} else if strings.Contains(intent, "intent_clock_settimer_extend") {
isParam = true
newIntent = "intent_clock_settimer"
timerSecs := words2num(speechText)
logger.Println("Seconds parsed from speech: " + timerSecs)
intentParam = "timer_duration"
intentParamValue = timerSecs
intentParams = map[string]string{intentParam: intentParamValue}
} else if strings.Contains(intent, "intent_global_stop_extend") {
isParam = true
newIntent = "intent_global_stop"
intentParam = "what_to_stop"
intentParamValue = "timer"
intentParams = map[string]string{intentParam: intentParamValue}
} else if strings.Contains(intent, "intent_message_playmessage_extend") {
var given_name string
isParam = true
newIntent = "intent_message_playmessage"
intentParam = "given_name"
if strings.Contains(speechText, lcztn.GetText(lcztn.STR_FOR)) {
splitPhrase := strings.SplitAfter(speechText, lcztn.GetText(lcztn.STR_FOR))
given_name = strings.TrimSpace(splitPhrase[1])
if len(splitPhrase) == 3 {
given_name = given_name + " " + strings.TrimSpace(splitPhrase[2])
} else if len(splitPhrase) == 4 {
given_name = given_name + " " + strings.TrimSpace(splitPhrase[2]) + " " + strings.TrimSpace(splitPhrase[3])
} else if len(splitPhrase) > 4 {
given_name = given_name + " " + strings.TrimSpace(splitPhrase[2]) + " " + strings.TrimSpace(splitPhrase[3])
}
intentParamValue = given_name
} else {
intentParamValue = ""
}
intentParams = map[string]string{intentParam: intentParamValue}
} else if strings.Contains(intent, "intent_message_recordmessage_extend") {
var given_name string
isParam = true
newIntent = "intent_message_recordmessage"
intentParam = "given_name"
if strings.Contains(speechText, lcztn.GetText(lcztn.STR_FOR)) {
splitPhrase := strings.SplitAfter(speechText, lcztn.GetText(lcztn.STR_FOR))
given_name = strings.TrimSpace(splitPhrase[1])
if len(splitPhrase) == 3 {
given_name = given_name + " " + strings.TrimSpace(splitPhrase[2])
} else if len(splitPhrase) == 4 {
given_name = given_name + " " + strings.TrimSpace(splitPhrase[2]) + " " + strings.TrimSpace(splitPhrase[3])
} else if len(splitPhrase) > 4 {
given_name = given_name + " " + strings.TrimSpace(splitPhrase[2]) + " " + strings.TrimSpace(splitPhrase[3])
}
intentParamValue = given_name
} else {
intentParamValue = ""
}
intentParams = map[string]string{intentParam: intentParamValue}
} else if strings.Contains(intent, "intent_play_blackjack") {
isParam = true
newIntent = "intent_play_specific_extend"
intentParam = "entity_behavior"
intentParamValue = "blackjack"
intentParams = map[string]string{intentParam: intentParamValue}
} else if strings.Contains(intent, "intent_play_fistbump") {
isParam = true
newIntent = "intent_play_specific_extend"
intentParam = "entity_behavior"
intentParamValue = "fist_bump"
intentParams = map[string]string{intentParam: intentParamValue}
} else if strings.Contains(intent, "intent_play_rollcube") {
isParam = true
newIntent = "intent_play_specific_extend"
intentParam = "entity_behavior"
intentParamValue = "roll_cube"
intentParams = map[string]string{intentParam: intentParamValue}
} else if strings.Contains(intent, "intent_imperative_praise") {
isParam = false
newIntent = "intent_imperative_affirmative"
intentParam = ""
intentParamValue = ""
intentParams = map[string]string{intentParam: intentParamValue}
} else if strings.Contains(intent, "intent_imperative_abuse") {
isParam = false
newIntent = "intent_imperative_negative"
intentParam = ""
intentParamValue = ""
intentParams = map[string]string{intentParam: intentParamValue}
} else {
newIntent = intent
intentParam = ""
intentParamValue = ""
isParam = false
intentParams = map[string]string{intentParam: intentParamValue}
}
IntentPass(req, newIntent, speechText, intentParams, isParam)
}