diff options
| author | Christine Dodrill <xena@yolo-swag.com> | 2015-08-20 08:34:15 -0700 |
|---|---|---|
| committer | Christine Dodrill <xena@yolo-swag.com> | 2015-08-20 08:34:15 -0700 |
| commit | e95c6ff82eeac4d7e643eed9a67b0401826e392c (patch) | |
| tree | 84655a8c44ac53e03501c6fdb1c7d372ad2786cc /irc/splatbot/handler.go | |
| parent | 0379d786ddbe81ea9cb03a126a5ce560d516c4f9 (diff) | |
| download | x-e95c6ff82eeac4d7e643eed9a67b0401826e392c.tar.xz x-e95c6ff82eeac4d7e643eed9a67b0401826e392c.zip | |
Add splatbot
Diffstat (limited to 'irc/splatbot/handler.go')
| -rw-r--r-- | irc/splatbot/handler.go | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/irc/splatbot/handler.go b/irc/splatbot/handler.go new file mode 100644 index 0000000..51ff843 --- /dev/null +++ b/irc/splatbot/handler.go @@ -0,0 +1,53 @@ +package main + +import ( + "encoding/json" + "io/ioutil" + "log" + "net/http" + "strings" + + "github.com/belak/irc" +) + +func handlePrivmsg(c *irc.Client, e *irc.Event) { + if strings.HasPrefix(e.Trailing(), "!splatoon") { + splatoonLookup(c, e) + } +} + +func splatoonLookup(c *irc.Client, e *irc.Event) { + resp, err := http.Get(url) + if err != nil { + c.Reply(e, "Couldn't look up splatoon maps: %s", err.Error()) + return + } + + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + c.Reply(e, "Couldn't look up splatoon maps: %s", err.Error()) + return + } + + defer resp.Body.Close() + + var sd []SplatoonData + err = json.Unmarshal(body, &sd) + if err != nil { + c.Reply(e, "Couldn't look up splatoon maps: %s", err.Error()) + return + } + + data := sd[0] + + stage1 := data.Stages[0] + stage2 := data.Stages[1] + c.Reply( + e, + "From %s to %s, the stage rotation is %s and %s", + data.DatetimeTermBegin, data.DatetimeTermEnd, + englishIfy(stage1), englishIfy(stage2), + ) + + log.Printf("%s asked me to look up data", e.Identity.Nick) +} |
