From 4b3e779872569db4f2bc3d81ad4a4f313768d258 Mon Sep 17 00:00:00 2001 From: Matthew Faltys Date: Tue, 5 Sep 2017 16:45:03 -0500 Subject: [PATCH] Add lore search function --- config.gcfg | 2 +- lorebot/lorebot.go | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/config.gcfg b/config.gcfg index d039490..6ce1952 100644 --- a/config.gcfg +++ b/config.gcfg @@ -1,7 +1,7 @@ [lorebot] loglevel = "debug" bootstrapdelay = 1 - APIToken = "" + APIToken = "xoxb-189788161987-7FK5NKnBtrFGGtv4yszr2URb" [redis] host = "localhost:6379" diff --git a/lorebot/lorebot.go b/lorebot/lorebot.go index 260f061..c3cc4ff 100644 --- a/lorebot/lorebot.go +++ b/lorebot/lorebot.go @@ -70,8 +70,11 @@ Loop: if ev.Text == "test" { rtm.SendMessage(rtm.NewOutgoingMessage("MY NAME IS ..JHEFFFFF", ev.Channel)) } - if strings.Contains(ev.Text, "lore") { - rtm.SendMessage(rtm.NewOutgoingMessage("THA LORE", ev.Channel)) + if strings.Contains(ev.Text, ".lore") { + //rtm.SendMessage(rtm.NewOutgoingMessage("THA LORE", ev.Channel)) + s := strings.SplitN(string(ev.Text), " ", 2) + //command, content := s[0], s[1] + lorehandler(rtm, ev, s[1]) } } case *slack.RTMError: @@ -119,3 +122,9 @@ func initRedisConnection() (*redis.Client, error) { _, redisErr := redisClient.Ping().Result() return redisClient, redisErr } + +func lorehandler(rtm *slack.RTM, ev *slack.MessageEvent, rawMessage string) { + loreTerm := strings.Replace(rawMessage, ".lore", "", -1) + println("searching for:", loreTerm) + rtm.SendMessage(rtm.NewOutgoingMessage(fmt.Sprintf("searching for '%s'\n", loreTerm), ev.Channel)) +}