diff --git a/lorebot/lorebot.go b/lorebot/lorebot.go index af449ed..bb89f3e 100644 --- a/lorebot/lorebot.go +++ b/lorebot/lorebot.go @@ -6,6 +6,7 @@ import ( "io" "io/ioutil" "log" + "math/rand" "mime/multipart" "net/http" "net/textproto" @@ -206,6 +207,8 @@ func staticCommandHandler(rtm *slack.RTM, ev *slack.MessageEvent, redisClient *r advancedhelpmsg(rtm, ev) case "rng": rnghandler(rtm, ev, redisClient) + case "betarng": + betarnghandler(rtm, ev, redisClient) case "listen": rtm.SendMessage(rtm.NewOutgoingMessage("*it's what you hearin*", ev.Channel)) case "lorelist": @@ -305,6 +308,29 @@ func rnghandler(rtm *slack.RTM, ev *slack.MessageEvent, redisClient *redis.Clien rtm.SendMessage(rtm.NewOutgoingMessage(rngMsg, ev.Channel)) } +func betarnghandler(rtm *slack.RTM, ev *slack.MessageEvent, redisClient *redis.Client) { + // aka index:command:added + newType := fmt.Sprintf("index:lore:added") + //command, err := botfunc.Query(newType, redisClient) + command, err := loreQuery(newType, redisClient) + if err != nil { + glogger.Error.Println(err) + println(err) + } + rngLore := fmt.Sprint(command[rand.Intn(len(command))]) + println(rngLore) + + // get lore content + rngContent, err := loreCheck(rngLore, "lore", redisClient) + if err != nil { + fmt.Printf("%v\n", err) + rtm.SendMessage(rtm.NewOutgoingMessage("beep boop.. broken bot..", ev.Channel)) + return + } + rngMsg := fmt.Sprintf("Random lore: `%s`\n%s", rngLore, rngContent) + rtm.SendMessage(rtm.NewOutgoingMessage(rngMsg, ev.Channel)) +} + func gnuhandler(rtm *slack.RTM, ev *slack.MessageEvent, target string) { gnuFmt := fmt.Sprintf("slaps the nonfree software out of %s's hands", target) rtm.SendMessage(rtm.NewOutgoingMessage(gnuFmt, ev.Channel))