|
|
|
@ -5,12 +5,10 @@ import (
|
|
|
|
|
"fmt" |
|
|
|
|
"io" |
|
|
|
|
"io/ioutil" |
|
|
|
|
"math/rand" |
|
|
|
|
"mime/multipart" |
|
|
|
|
"net/http" |
|
|
|
|
"net/textproto" |
|
|
|
|
"os" |
|
|
|
|
"strconv" |
|
|
|
|
"strings" |
|
|
|
|
"time" |
|
|
|
|
|
|
|
|
@ -23,7 +21,6 @@ import (
|
|
|
|
|
type Config struct { |
|
|
|
|
Lorebot struct { |
|
|
|
|
Loglevel string |
|
|
|
|
SlackDebug bool |
|
|
|
|
BootstrapDelay time.Duration |
|
|
|
|
AuthFile string |
|
|
|
|
} |
|
|
|
@ -64,6 +61,7 @@ func main() {
|
|
|
|
|
auth := lines[0] |
|
|
|
|
|
|
|
|
|
api := slack.New(auth) |
|
|
|
|
//api.SetDebug(true)
|
|
|
|
|
|
|
|
|
|
rtm := api.NewRTM() |
|
|
|
|
go rtm.ManageConnection() |
|
|
|
@ -158,40 +156,16 @@ func dynamicCommandHandler(rtm *slack.RTM, ev *slack.MessageEvent, redisClient *
|
|
|
|
|
contenthandler(rtm, ev, s[1], "lore", redisClient) |
|
|
|
|
case "newlore": |
|
|
|
|
if strings.Contains(content, " ") { |
|
|
|
|
newhandler(rtm, ev, content, "lore", redisClient) |
|
|
|
|
} else { |
|
|
|
|
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 "newlunch": |
|
|
|
|
s := strings.SplitN(string(ev.Text), " ", 2) |
|
|
|
|
newlunchhandler(rtm, ev, s[1], redisClient) |
|
|
|
|
case "rmlunch": |
|
|
|
|
s := strings.SplitN(string(ev.Text), " ", 2) |
|
|
|
|
rmlunchhandler(rtm, ev, s[1], redisClient) |
|
|
|
|
case "newbrb": |
|
|
|
|
s := strings.SplitN(string(ev.Text), " ", 2) |
|
|
|
|
newbrbhandler(rtm, ev, s[1], redisClient) |
|
|
|
|
case "rmbrb": |
|
|
|
|
s := strings.SplitN(string(ev.Text), " ", 2) |
|
|
|
|
rmbrbhandler(rtm, ev, s[1], redisClient) |
|
|
|
|
newhandler(rtm, ev, content, "lore", redisClient) |
|
|
|
|
case "rmlore": |
|
|
|
|
rmhandler(rtm, ev, content, "lore", redisClient) |
|
|
|
|
case "rek": |
|
|
|
|
s := strings.SplitN(string(ev.Text), " ", 2) |
|
|
|
|
rekhandler(rtm, ev, s[1], redisClient) |
|
|
|
|
case "rip": |
|
|
|
|
s := strings.SplitN(string(ev.Text), " ", 2) |
|
|
|
|
riphandler(rtm, ev, s[1]) |
|
|
|
|
case "summon": |
|
|
|
|
s := strings.SplitN(string(ev.Text), " ", 2) |
|
|
|
|
summonhandler(rtm, ev, s[1]) |
|
|
|
|
case "gnu": |
|
|
|
|
s := strings.SplitN(string(ev.Text), " ", 2) |
|
|
|
|
gnuhandler(rtm, ev, s[1]) |
|
|
|
@ -217,29 +191,9 @@ func staticCommandHandler(rtm *slack.RTM, ev *slack.MessageEvent, redisClient *r
|
|
|
|
|
case "help2": |
|
|
|
|
advancedhelpmsg(rtm, ev) |
|
|
|
|
case "rng": |
|
|
|
|
rnghandler(rtm, ev, redisClient) |
|
|
|
|
case "egg": |
|
|
|
|
egghandler(rtm, ev, redisClient) |
|
|
|
|
case "giveup": |
|
|
|
|
giveuphandler(rtm, ev, redisClient) |
|
|
|
|
case "depricatedrng": |
|
|
|
|
depricatedrnghandler(rtm, ev, redisClient) |
|
|
|
|
case "dubs": |
|
|
|
|
dubshandler(rtm, ev, redisClient) |
|
|
|
|
case "lunch": |
|
|
|
|
lunchhandler(rtm, ev, redisClient) |
|
|
|
|
case "brb": |
|
|
|
|
brbhandler(rtm, ev, redisClient) |
|
|
|
|
case "roll": |
|
|
|
|
rollhandler(rtm, ev) |
|
|
|
|
case "rr": |
|
|
|
|
rrhandler(rtm, ev) |
|
|
|
|
case "dice": |
|
|
|
|
dicerollhandler(rtm, ev) |
|
|
|
|
case "ceelo": |
|
|
|
|
ceelorollhandler(rtm, ev) |
|
|
|
|
case "listen": |
|
|
|
|
rtm.SendMessage(rtm.NewOutgoingMessage("*it's what you hearin*", ev.Channel)) |
|
|
|
|
rtm.SendMessage(rtm.NewOutgoingMessage("command not yet supported", ev.Channel)) |
|
|
|
|
case "version": |
|
|
|
|
rtm.SendMessage(rtm.NewOutgoingMessage("command not yet supported", ev.Channel)) |
|
|
|
|
case "lorelist": |
|
|
|
|
listhandler(redisClient, rtm, ev, "lore", "added") |
|
|
|
|
case "removedlore": |
|
|
|
@ -251,20 +205,6 @@ 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) { |
|
|
|
@ -293,7 +233,8 @@ func advancedhelpmsg(rtm *slack.RTM, ev *slack.MessageEvent) {
|
|
|
|
|
|
|
|
|
|
func contenthandler(rtm *slack.RTM, ev *slack.MessageEvent, message, queryType string, redisClient *redis.Client) { |
|
|
|
|
loreTerm := strings.Replace(message, ".lore", "", -1) |
|
|
|
|
glogger.Debug.Printf("searching for: %s\n", loreTerm) |
|
|
|
|
println("searching for:", loreTerm) |
|
|
|
|
//rtm.SendMessage(rtm.NewOutgoingMessage(fmt.Sprintf("searching for '%s'\n", loreTerm), ev.Channel))
|
|
|
|
|
|
|
|
|
|
content, err := loreCheck(loreTerm, queryType, redisClient) |
|
|
|
|
if err == nil { |
|
|
|
@ -320,179 +261,6 @@ func rekhandler(rtm *slack.RTM, ev *slack.MessageEvent, target string, redisClie
|
|
|
|
|
rtm.SendMessage(rtm.NewOutgoingMessage(rekFmt, ev.Channel)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func summonhandler(rtm *slack.RTM, ev *slack.MessageEvent, target string) { |
|
|
|
|
sumFmt := fmt.Sprintf("つ◕_◕)つ %s つ◕_◕)つ", target) |
|
|
|
|
rtm.SendMessage(rtm.NewOutgoingMessage(sumFmt, ev.Channel)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func riphandler(rtm *slack.RTM, ev *slack.MessageEvent, target string) { |
|
|
|
|
// create a timestamp to use
|
|
|
|
|
t := time.Now() |
|
|
|
|
tstamp := t.Format("01-02-2006") |
|
|
|
|
ripFmt := fmt.Sprintf("here lies %s, disrespected to death %s..", target, tstamp) |
|
|
|
|
rtm.SendMessage(rtm.NewOutgoingMessage(ripFmt, ev.Channel)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func rollhandler(rtm *slack.RTM, ev *slack.MessageEvent) { |
|
|
|
|
//fmt.Print(rand.Intn(100))
|
|
|
|
|
rndStr := fmt.Sprintf("%08d", rand.Int63n(1e8)) |
|
|
|
|
rtm.SendMessage(rtm.NewOutgoingMessage(rndStr, ev.Channel)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func dicerollhandler(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(6)+1), ev.Channel)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func ceelorollhandler(rtm *slack.RTM, ev *slack.MessageEvent) { |
|
|
|
|
rand.Seed(time.Now().UnixNano()) |
|
|
|
|
|
|
|
|
|
// set condition
|
|
|
|
|
hand := false |
|
|
|
|
|
|
|
|
|
for !hand { |
|
|
|
|
roll0 := rand.Intn(6) + 1 |
|
|
|
|
roll1 := rand.Intn(6) + 1 |
|
|
|
|
roll2 := rand.Intn(6) + 1 |
|
|
|
|
|
|
|
|
|
rtm.SendMessage(rtm.NewOutgoingMessage(fmt.Sprintf("%d, %d, %d", roll0, roll1, roll2), ev.Channel)) |
|
|
|
|
|
|
|
|
|
// check for pair
|
|
|
|
|
if (roll0 == roll1) || (roll0 == roll2) || (roll1 == roll2) { |
|
|
|
|
hand = true |
|
|
|
|
} |
|
|
|
|
a := fmt.Sprintf("%d%d%d", roll0, roll1, roll2) |
|
|
|
|
// check for instant win
|
|
|
|
|
if strings.Contains(a, "4") && strings.Contains(a, "5") && strings.Contains(a, "6") { |
|
|
|
|
hand = true |
|
|
|
|
} |
|
|
|
|
// check for instant loss
|
|
|
|
|
if strings.Contains(a, "1") && strings.Contains(a, "2") && strings.Contains(a, "3") { |
|
|
|
|
hand = true |
|
|
|
|
} |
|
|
|
|
time.Sleep(1000 * time.Millisecond) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func rrhandler(rtm *slack.RTM, ev *slack.MessageEvent) { |
|
|
|
|
//fmt.Print(rand.Intn(100))
|
|
|
|
|
dice := []string{"*click*", "*BANG*", "*click*", "*click*", "*click*", "*click*"} |
|
|
|
|
rand.Seed(time.Now().UnixNano()) |
|
|
|
|
rndStr := dice[rand.Intn(len(dice)-1)] |
|
|
|
|
|
|
|
|
|
rtm.SendMessage(rtm.NewOutgoingMessage(rndStr, 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) { |
|
|
|
|
// 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 rnghandler(rtm *slack.RTM, ev *slack.MessageEvent, redisClient *redis.Client) { |
|
|
|
|
// aka index:command:added
|
|
|
|
|
newType := fmt.Sprintf("index:lore:added") |
|
|
|
|
//command, err := botfunc.Query(newType, redisClient)
|
|
|
|
|
command, err := loreQuery(newType, redisClient) |
|
|
|
|
if err != nil { |
|
|
|
|
glogger.Error.Println(err) |
|
|
|
|
println(err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// if the array is empty, exit early
|
|
|
|
|
if len(command) <= 0 { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// pick a random one
|
|
|
|
|
rand.Seed(time.Now().UnixNano()) |
|
|
|
|
rngLore := fmt.Sprint(command[rand.Intn(len(command))]) |
|
|
|
|
glogger.Debug.Printf("rng lore: %s\n", rngLore) |
|
|
|
|
|
|
|
|
|
// get lore content
|
|
|
|
|
rngContent, err := loreCheck(rngLore, "lore", redisClient) |
|
|
|
|
if err != nil { |
|
|
|
|
glogger.Error.Printf("%v\n", err) |
|
|
|
|
rtm.SendMessage(rtm.NewOutgoingMessage("beep boop.. broken bot..", ev.Channel)) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
glogger.Debug.Printf("rng content: %s\n", rngContent) |
|
|
|
|
rngMsg := fmt.Sprintf("Random lore: `%s`\n%s", rngLore, rngContent) |
|
|
|
|
rtm.SendMessage(rtm.NewOutgoingMessage(rngMsg, ev.Channel)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func egghandler(rtm *slack.RTM, ev *slack.MessageEvent, redisClient *redis.Client) { |
|
|
|
|
// aka index:command:added
|
|
|
|
|
newType := fmt.Sprintf("index:lore:added") |
|
|
|
|
//command, err := botfunc.Query(newType, redisClient)
|
|
|
|
|
command, err := loreQuery(newType, redisClient) |
|
|
|
|
if err != nil { |
|
|
|
|
glogger.Error.Println(err) |
|
|
|
|
println(err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// if the array is empty, exit early
|
|
|
|
|
if len(command) <= 0 { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// pick a random one
|
|
|
|
|
rand.Seed(time.Now().UnixNano()) |
|
|
|
|
rngLore := fmt.Sprint(command[rand.Intn(len(command))]) |
|
|
|
|
println(rngLore) |
|
|
|
|
|
|
|
|
|
// 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 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// set the lore in case we cant find it.
|
|
|
|
|
redisClient.Del("index:egg") |
|
|
|
|
err = redisClient.Set("index:egg", rngLore, 0).Err() |
|
|
|
|
if err != nil { |
|
|
|
|
glogger.Error.Println("error updating redis egg index") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
rngMsg := fmt.Sprintf("begin the hunt boiiz...\n ```%s```", rngContent) |
|
|
|
|
rtm.SendMessage(rtm.NewOutgoingMessage(rngMsg, ev.Channel)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func giveuphandler(rtm *slack.RTM, ev *slack.MessageEvent, redisClient *redis.Client) { |
|
|
|
|
giveup, err := redisClient.Get("index:egg").Result() |
|
|
|
|
if err != nil { |
|
|
|
|
glogger.Error.Println("error getting redis egg index") |
|
|
|
|
glogger.Error.Println(err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
giveupMsg := fmt.Sprintf("foolz.. it was `%s`", giveup) |
|
|
|
|
rtm.SendMessage(rtm.NewOutgoingMessage(giveupMsg, 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)) |
|
|
|
@ -507,7 +275,8 @@ func listhandler(redisClient *redis.Client, rtm *slack.RTM, ev *slack.MessageEve
|
|
|
|
|
glogger.Error.Println(err) |
|
|
|
|
println(err) |
|
|
|
|
} |
|
|
|
|
fCommand := strings.Join(command, "\n") |
|
|
|
|
fCommand := strings.Replace(command, " ", "\n", -1) |
|
|
|
|
fCommand = strings.Replace(fCommand, "\n", "", 1) |
|
|
|
|
|
|
|
|
|
// initialize buffer
|
|
|
|
|
bodyBuf := &bytes.Buffer{} |
|
|
|
@ -545,8 +314,8 @@ func listhandler(redisClient *redis.Client, rtm *slack.RTM, ev *slack.MessageEve
|
|
|
|
|
|
|
|
|
|
func lorestatus(rtm *slack.RTM, ev *slack.MessageEvent, redisClient *redis.Client) { |
|
|
|
|
command, _ := loreQuery("index:lore:added", redisClient) |
|
|
|
|
loreammount := len(command) |
|
|
|
|
status := fmt.Sprintf("the lore db has %d entries", loreammount) |
|
|
|
|
loreammount := strings.Count(command, " ") |
|
|
|
|
status := fmt.Sprintf("the lore db has %d entries", loreammount-1) |
|
|
|
|
rtm.SendMessage(rtm.NewOutgoingMessage(status, ev.Channel)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -567,163 +336,6 @@ 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) { |
|
|
|
|
// 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) |
|
|
|
|
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 := loreQuery(newType, redisClient) |
|
|
|
|
if err != nil { |
|
|
|
|
glogger.Error.Println(err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// if the array is empty, exit early
|
|
|
|
|
if len(command) <= 0 { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// pick a random one
|
|
|
|
|
rand.Seed(time.Now().UnixNano()) |
|
|
|
|
rngDubs := fmt.Sprint(command[rand.Intn(len(command))]) |
|
|
|
|
rtm.SendMessage(rtm.NewOutgoingMessage(rngDubs, ev.Channel)) |
|
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
|
//}
|
|
|
|
|
rollhandler(rtm, ev) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func newlunchhandler(rtm *slack.RTM, ev *slack.MessageEvent, newContent string, redisClient *redis.Client) { |
|
|
|
|
// prep content for lunchification
|
|
|
|
|
// aka remove the '<' and '>' that slack adds
|
|
|
|
|
newContent = strings.Replace(newContent, "<", "", -1) |
|
|
|
|
newContent = strings.Replace(newContent, ">", "", -1) |
|
|
|
|
|
|
|
|
|
err := redisClient.SAdd("index:lunch", newContent) |
|
|
|
|
if err != nil { |
|
|
|
|
rtm.SendMessage(rtm.NewOutgoingMessage("lunch location added", ev.Channel)) |
|
|
|
|
} else { |
|
|
|
|
rtm.SendMessage(rtm.NewOutgoingMessage("lunch location addition failed", ev.Channel)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func rmlunchhandler(rtm *slack.RTM, ev *slack.MessageEvent, rmContent string, redisClient *redis.Client) { |
|
|
|
|
// prep content for lunch removal
|
|
|
|
|
// aka remove the '<' and '>' that slack adds
|
|
|
|
|
rmContent = strings.Replace(rmContent, "<", "", -1) |
|
|
|
|
rmContent = strings.Replace(rmContent, ">", "", -1) |
|
|
|
|
|
|
|
|
|
err := redisClient.SRem("index:lunch", rmContent) |
|
|
|
|
if err != nil { |
|
|
|
|
rtm.SendMessage(rtm.NewOutgoingMessage("lunch location removed", ev.Channel)) |
|
|
|
|
} else { |
|
|
|
|
rtm.SendMessage(rtm.NewOutgoingMessage("lunch location removal failed", ev.Channel)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func lunchhandler(rtm *slack.RTM, ev *slack.MessageEvent, redisClient *redis.Client) { |
|
|
|
|
// aka index:command:added
|
|
|
|
|
newType := fmt.Sprintf("index:lunch") |
|
|
|
|
|
|
|
|
|
command, err := loreQuery(newType, redisClient) |
|
|
|
|
if err != nil { |
|
|
|
|
glogger.Error.Println(err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// if the array is empty, exit early
|
|
|
|
|
if len(command) <= 0 { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// pick a random one
|
|
|
|
|
rand.Seed(time.Now().UnixNano()) |
|
|
|
|
rngDubs := fmt.Sprint(command[rand.Intn(len(command))]) |
|
|
|
|
rtm.SendMessage(rtm.NewOutgoingMessage(rngDubs, ev.Channel)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func newbrbhandler(rtm *slack.RTM, ev *slack.MessageEvent, newContent string, redisClient *redis.Client) { |
|
|
|
|
// prep content for brbification
|
|
|
|
|
// aka remove the '<' and '>' that slack adds
|
|
|
|
|
newContent = strings.Replace(newContent, "<", "", -1) |
|
|
|
|
newContent = strings.Replace(newContent, ">", "", -1) |
|
|
|
|
|
|
|
|
|
err := redisClient.SAdd("index:brb", newContent) |
|
|
|
|
if err != nil { |
|
|
|
|
rtm.SendMessage(rtm.NewOutgoingMessage("tjancism added", ev.Channel)) |
|
|
|
|
} else { |
|
|
|
|
rtm.SendMessage(rtm.NewOutgoingMessage("tjanceism addition failed", ev.Channel)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func rmbrbhandler(rtm *slack.RTM, ev *slack.MessageEvent, rmContent string, redisClient *redis.Client) { |
|
|
|
|
// prep content for brb removal
|
|
|
|
|
// aka remove the '<' and '>' that slack adds
|
|
|
|
|
rmContent = strings.Replace(rmContent, "<", "", -1) |
|
|
|
|
rmContent = strings.Replace(rmContent, ">", "", -1) |
|
|
|
|
|
|
|
|
|
err := redisClient.SRem("index:brb", rmContent) |
|
|
|
|
if err != nil { |
|
|
|
|
rtm.SendMessage(rtm.NewOutgoingMessage("tjancism removed", ev.Channel)) |
|
|
|
|
} else { |
|
|
|
|
rtm.SendMessage(rtm.NewOutgoingMessage("tjancism removal failed", ev.Channel)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func brbhandler(rtm *slack.RTM, ev *slack.MessageEvent, redisClient *redis.Client) { |
|
|
|
|
// aka index:command:added
|
|
|
|
|
newType := fmt.Sprintf("index:brb") |
|
|
|
|
|
|
|
|
|
command, err := loreQuery(newType, redisClient) |
|
|
|
|
if err != nil { |
|
|
|
|
glogger.Error.Println(err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// if the array is empty, exit early
|
|
|
|
|
if len(command) <= 0 { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// pick a random one
|
|
|
|
|
rand.Seed(time.Now().UnixNano()) |
|
|
|
|
rngDubs := fmt.Sprint(command[rand.Intn(len(command))]) |
|
|
|
|
rtm.SendMessage(rtm.NewOutgoingMessage(rngDubs, ev.Channel)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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) |
|
|
|
|