From 65ddb3d48cf38fe5426225b3af83136cb00bd982 Mon Sep 17 00:00:00 2001 From: Matthew Faltys Date: Wed, 6 Sep 2017 21:53:47 -0500 Subject: [PATCH] Fix nick parsing to be more efficient --- lorebot/lorebot.go | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/lorebot/lorebot.go b/lorebot/lorebot.go index 4d4c465..472dd22 100644 --- a/lorebot/lorebot.go +++ b/lorebot/lorebot.go @@ -136,16 +136,6 @@ func initRedisConnection() (*redis.Client, error) { } func dynamicCommandHandler(rtm *slack.RTM, ev *slack.MessageEvent, redisClient *redis.Client) { - //nick := ev.User - //fmt.Printf("%s", ev.User) - user, err := rtm.GetUserInfo(ev.User) - if err != nil { - fmt.Printf("%s\n", err) - return - } - println(user.Name) - nick := fmt.Sprintf("%s", user.Name) - message := ev.Text if strings.Count(message, " ") < 1 { glogger.Debug.Println("not proper syntax") @@ -166,7 +156,7 @@ func dynamicCommandHandler(rtm *slack.RTM, ev *slack.MessageEvent, redisClient * rtm.SendMessage(rtm.NewOutgoingMessage("not proper syntax", ev.Channel)) return } - newhandler(rtm, ev, nick, content, "lore", redisClient) + newhandler(rtm, ev, content, "lore", redisClient) case "rmlore": rtm.SendMessage(rtm.NewOutgoingMessage("command not yet supported", ev.Channel)) case "rek": @@ -388,8 +378,16 @@ func lorestatus(rtm *slack.RTM, ev *slack.MessageEvent, redisClient *redis.Clien rtm.SendMessage(rtm.NewOutgoingMessage(status, ev.Channel)) } -func newhandler(rtm *slack.RTM, ev *slack.MessageEvent, nick, message, newType string, redisClient *redis.Client) { - err := loreNewString(nick, message, newType, redisClient) +func newhandler(rtm *slack.RTM, ev *slack.MessageEvent, message, newType string, redisClient *redis.Client) { + // get nick from slack api + user, err := rtm.GetUserInfo(ev.User) + if err != nil { + fmt.Printf("%s\n", err) + return + } + nick := fmt.Sprintf("%s", user.Name) + + err = loreNewString(nick, message, newType, redisClient) if err == nil { rtm.SendMessage(rtm.NewOutgoingMessage("entry created", ev.Channel)) } else {