bot should respond to alive queries in public channels now
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Jeffrey Paul 2020-09-08 18:54:04 -07:00
parent 0b76d0269a
commit 21c4316fc8

View File

@ -165,6 +165,17 @@ func (b *Bot) CreateBotDebuggingChannelIfNeeded() {
} }
} }
func (b *Bot) SendMsgToChannel(msg string, replyToId string, channelId string) {
post := &model.Post{}
post.ChannelId = ChannelId
post.Message = msg
post.RootId = replyToId
if _, resp := b.client.CreatePost(post); resp.Error != nil {
println("We failed to send a message to the logging channel")
PrintError(resp.Error)
}
}
func (b *Bot) SendMsgToDebuggingChannel(msg string, replyToId string) { func (b *Bot) SendMsgToDebuggingChannel(msg string, replyToId string) {
post := &model.Post{} post := &model.Post{}
post.ChannelId = b.debuggingChannel.Id post.ChannelId = b.debuggingChannel.Id
@ -196,7 +207,7 @@ func (b *Bot) HandleMsgFromAnyChannel(event *model.WebSocketEvent) {
pretty.Print(post) pretty.Print(post)
// FIXME find out what channel it came from so can respond appropriately channel := post.ChannelId
// ignore my events // ignore my events
if post.UserId == b.botUser.Id { if post.UserId == b.botUser.Id {
@ -205,29 +216,11 @@ func (b *Bot) HandleMsgFromAnyChannel(event *model.WebSocketEvent) {
// if you see any word matching 'alive' then respond // if you see any word matching 'alive' then respond
if matched, _ := regexp.MatchString(`(?:^|\W)alive(?:$|\W)`, post.Message); matched { if matched, _ := regexp.MatchString(`(?:^|\W)alive(?:$|\W)`, post.Message); matched {
b.SendMsgToDebuggingChannel("Yes I'm running", post.Id) b.SendMsgToChannel("Yes I'm running", "", channel)
return return
} }
// if you see any word matching 'up' then respond //b.SendMsgToDebuggingChannel("I did not understand you!", post.Id)
if matched, _ := regexp.MatchString(`(?:^|\W)up(?:$|\W)`, post.Message); matched {
b.SendMsgToDebuggingChannel("Yes I'm running", post.Id)
return
}
// if you see any word matching 'running' then respond
if matched, _ := regexp.MatchString(`(?:^|\W)running(?:$|\W)`, post.Message); matched {
b.SendMsgToDebuggingChannel("Yes I'm running", post.Id)
return
}
// if you see any word matching 'hello' then respond
if matched, _ := regexp.MatchString(`(?:^|\W)hello(?:$|\W)`, post.Message); matched {
b.SendMsgToDebuggingChannel("Yes I'm running", post.Id)
return
}
b.SendMsgToDebuggingChannel("I did not understand you!", post.Id)
} }