Browse Source

Fix nil message bug

Add rek command
master
Matthew Faltys 7 years ago
parent
commit
660b809679
  1. 36
      lorebot/lorebot.go

36
lorebot/lorebot.go

@ -62,28 +62,15 @@ Loop:
select { select {
case msg := <-rtm.IncomingEvents: case msg := <-rtm.IncomingEvents:
switch ev := msg.Data.(type) { switch ev := msg.Data.(type) {
//case *slack.ConnectedEvent:
// //botId = ev.Info.User.ID
//case *slack.TeamJoinEvent:
// // Handle new user to client
case *slack.MessageEvent: case *slack.MessageEvent:
if ev.Type == "message" { if ev.Type == "message" {
//if ev.Text == "test" { glogger.Debug.Printf("processing: %s", ev.Text)
// 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)
//}
// see if the message begins with '.', it could be a command // 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]) comm := fmt.Sprintf("%c", ev.Text[0])
if comm == "." { if comm == "." {
if strings.Count(ev.Text, " ") == 0 { if strings.Count(ev.Text, " ") == 0 {
@ -95,12 +82,14 @@ Loop:
} }
} }
} }
}
case *slack.RTMError: case *slack.RTMError:
fmt.Printf("Error: %s\n", ev.Error()) fmt.Printf("Error: %s\n", ev.Error())
case *slack.InvalidAuthEvent: case *slack.InvalidAuthEvent:
fmt.Printf("Invalid credentials") fmt.Printf("Invalid credentials")
break Loop break Loop
default: default:
// ignore all other events
//fmt.Printf("Unknown error") //fmt.Printf("Unknown error")
//fmt.Printf("%v\n", msg.Data) //fmt.Printf("%v\n", msg.Data)
} }
@ -162,7 +151,8 @@ func dynamicCommandHandler(rtm *slack.RTM, ev *slack.MessageEvent, redisClient *
case "rmlore": case "rmlore":
rtm.SendMessage(rtm.NewOutgoingMessage("command not yet supported", ev.Channel)) rtm.SendMessage(rtm.NewOutgoingMessage("command not yet supported", ev.Channel))
case "rek": 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": case "created":
rtm.SendMessage(rtm.NewOutgoingMessage("command not yet supported", ev.Channel)) rtm.SendMessage(rtm.NewOutgoingMessage("command not yet supported", ev.Channel))
case "owner": 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) { func checkLore(searchTerm string, redisClient *redis.Client) (string, error) {
val, err := redisClient.Get(fmt.Sprintf("lore:%s:content", searchTerm)).Result() val, err := redisClient.Get(fmt.Sprintf("lore:%s:content", searchTerm)).Result()
if err != nil { if err != nil {

Loading…
Cancel
Save