diff options
| author | Christine Dodrill <me@christine.website> | 2018-09-23 16:34:54 -0700 |
|---|---|---|
| committer | Christine Dodrill <me@christine.website> | 2018-09-23 16:34:54 -0700 |
| commit | 5465d4cdeacd15050e6ce2d21959f217c672b464 (patch) | |
| tree | e5099630956e39ed8ab51b85f11d26c1b7a72814 | |
| parent | fe760ddbdc36008cb1747fcfb742072e5240cdd6 (diff) | |
| download | x-5465d4cdeacd15050e6ce2d21959f217c672b464.tar.xz x-5465d4cdeacd15050e6ce2d21959f217c672b464.zip | |
discord/ilo-kesi: implement switching, time
| -rw-r--r-- | discord/ilo-kesi/.gitignore | 1 | ||||
| -rw-r--r-- | discord/ilo-kesi/context.go | 14 | ||||
| -rw-r--r-- | discord/ilo-kesi/main.go | 28 | ||||
| -rw-r--r-- | discord/ilo-kesi/toki_pona.go | 18 | ||||
| -rw-r--r-- | discord/ilo-kesi/within.go | 8 |
5 files changed, 60 insertions, 9 deletions
diff --git a/discord/ilo-kesi/.gitignore b/discord/ilo-kesi/.gitignore new file mode 100644 index 0000000..1e74762 --- /dev/null +++ b/discord/ilo-kesi/.gitignore @@ -0,0 +1 @@ +ilo-kesi
\ No newline at end of file diff --git a/discord/ilo-kesi/context.go b/discord/ilo-kesi/context.go index 069bd8b..c46471d 100644 --- a/discord/ilo-kesi/context.go +++ b/discord/ilo-kesi/context.go @@ -7,6 +7,7 @@ import ( const ( actionFront = "lawa,insa" + actionWhat = "seme" ) var ( @@ -16,7 +17,7 @@ var ( type Request struct { Address []*part Action string - Subject *string // if null, user is asking for the info + Subject string // if null, user is asking for the info Punct string } @@ -28,15 +29,18 @@ func parseRequest(inp Sentence) (*Request, error) { case partAddress: result.Address = part.Parts case partSubject: - if len(part.Tokens) == 1 && part.Tokens[0] != "seme" { - sub := strings.Join(part.Tokens, ",") - result.Subject = &sub + if len(part.Tokens) == 0 { + sub := strings.Title(strings.Join(part.Parts[1].Tokens, "")) + result.Subject = sub + } else { + sub := strings.Join(part.Tokens, " ") + result.Subject = sub } case partObjectMarker: act := strings.Join(part.Tokens, ",") switch act { - case actionFront: + case actionFront, actionWhat: default: return nil, ErrUnknownAction } diff --git a/discord/ilo-kesi/main.go b/discord/ilo-kesi/main.go index 1bc12bc..0d4f325 100644 --- a/discord/ilo-kesi/main.go +++ b/discord/ilo-kesi/main.go @@ -50,6 +50,8 @@ func main() { log.Printf("Can't parse: %v", err) } + //pretty.Println(parts) + for _, sent := range parts { req, err := parseRequest(sent) if err != nil { @@ -57,22 +59,40 @@ func main() { continue } + if req.Address == nil { + log.Println("ilo Kesi was not addressed") + continue + } + switch req.Action { case actionFront: - if req.Subject == nil { + if req.Subject == actionWhat { st, err := sw.Status(context.Background()) if err != nil { log.Printf("status error: %v", err) continue } - fmt.Printf("ilo Kesi\\ jan %s li lawa insa.\n", withinToToki[st.Front]) + qual := TimeToQualifier(st.StartedAt) + fmt.Printf("ilo Kesi\\ %s la jan %s li lawa insa.\n", qual, withinToToki[st.Front]) - log.Printf("Started at: %s (%s ago)", st.StartedAt, time.Since(st.StartedAt)) continue } - log.Printf("setting front not implemented yet :(") + front := tokiToWithin[req.Subject] + + _, err := sw.Switch(context.Background(), front) + if err != nil { + log.Printf("switch error: %v", err) + continue + } + + fmt.Printf("ijo Kesi\\ tenpo ni la jan %s li lawa insa.\n", req.Subject) + case actionWhat: + switch req.Subject { + case "tenpo ni": + fmt.Printf("ilo Kesi\\ ni li tenpo %s\n", time.Now().Format(time.Kitchen)) + } } } } else if err == liner.ErrPromptAborted { diff --git a/discord/ilo-kesi/toki_pona.go b/discord/ilo-kesi/toki_pona.go index 9f027d2..d1ade93 100644 --- a/discord/ilo-kesi/toki_pona.go +++ b/discord/ilo-kesi/toki_pona.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/json" "net/http" + "time" ) type part struct { @@ -54,3 +55,20 @@ func TokenizeTokiPona(aurl, text string) ([]Sentence, error) { return result, nil } + +func TimeToQualifier(t time.Time) string { + const ( + nowRange = 15 * time.Minute + ) + + s := time.Since(t) + if s > 0 { + return "tenpo kama" + } + + if s < nowRange { + return "tenpo ni" + } + + return "tenpo pini" +} diff --git a/discord/ilo-kesi/within.go b/discord/ilo-kesi/within.go index 048a2de..1b4d291 100644 --- a/discord/ilo-kesi/within.go +++ b/discord/ilo-kesi/within.go @@ -1,5 +1,13 @@ package main +var tokiToWithin = map[string]string{ + "Kesi": "Cadey", + "Liso": "Nicole", + "Lesi": "Jessie", + "Sesi": "Sephie", + "Ase": "Ashe", +} + var withinToToki = map[string]string{ "Cadey": "Kesi", "Nicole": "Liso", |
