fix gitignore, make bot respond to version request
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Jeffrey Paul 2020-09-08 19:29:51 -07:00
parent 1239c9e1f3
commit cfec102364
2 changed files with 23 additions and 29 deletions

2
.gitignore vendored
View File

@ -1 +1 @@
./sco
sco

View File

@ -195,8 +195,6 @@ func (b *Bot) SendMsgToDebuggingChannel(msg string, replyToId string) {
func (b *Bot) HandleWebSocketResponse(event *model.WebSocketEvent) {
b.HandleMsgFromDebuggingChannel(event)
if event.Event != model.WEBSOCKET_EVENT_POSTED {
return
}
@ -206,16 +204,25 @@ func (b *Bot) HandleWebSocketResponse(event *model.WebSocketEvent) {
return
}
if post.UserId == b.botUser.Id {
return
}
if event.Broadcast.ChannelId == b.debuggingChannel.Id {
b.HandleMsgFromDebuggingChannel(event)
return
}
// check to see if we have been addressed
if matched, _ := regexp.MatchString(`^`+b.BotName+`\s+`, post.Message); matched {
b.SendMsgToDebuggingChannel("i have been addressed in channel "+post.ChannelId, "")
b.HandleMsgFromAnyChannel(event)
if matched, _ := regexp.MatchString(`^\s*`+b.BotName+`\s*`, post.Message); matched {
println("i have been addressed in channel " + post.ChannelId)
//b.SendMsgToDebuggingChannel("i have been addressed in channel "+post.ChannelId, "")
b.HandleMsgFromChannel(event)
}
}
func (b *Bot) HandleMsgFromAnyChannel(event *model.WebSocketEvent) {
println("responding to channel msg")
func (b *Bot) HandleMsgFromChannel(event *model.WebSocketEvent) {
post := model.PostFromJson(strings.NewReader(event.Data["post"].(string)))
if post == nil {
@ -224,21 +231,21 @@ func (b *Bot) HandleMsgFromAnyChannel(event *model.WebSocketEvent) {
//pretty.Print(post)
// ignore my events
if post.UserId == b.botUser.Id {
if matched, _ := regexp.MatchString(`(?:^|\W)alive(?:$|\W)`, post.Message); matched {
b.SendMsgToChannel("yes I'm running", post.Id, post.ChannelId)
return
}
// if you see any word matching 'alive' then respond
if matched, _ := regexp.MatchString(`(?:^|\W)alive(?:$|\W)`, post.Message); matched {
b.SendMsgToChannel("Yes I'm running", "", post.ChannelId)
if matched, _ := regexp.MatchString(`(?:^|\W)version(?:$|\W)`, post.Message); matched {
msg := fmt.Sprintf("I am running version `%s` from git: https://git.eeqj.de/sneak/sco", b.Version)
b.SendMsgToChannel(msg, post.Id, post.ChannelId)
return
}
if matched, _ := regexp.MatchString(`(?:^|\W)uptime(?:$|\W)`, post.Message); matched {
uptime := time.Now().Unix() - b.StartupUnixTime
msg := fmt.Sprintf("running: uptime %d seconds", uptime)
b.SendMsgToChannel(msg, "", post.ChannelId)
b.SendMsgToChannel(msg, post.Id, post.ChannelId)
return
}
@ -247,26 +254,12 @@ func (b *Bot) HandleMsgFromAnyChannel(event *model.WebSocketEvent) {
}
func (b *Bot) HandleMsgFromDebuggingChannel(event *model.WebSocketEvent) {
// If this isn't the debugging channel then lets ingore it
if event.Broadcast.ChannelId != b.debuggingChannel.Id {
return
}
// Lets only reponded to messaged posted events
if event.Event != model.WEBSOCKET_EVENT_POSTED {
return
}
println("responding to debugging channel msg")
post := model.PostFromJson(strings.NewReader(event.Data["post"].(string)))
if post != nil {
// ignore my events
if post.UserId == b.botUser.Id {
return
}
if matched, _ := regexp.MatchString(`(?:^|\W)shutdown(?:$|\W)`, post.Message); matched {
b.SendMsgToDebuggingChannel("i will now exit", post.Id)
syscall.Kill(syscall.Getpid(), syscall.SIGINT)
@ -298,7 +291,8 @@ func (b *Bot) HandleMsgFromDebuggingChannel(event *model.WebSocketEvent) {
}
}
b.SendMsgToDebuggingChannel("I did not understand you!", post.Id)
b.SendMsgToChannel("I did not understand your command, sorry", post.Id, post.ChannelId)
//b.SendMsgToDebuggingChannel("I did not understand you!", post.Id)
}
func PrintError(err *model.AppError) {