Browse Source

Fix rmlore parsing wrong slack url

develop
Matthew Faltys 7 years ago
parent
commit
9bbdc048cc
  1. 19
      lorebot/lorebot.go

19
lorebot/lorebot.go

@ -11,6 +11,7 @@ import (
"net/http" "net/http"
"net/textproto" "net/textproto"
"os" "os"
"regexp"
"strings" "strings"
"time" "time"
@ -465,6 +466,11 @@ func newdubshandler(rtm *slack.RTM, ev *slack.MessageEvent, newContent string, r
} }
func rmdubshandler(rtm *slack.RTM, ev *slack.MessageEvent, rmContent string, redisClient *redis.Client) { func rmdubshandler(rtm *slack.RTM, ev *slack.MessageEvent, rmContent string, redisClient *redis.Client) {
// prep content for dubs removal
// aka remove the '<' and '>' that slack adds
rmContent = strings.Replace(rmContent, "<", "", -1)
rmContent = strings.Replace(rmContent, ">", "", -1)
err := redisClient.SRem("index:dubs", rmContent) err := redisClient.SRem("index:dubs", rmContent)
if err != nil { if err != nil {
rtm.SendMessage(rtm.NewOutgoingMessage("dubs unchecked", ev.Channel)) rtm.SendMessage(rtm.NewOutgoingMessage("dubs unchecked", ev.Channel))
@ -484,12 +490,19 @@ func dubshandler(rtm *slack.RTM, ev *slack.MessageEvent, redisClient *redis.Clie
// pick a random one // pick a random one
rand.Seed(time.Now().UnixNano()) rand.Seed(time.Now().UnixNano())
rngDubs := fmt.Sprint(command[rand.Intn(len(command))]) rngDubs := fmt.Sprint(command[rand.Intn(len(command))])
// DEBUG
//println(rngDubs)
rtm.SendMessage(rtm.NewOutgoingMessage(rngDubs, ev.Channel)) rtm.SendMessage(rtm.NewOutgoingMessage(rngDubs, ev.Channel))
// roll after we've proccessed dubs // roll after we've proccessed dubs
rollhandler(rtm, ev) // 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)
}
} }
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