diff --git a/lorebot/lorebot.go b/lorebot/lorebot.go index ab0669c..5369a53 100644 --- a/lorebot/lorebot.go +++ b/lorebot/lorebot.go @@ -11,7 +11,8 @@ import ( "net/http" "net/textproto" "os" - "regexp" + //"regexp" + "strconv" "strings" "time" @@ -220,8 +221,6 @@ func staticCommandHandler(rtm *slack.RTM, ev *slack.MessageEvent, redisClient *r dubshandler(rtm, ev, redisClient) case "roll": rollhandler(rtm, ev) - case "d20": - d20handler(rtm, ev) case "rr": rrhandler(rtm, ev) case "dice": @@ -239,6 +238,20 @@ func staticCommandHandler(rtm *slack.RTM, ev *slack.MessageEvent, redisClient *r case "lorestatus": lorestatus(rtm, ev, redisClient) } + + // get that dice handler + if len(ev.Text) >= 2 { + if strings.Contains(ev.Text, ".d") { + trm := strings.Replace(ev.Text, ".d", "", -1) + + // check if the rest of the string is an int + num, err := strconv.Atoi(trm) + if err == nil { + //glogger.Debug.Printf("rolling for %d", num) + dhandler(rtm, ev, num) + } + } + } } func helpmsg(rtm *slack.RTM, ev *slack.MessageEvent) { @@ -328,10 +341,13 @@ func rrhandler(rtm *slack.RTM, ev *slack.MessageEvent) { rtm.SendMessage(rtm.NewOutgoingMessage(rndStr, ev.Channel)) } -func d20handler(rtm *slack.RTM, ev *slack.MessageEvent) { - //fmt.Print(rand.Intn(100)) - rand.Seed(time.Now().UnixNano()) - rtm.SendMessage(rtm.NewOutgoingMessage(fmt.Sprintf("%d", rand.Intn(20)+1), ev.Channel)) +func dhandler(rtm *slack.RTM, ev *slack.MessageEvent, num int) { + if (num > 0) && (num < 99999999) { + rand.Seed(time.Now().UnixNano()) + rtm.SendMessage(rtm.NewOutgoingMessage(fmt.Sprintf("%d", rand.Intn(num)+1), ev.Channel)) + } else { + rtm.SendMessage(rtm.NewOutgoingMessage("na fam, we need a different number. stay lit tho", ev.Channel)) + } } func depricatedrnghandler(rtm *slack.RTM, ev *slack.MessageEvent, redisClient *redis.Client) { @@ -506,15 +522,16 @@ func dubshandler(rtm *slack.RTM, ev *slack.MessageEvent, redisClient *redis.Clie // roll after we've proccessed dubs // you already know tho.. - re := regexp.MustCompile(`taylor|swift|2725225`) - if re.MatchString(rngDubs) { - rndInt := 1 + rand.Intn(10-1) - rndStr := fmt.Sprintf("%06d", rand.Int63n(1e6)) - finStr := fmt.Sprintf("%s%d%d", rndStr, rndInt, rndInt) - rtm.SendMessage(rtm.NewOutgoingMessage(finStr, ev.Channel)) - } else { - rollhandler(rtm, ev) - } + //re := regexp.MustCompile(`taylor|swift|2725225`) + //if re.MatchString(rngDubs) { + // rndInt := 1 + rand.Intn(10-1) + // rndStr := fmt.Sprintf("%06d", rand.Int63n(1e6)) + // finStr := fmt.Sprintf("%s%d%d", rndStr, rndInt, rndInt) + // rtm.SendMessage(rtm.NewOutgoingMessage(finStr, ev.Channel)) + //} else { + // rollhandler(rtm, ev) + //} + rollhandler(rtm, ev) } func rmhandler(rtm *slack.RTM, ev *slack.MessageEvent, message, rmType string, redisClient *redis.Client) {