From 4f01524e98043ba4e20c10fe883f2d3964e1ee98 Mon Sep 17 00:00:00 2001 From: Matthew Faltys Date: Wed, 14 Mar 2018 14:16:49 -0500 Subject: [PATCH] Add error checking to not trace on empty db --- lorebot/lorebot.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lorebot/lorebot.go b/lorebot/lorebot.go index 81b082b..ab0669c 100644 --- a/lorebot/lorebot.go +++ b/lorebot/lorebot.go @@ -361,6 +361,12 @@ func rnghandler(rtm *slack.RTM, ev *slack.MessageEvent, redisClient *redis.Clien glogger.Error.Println(err) println(err) } + + // if the array is empty, exit early + if len(command) <= 0 { + return + } + // pick a random one rand.Seed(time.Now().UnixNano()) rngLore := fmt.Sprint(command[rand.Intn(len(command))]) @@ -482,11 +488,17 @@ func rmdubshandler(rtm *slack.RTM, ev *slack.MessageEvent, rmContent string, red func dubshandler(rtm *slack.RTM, ev *slack.MessageEvent, redisClient *redis.Client) { // aka index:command:added newType := fmt.Sprintf("index:dubs") - //command, err := botfunc.Query(newType, redisClient) + command, err := loreQuery(newType, redisClient) if err != nil { glogger.Error.Println(err) } + + // if the array is empty, exit early + if len(command) <= 0 { + return + } + // pick a random one rand.Seed(time.Now().UnixNano()) rngDubs := fmt.Sprint(command[rand.Intn(len(command))])