From 0b619605cd54ad822dd90eb2834049925a403b7e Mon Sep 17 00:00:00 2001 From: Matthew Faltys Date: Mon, 11 Sep 2017 09:38:17 -0500 Subject: [PATCH] Add rng function --- lorebot/lorebot.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lorebot/lorebot.go b/lorebot/lorebot.go index 2ee93e8..376e20a 100644 --- a/lorebot/lorebot.go +++ b/lorebot/lorebot.go @@ -199,7 +199,7 @@ func staticCommandHandler(rtm *slack.RTM, ev *slack.MessageEvent, redisClient *r case "help2": advancedhelpmsg(rtm, ev) case "rng": - rtm.SendMessage(rtm.NewOutgoingMessage("command not yet supported", ev.Channel)) + rnghandler(rtm, ev, redisClient) case "version": rtm.SendMessage(rtm.NewOutgoingMessage("command not yet supported", ev.Channel)) case "lorelist": @@ -269,6 +269,24 @@ func rekhandler(rtm *slack.RTM, ev *slack.MessageEvent, target string, redisClie rtm.SendMessage(rtm.NewOutgoingMessage(rekFmt, ev.Channel)) } +func rnghandler(rtm *slack.RTM, ev *slack.MessageEvent, redisClient *redis.Client) { + // get random lore from list + rngLore, err := redisClient.SRandMember("index:lore:added").Result() + if err != nil { + fmt.Printf("%v\n", err) + } + + // 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))