From 21c4316fc8db842dd2ba679c246b845c4330f278 Mon Sep 17 00:00:00 2001 From: sneak Date: Tue, 8 Sep 2020 18:54:04 -0700 Subject: [PATCH] bot should respond to alive queries in public channels now --- bot/bot.go | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/bot/bot.go b/bot/bot.go index 886eafb..e36f92d 100644 --- a/bot/bot.go +++ b/bot/bot.go @@ -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) { post := &model.Post{} post.ChannelId = b.debuggingChannel.Id @@ -196,7 +207,7 @@ func (b *Bot) HandleMsgFromAnyChannel(event *model.WebSocketEvent) { pretty.Print(post) - // FIXME find out what channel it came from so can respond appropriately + channel := post.ChannelId // ignore my events 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 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 } - // if you see any word matching 'up' then respond - 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) + //b.SendMsgToDebuggingChannel("I did not understand you!", post.Id) }