diff options
| author | Christine Dodrill <me@christine.website> | 2018-09-30 14:25:44 -0700 |
|---|---|---|
| committer | Christine Dodrill <me@christine.website> | 2018-09-30 14:25:44 -0700 |
| commit | 51b60f36ac286c973dd258571b77db24e9ace031 (patch) | |
| tree | cdfbfb29a57b4b5ee8b1c83e59b495bdc381aeb0 | |
| parent | e816e3be6d80c30b804de8614cee41c0ce644eea (diff) | |
| download | x-51b60f36ac286c973dd258571b77db24e9ace031.tar.xz x-51b60f36ac286c973dd258571b77db24e9ace031.zip | |
be a discord bot
| -rw-r--r-- | discord/ilo-kesi/context.go | 3 | ||||
| -rw-r--r-- | discord/ilo-kesi/main.go | 11 | ||||
| -rw-r--r-- | discord/ilo-kesi/parse.go | 15 |
3 files changed, 22 insertions, 7 deletions
diff --git a/discord/ilo-kesi/context.go b/discord/ilo-kesi/context.go index 8762bc5..ab9cd43 100644 --- a/discord/ilo-kesi/context.go +++ b/discord/ilo-kesi/context.go @@ -54,7 +54,8 @@ func parseRequest(authorID string, inp tokiponatokens.Sentence) (*Request, error act := strings.Join(part.Tokens, ",") switch act { - case actionFront, actionWhat, actionMarkov: + case actionFront, actionWhat: + case actionMarkov: default: return nil, ErrUnknownAction } diff --git a/discord/ilo-kesi/main.go b/discord/ilo-kesi/main.go index a0f27e9..cda2584 100644 --- a/discord/ilo-kesi/main.go +++ b/discord/ilo-kesi/main.go @@ -80,7 +80,13 @@ func main() { result, err := i.parse(m.Author.ID, m.ContentWithMentionsReplaced()) if err != nil { - s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("mi tawa ala la %v", err)) + switch err { + case ErrJanLawaAla, ErrUnknownAction: + s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("mi ken ala la %v", err)) + return + } + + log.Printf("other error: %s", err) return } @@ -101,7 +107,7 @@ func main() { if *repl { for { - if inp, err := line.Prompt("|: "); err == nil { + if inp, err := line.Prompt("|lipu: "); err == nil { if inp == "" { return } @@ -111,6 +117,7 @@ func main() { result, err := i.parse("console", inp) if err != nil { log.Printf("error: %v", err) + continue } fmt.Println(result.msg) diff --git a/discord/ilo-kesi/parse.go b/discord/ilo-kesi/parse.go index 350bf69..30b9b66 100644 --- a/discord/ilo-kesi/parse.go +++ b/discord/ilo-kesi/parse.go @@ -43,10 +43,6 @@ func (i ilo) parse(authorID, inp string) (*reply, error) { 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 { @@ -55,6 +51,11 @@ func (i ilo) parse(authorID, inp string) (*reply, error) { qual := TimeToQualifier(st.StartedAt) fmt.Fprintf(buf, "%s la jan %s li lawa insa.\n", qual, withinToToki[st.Front]) + goto ok + } + + if !i.janLawaAnuSeme(authorID) { + return nil, ErrJanLawaAla } front := tokiToWithin[req.Subject] @@ -65,19 +66,25 @@ func (i ilo) parse(authorID, inp string) (*reply, error) { } fmt.Fprintf(buf, "tenpo ni la jan %s li lawa insa.\n", req.Subject) + goto ok case actionWhat: switch req.Subject { case "tenpo ni": fmt.Fprintf(buf, "ni li tenpo %s\n", time.Now().Format(time.Kitchen)) + goto ok } } switch req.Subject { case "sitelen pakala": fmt.Fprintf(buf, "%s\n", i.chain.Generate(20)) + goto ok } + + return nil, ErrUnknownAction } +ok: result.msg = buf.String() buf.Reset() |
