|
|
|
@ -62,28 +62,15 @@ Loop:
|
|
|
|
|
select { |
|
|
|
|
case msg := <-rtm.IncomingEvents: |
|
|
|
|
switch ev := msg.Data.(type) { |
|
|
|
|
//case *slack.ConnectedEvent:
|
|
|
|
|
// //botId = ev.Info.User.ID
|
|
|
|
|
//case *slack.TeamJoinEvent:
|
|
|
|
|
// // Handle new user to client
|
|
|
|
|
case *slack.MessageEvent: |
|
|
|
|
if ev.Type == "message" { |
|
|
|
|
//if ev.Text == "test" {
|
|
|
|
|
// rtm.SendMessage(rtm.NewOutgoingMessage("MY NAME IS ..JHEFFFFF", ev.Channel))
|
|
|
|
|
//}
|
|
|
|
|
//if strings.Contains(ev.Text, ".lore") {
|
|
|
|
|
// //rtm.SendMessage(rtm.NewOutgoingMessage("THA LORE", ev.Channel))
|
|
|
|
|
// s := strings.SplitN(string(ev.Text), " ", 2)
|
|
|
|
|
// //command, content := s[0], s[1]
|
|
|
|
|
// lorehandler(redisClient, rtm, ev, s[1])
|
|
|
|
|
//}
|
|
|
|
|
//if strings.Contains(ev.Text, ".help") {
|
|
|
|
|
// helpmsg(rtm, ev)
|
|
|
|
|
//}
|
|
|
|
|
//if strings.Contains(ev.Text, ".help2") {
|
|
|
|
|
// helpmsg(rtm, ev)
|
|
|
|
|
//}
|
|
|
|
|
glogger.Debug.Printf("processing: %s", ev.Text) |
|
|
|
|
// see if the message begins with '.', it could be a command
|
|
|
|
|
if len(ev.Text) == 0 { |
|
|
|
|
// nil message, dont print
|
|
|
|
|
//glogger.Debug.Println("breaking on blank message")
|
|
|
|
|
break |
|
|
|
|
} else { |
|
|
|
|
comm := fmt.Sprintf("%c", ev.Text[0]) |
|
|
|
|
if comm == "." { |
|
|
|
|
if strings.Count(ev.Text, " ") == 0 { |
|
|
|
@ -95,12 +82,14 @@ Loop:
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
case *slack.RTMError: |
|
|
|
|
fmt.Printf("Error: %s\n", ev.Error()) |
|
|
|
|
case *slack.InvalidAuthEvent: |
|
|
|
|
fmt.Printf("Invalid credentials") |
|
|
|
|
break Loop |
|
|
|
|
default: |
|
|
|
|
// ignore all other events
|
|
|
|
|
//fmt.Printf("Unknown error")
|
|
|
|
|
//fmt.Printf("%v\n", msg.Data)
|
|
|
|
|
} |
|
|
|
@ -162,7 +151,8 @@ func dynamicCommandHandler(rtm *slack.RTM, ev *slack.MessageEvent, redisClient *
|
|
|
|
|
case "rmlore": |
|
|
|
|
rtm.SendMessage(rtm.NewOutgoingMessage("command not yet supported", ev.Channel)) |
|
|
|
|
case "rek": |
|
|
|
|
rtm.SendMessage(rtm.NewOutgoingMessage("command not yet supported", ev.Channel)) |
|
|
|
|
s := strings.SplitN(string(ev.Text), " ", 2) |
|
|
|
|
rekhandler(redisClient, rtm, ev, s[1]) |
|
|
|
|
case "created": |
|
|
|
|
rtm.SendMessage(rtm.NewOutgoingMessage("command not yet supported", ev.Channel)) |
|
|
|
|
case "owner": |
|
|
|
@ -236,6 +226,12 @@ func lorehandler(redisClient *redis.Client, rtm *slack.RTM, ev *slack.MessageEve
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func rekhandler(redisClient *redis.Client, rtm *slack.RTM, ev *slack.MessageEvent, target string) { |
|
|
|
|
rektBit, _ := redisClient.SRandMember("index:rekt").Result() |
|
|
|
|
rekFmt := fmt.Sprintf("%s %s", target, rektBit) |
|
|
|
|
rtm.SendMessage(rtm.NewOutgoingMessage(rekFmt, ev.Channel)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func checkLore(searchTerm string, redisClient *redis.Client) (string, error) { |
|
|
|
|
val, err := redisClient.Get(fmt.Sprintf("lore:%s:content", searchTerm)).Result() |
|
|
|
|
if err != nil { |
|
|
|
|