prettyprint channel msgs
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
b0a42c125c
commit
0b76d0269a
51
bot/bot.go
51
bot/bot.go
|
@ -6,6 +6,8 @@ import (
|
|||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/kr/pretty"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
)
|
||||
|
||||
|
@ -178,6 +180,55 @@ func (b *Bot) SendMsgToDebuggingChannel(msg string, replyToId string) {
|
|||
|
||||
func (b *Bot) HandleWebSocketResponse(event *model.WebSocketEvent) {
|
||||
b.HandleMsgFromDebuggingChannel(event)
|
||||
b.HandleMsgFromAnyChannel(event)
|
||||
}
|
||||
|
||||
func (b *Bot) HandleMsgFromAnyChannel(event *model.WebSocketEvent) {
|
||||
if event.Event != model.WEBSOCKET_EVENT_POSTED {
|
||||
return
|
||||
}
|
||||
println("responding to channel msg")
|
||||
|
||||
post := model.PostFromJson(strings.NewReader(event.Data["post"].(string)))
|
||||
if post == nil {
|
||||
return
|
||||
}
|
||||
|
||||
pretty.Print(post)
|
||||
|
||||
// FIXME find out what channel it came from so can respond appropriately
|
||||
|
||||
// ignore my events
|
||||
if post.UserId == b.botUser.Id {
|
||||
return
|
||||
}
|
||||
|
||||
// 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)
|
||||
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)
|
||||
|
||||
}
|
||||
|
||||
func (b *Bot) HandleMsgFromDebuggingChannel(event *model.WebSocketEvent) {
|
||||
|
|
Loading…
Reference in New Issue