-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcortex.go
More file actions
65 lines (56 loc) · 1.25 KB
/
cortex.go
File metadata and controls
65 lines (56 loc) · 1.25 KB
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
package cortex
import (
"log"
"math/rand"
"time"
"github.com/itsabot/abot/shared/datatypes"
"github.com/itsabot/abot/shared/nlp"
"github.com/itsabot/abot/shared/plugin"
)
type weatherJSON struct {
Description []string
Temp float64
Humidity int
}
var p *dt.Plugin
func init() {
rand.Seed(time.Now().UnixNano())
trigger := &nlp.StructuredInput{
Commands: []string{"who"},
Objects: []string{"you"},
}
fns := &dt.PluginFns{Run: Run, FollowUp: FollowUp}
var err error
p, err = plugin.New("github.com/crazytweek/plugin_cortex", trigger, fns)
if err != nil {
log.Fatal(err)
}
p.Vocab = dt.NewVocab(
dt.VocabHandler{
Fn: kwIAm,
Trigger: &nlp.StructuredInput{
Commands: []string{"who"},
Objects: []string{"you"},
},
},
)
}
func Run(in *dt.Msg) (string, error) {
return FollowUp(in)
}
func FollowUp(in *dt.Msg) (string, error) {
return p.Vocab.HandleKeywords(in), nil
}
func kwIAm(in *dt.Msg) (resp string) {
return "I am Jet, your personal assistant!"
}
func buildStateMachine(in *dt.Msg) *dt.StateMachine {
sm := dt.NewStateMachine(p)
sm.SetStates([]dt.State{})
sm.LoadState(in)
return sm
}
func er(err error) string {
p.Log.Debug(err)
return "Something went wrong, but I'll try to get that fixed right away."
}