diff options
| author | Christine Dodrill <me@christine.website> | 2018-09-30 13:32:15 -0700 |
|---|---|---|
| committer | Christine Dodrill <me@christine.website> | 2018-09-30 13:33:02 -0700 |
| commit | e816e3be6d80c30b804de8614cee41c0ce644eea (patch) | |
| tree | 2f9c535ab05de3d97e4f1a5004b261358ba6a5e9 /discord/ilo-kesi/parse.go | |
| parent | b1af575815bdcc05329f3aa92bcaa46b6fb0ada6 (diff) | |
| download | x-e816e3be6d80c30b804de8614cee41c0ce644eea.tar.xz x-e816e3be6d80c30b804de8614cee41c0ce644eea.zip | |
ilo-kesi: prepare for discord
Diffstat (limited to 'discord/ilo-kesi/parse.go')
| -rw-r--r-- | discord/ilo-kesi/parse.go | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/discord/ilo-kesi/parse.go b/discord/ilo-kesi/parse.go new file mode 100644 index 0000000..350bf69 --- /dev/null +++ b/discord/ilo-kesi/parse.go @@ -0,0 +1,85 @@ +package main + +import ( + "bytes" + "context" + "errors" + "fmt" + "time" + + "github.com/Xe/x/web/tokiponatokens" +) + +var ( + ErrNotAddressed = errors.New("ilo-kesi: ilo kesi was not addressed") +) + +func (i ilo) parse(authorID, inp string) (*reply, error) { + var result reply + buf := bytes.NewBuffer(nil) + + parts, err := tokiponatokens.Tokenize(i.cfg.TokiPonaTokenizerAPIURL, inp) + if err != nil { + return nil, err + } + + for _, sent := range parts { + req, err := parseRequest(authorID, sent) + if err != nil { + return nil, err + } + + if len(req.Address) != 2 { + return nil, ErrNotAddressed + } + + if req.Address[0] != "ilo" { + return nil, ErrNotAddressed + } + + if req.Address[1] != i.cfg.IloNimi { + return nil, ErrNotAddressed + } + + switch req.Action { + case actionFront: + if !i.janLawaAnuSeme(authorID) { + return nil, ErrJanLawaAla + } + + if req.Subject == actionWhat { + st, err := i.sw.Status(context.Background()) + if err != nil { + return nil, err + } + + qual := TimeToQualifier(st.StartedAt) + fmt.Fprintf(buf, "%s la jan %s li lawa insa.\n", qual, withinToToki[st.Front]) + } + + front := tokiToWithin[req.Subject] + + _, err := i.sw.Switch(context.Background(), front) + if err != nil { + return nil, err + } + + fmt.Fprintf(buf, "tenpo ni la jan %s li lawa insa.\n", req.Subject) + case actionWhat: + switch req.Subject { + case "tenpo ni": + fmt.Fprintf(buf, "ni li tenpo %s\n", time.Now().Format(time.Kitchen)) + } + } + + switch req.Subject { + case "sitelen pakala": + fmt.Fprintf(buf, "%s\n", i.chain.Generate(20)) + } + } + + result.msg = buf.String() + buf.Reset() + + return &result, nil +} |
