fix gitignore, make bot respond to version request
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
1239c9e1f3
commit
cfec102364
|
@ -1 +1 @@
|
||||||
./sco
|
sco
|
||||||
|
|
50
bot/bot.go
50
bot/bot.go
|
@ -195,8 +195,6 @@ func (b *Bot) SendMsgToDebuggingChannel(msg string, replyToId string) {
|
||||||
|
|
||||||
func (b *Bot) HandleWebSocketResponse(event *model.WebSocketEvent) {
|
func (b *Bot) HandleWebSocketResponse(event *model.WebSocketEvent) {
|
||||||
|
|
||||||
b.HandleMsgFromDebuggingChannel(event)
|
|
||||||
|
|
||||||
if event.Event != model.WEBSOCKET_EVENT_POSTED {
|
if event.Event != model.WEBSOCKET_EVENT_POSTED {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -206,16 +204,25 @@ func (b *Bot) HandleWebSocketResponse(event *model.WebSocketEvent) {
|
||||||
return
|
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
|
// check to see if we have been addressed
|
||||||
if matched, _ := regexp.MatchString(`^`+b.BotName+`\s+`, post.Message); matched {
|
if matched, _ := regexp.MatchString(`^\s*`+b.BotName+`\s*`, post.Message); matched {
|
||||||
b.SendMsgToDebuggingChannel("i have been addressed in channel "+post.ChannelId, "")
|
println("i have been addressed in channel " + post.ChannelId)
|
||||||
b.HandleMsgFromAnyChannel(event)
|
//b.SendMsgToDebuggingChannel("i have been addressed in channel "+post.ChannelId, "")
|
||||||
|
b.HandleMsgFromChannel(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bot) HandleMsgFromAnyChannel(event *model.WebSocketEvent) {
|
func (b *Bot) HandleMsgFromChannel(event *model.WebSocketEvent) {
|
||||||
println("responding to channel msg")
|
|
||||||
|
|
||||||
post := model.PostFromJson(strings.NewReader(event.Data["post"].(string)))
|
post := model.PostFromJson(strings.NewReader(event.Data["post"].(string)))
|
||||||
if post == nil {
|
if post == nil {
|
||||||
|
@ -224,21 +231,21 @@ func (b *Bot) HandleMsgFromAnyChannel(event *model.WebSocketEvent) {
|
||||||
|
|
||||||
//pretty.Print(post)
|
//pretty.Print(post)
|
||||||
|
|
||||||
// ignore my events
|
if matched, _ := regexp.MatchString(`(?:^|\W)alive(?:$|\W)`, post.Message); matched {
|
||||||
if post.UserId == b.botUser.Id {
|
b.SendMsgToChannel("yes I'm running", post.Id, post.ChannelId)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// if you see any word matching 'alive' then respond
|
if matched, _ := regexp.MatchString(`(?:^|\W)version(?:$|\W)`, post.Message); matched {
|
||||||
if matched, _ := regexp.MatchString(`(?:^|\W)alive(?:$|\W)`, post.Message); matched {
|
msg := fmt.Sprintf("I am running version `%s` from git: https://git.eeqj.de/sneak/sco", b.Version)
|
||||||
b.SendMsgToChannel("Yes I'm running", "", post.ChannelId)
|
b.SendMsgToChannel(msg, post.Id, post.ChannelId)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if matched, _ := regexp.MatchString(`(?:^|\W)uptime(?:$|\W)`, post.Message); matched {
|
if matched, _ := regexp.MatchString(`(?:^|\W)uptime(?:$|\W)`, post.Message); matched {
|
||||||
uptime := time.Now().Unix() - b.StartupUnixTime
|
uptime := time.Now().Unix() - b.StartupUnixTime
|
||||||
msg := fmt.Sprintf("running: uptime %d seconds", uptime)
|
msg := fmt.Sprintf("running: uptime %d seconds", uptime)
|
||||||
b.SendMsgToChannel(msg, "", post.ChannelId)
|
b.SendMsgToChannel(msg, post.Id, post.ChannelId)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,26 +254,12 @@ func (b *Bot) HandleMsgFromAnyChannel(event *model.WebSocketEvent) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bot) HandleMsgFromDebuggingChannel(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")
|
println("responding to debugging channel msg")
|
||||||
|
|
||||||
post := model.PostFromJson(strings.NewReader(event.Data["post"].(string)))
|
post := model.PostFromJson(strings.NewReader(event.Data["post"].(string)))
|
||||||
if post != nil {
|
if post != nil {
|
||||||
|
|
||||||
// ignore my events
|
// ignore my events
|
||||||
if post.UserId == b.botUser.Id {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if matched, _ := regexp.MatchString(`(?:^|\W)shutdown(?:$|\W)`, post.Message); matched {
|
if matched, _ := regexp.MatchString(`(?:^|\W)shutdown(?:$|\W)`, post.Message); matched {
|
||||||
b.SendMsgToDebuggingChannel("i will now exit", post.Id)
|
b.SendMsgToDebuggingChannel("i will now exit", post.Id)
|
||||||
syscall.Kill(syscall.Getpid(), syscall.SIGINT)
|
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) {
|
func PrintError(err *model.AppError) {
|
||||||
|
|
Loading…
Reference in New Issue