From 4f5ecbd83875de6e84cbd7125de66be859816488 Mon Sep 17 00:00:00 2001 From: Matthew Faltys Date: Tue, 13 Mar 2018 13:56:05 -0500 Subject: [PATCH] Add .dubs, .newdubs, and .rmdubs --- lorebot/lorebot.go | 50 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/lorebot/lorebot.go b/lorebot/lorebot.go index 3d4a8d1..4066225 100644 --- a/lorebot/lorebot.go +++ b/lorebot/lorebot.go @@ -170,6 +170,12 @@ func dynamicCommandHandler(rtm *slack.RTM, ev *slack.MessageEvent, redisClient * rtm.SendMessage(rtm.NewOutgoingMessage("not proper syntax", ev.Channel)) return } + case "newdubs": + s := strings.SplitN(string(ev.Text), " ", 2) + newdubshandler(rtm, ev, s[1], redisClient) + case "rmdubs": + s := strings.SplitN(string(ev.Text), " ", 2) + rmdubshandler(rtm, ev, s[1], redisClient) case "rmlore": rmhandler(rtm, ev, content, "lore", redisClient) case "rek": @@ -209,6 +215,8 @@ func staticCommandHandler(rtm *slack.RTM, ev *slack.MessageEvent, redisClient *r rnghandler(rtm, ev, redisClient) case "depricatedrng": depricatedrnghandler(rtm, ev, redisClient) + case "dubs": + dubshandler(rtm, ev, redisClient) case "roll": rollhandler(rtm, ev) case "d20": @@ -442,6 +450,48 @@ func newhandler(rtm *slack.RTM, ev *slack.MessageEvent, message, newType string, } } +func newdubshandler(rtm *slack.RTM, ev *slack.MessageEvent, newContent string, redisClient *redis.Client) { + // prep content for dubsification + // aka remove the '<' and '>' that slack adds + newContent = strings.Replace(newContent, "<", "", -1) + newContent = strings.Replace(newContent, ">", "", -1) + + err := redisClient.SAdd("index:dubs", newContent) + if err != nil { + rtm.SendMessage(rtm.NewOutgoingMessage("dubs checked", ev.Channel)) + } else { + rtm.SendMessage(rtm.NewOutgoingMessage("dubs check failed", ev.Channel)) + } +} + +func rmdubshandler(rtm *slack.RTM, ev *slack.MessageEvent, rmContent string, redisClient *redis.Client) { + err := redisClient.SRem("index:dubs", rmContent) + if err != nil { + rtm.SendMessage(rtm.NewOutgoingMessage("dubs unchecked", ev.Channel)) + } else { + rtm.SendMessage(rtm.NewOutgoingMessage("dubs check failed", ev.Channel)) + } +} + +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) + } + // pick a random one + rand.Seed(time.Now().UnixNano()) + rngDubs := fmt.Sprint(command[rand.Intn(len(command))]) + // DEBUG + //println(rngDubs) + rtm.SendMessage(rtm.NewOutgoingMessage(rngDubs, ev.Channel)) + + // roll after we've proccessed dubs + rollhandler(rtm, ev) +} + func rmhandler(rtm *slack.RTM, ev *slack.MessageEvent, message, rmType string, redisClient *redis.Client) { // get nick from slack api user, err := rtm.GetUserInfo(ev.User)