Browse Source

Fix nick parsing to be more efficient

master
Matthew Faltys 7 years ago
parent
commit
65ddb3d48c
  1. 24
      lorebot/lorebot.go

24
lorebot/lorebot.go

@ -136,16 +136,6 @@ func initRedisConnection() (*redis.Client, error) {
} }
func dynamicCommandHandler(rtm *slack.RTM, ev *slack.MessageEvent, redisClient *redis.Client) { func dynamicCommandHandler(rtm *slack.RTM, ev *slack.MessageEvent, redisClient *redis.Client) {
//nick := ev.User
//fmt.Printf("%s", ev.User)
user, err := rtm.GetUserInfo(ev.User)
if err != nil {
fmt.Printf("%s\n", err)
return
}
println(user.Name)
nick := fmt.Sprintf("%s", user.Name)
message := ev.Text message := ev.Text
if strings.Count(message, " ") < 1 { if strings.Count(message, " ") < 1 {
glogger.Debug.Println("not proper syntax") glogger.Debug.Println("not proper syntax")
@ -166,7 +156,7 @@ func dynamicCommandHandler(rtm *slack.RTM, ev *slack.MessageEvent, redisClient *
rtm.SendMessage(rtm.NewOutgoingMessage("not proper syntax", ev.Channel)) rtm.SendMessage(rtm.NewOutgoingMessage("not proper syntax", ev.Channel))
return return
} }
newhandler(rtm, ev, nick, content, "lore", redisClient) newhandler(rtm, ev, content, "lore", 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":
@ -388,8 +378,16 @@ func lorestatus(rtm *slack.RTM, ev *slack.MessageEvent, redisClient *redis.Clien
rtm.SendMessage(rtm.NewOutgoingMessage(status, ev.Channel)) rtm.SendMessage(rtm.NewOutgoingMessage(status, ev.Channel))
} }
func newhandler(rtm *slack.RTM, ev *slack.MessageEvent, nick, message, newType string, redisClient *redis.Client) { func newhandler(rtm *slack.RTM, ev *slack.MessageEvent, message, newType string, redisClient *redis.Client) {
err := loreNewString(nick, message, newType, redisClient) // get nick from slack api
user, err := rtm.GetUserInfo(ev.User)
if err != nil {
fmt.Printf("%s\n", err)
return
}
nick := fmt.Sprintf("%s", user.Name)
err = loreNewString(nick, message, newType, redisClient)
if err == nil { if err == nil {
rtm.SendMessage(rtm.NewOutgoingMessage("entry created", ev.Channel)) rtm.SendMessage(rtm.NewOutgoingMessage("entry created", ev.Channel))
} else { } else {

Loading…
Cancel
Save