Browse Source

Add dxx hanlder

develop
Matthew Faltys 7 years ago
parent
commit
db7e379d8c
  1. 45
      lorebot/lorebot.go

45
lorebot/lorebot.go

@ -11,7 +11,8 @@ import (
"net/http" "net/http"
"net/textproto" "net/textproto"
"os" "os"
"regexp" //"regexp"
"strconv"
"strings" "strings"
"time" "time"
@ -220,8 +221,6 @@ func staticCommandHandler(rtm *slack.RTM, ev *slack.MessageEvent, redisClient *r
dubshandler(rtm, ev, redisClient) dubshandler(rtm, ev, redisClient)
case "roll": case "roll":
rollhandler(rtm, ev) rollhandler(rtm, ev)
case "d20":
d20handler(rtm, ev)
case "rr": case "rr":
rrhandler(rtm, ev) rrhandler(rtm, ev)
case "dice": case "dice":
@ -239,6 +238,20 @@ func staticCommandHandler(rtm *slack.RTM, ev *slack.MessageEvent, redisClient *r
case "lorestatus": case "lorestatus":
lorestatus(rtm, ev, redisClient) 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) { 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)) rtm.SendMessage(rtm.NewOutgoingMessage(rndStr, ev.Channel))
} }
func d20handler(rtm *slack.RTM, ev *slack.MessageEvent) { func dhandler(rtm *slack.RTM, ev *slack.MessageEvent, num int) {
//fmt.Print(rand.Intn(100)) if (num > 0) && (num < 99999999) {
rand.Seed(time.Now().UnixNano()) rand.Seed(time.Now().UnixNano())
rtm.SendMessage(rtm.NewOutgoingMessage(fmt.Sprintf("%d", rand.Intn(20)+1), ev.Channel)) 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) { 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 // roll after we've proccessed dubs
// you already know tho.. // you already know tho..
re := regexp.MustCompile(`taylor|swift|2725225`) //re := regexp.MustCompile(`taylor|swift|2725225`)
if re.MatchString(rngDubs) { //if re.MatchString(rngDubs) {
rndInt := 1 + rand.Intn(10-1) // rndInt := 1 + rand.Intn(10-1)
rndStr := fmt.Sprintf("%06d", rand.Int63n(1e6)) // rndStr := fmt.Sprintf("%06d", rand.Int63n(1e6))
finStr := fmt.Sprintf("%s%d%d", rndStr, rndInt, rndInt) // finStr := fmt.Sprintf("%s%d%d", rndStr, rndInt, rndInt)
rtm.SendMessage(rtm.NewOutgoingMessage(finStr, ev.Channel)) // rtm.SendMessage(rtm.NewOutgoingMessage(finStr, ev.Channel))
} else { //} else {
// rollhandler(rtm, ev)
//}
rollhandler(rtm, ev) rollhandler(rtm, ev)
}
} }
func rmhandler(rtm *slack.RTM, ev *slack.MessageEvent, message, rmType string, redisClient *redis.Client) { func rmhandler(rtm *slack.RTM, ev *slack.MessageEvent, message, rmType string, redisClient *redis.Client) {

Loading…
Cancel
Save