helperbot/cmd/main.go

48 lines
819 B
Go
Raw Normal View History

2019-11-13 00:45:56 +00:00
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
"time"
2019-11-21 23:45:04 +00:00
"github.com/nlopes/slack"
2019-11-13 00:45:56 +00:00
)
var DebugMode = false
var a *App
func main() {
if len(os.Args) > 1 {
if os.Args[1] == "-debug" || os.Args[1] == "--debug" {
DebugMode = true
}
}
a, err := NewApp()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
// Set up a channel to intercept Ctrl+C for graceful shutdowns
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
<-c
// Save the changes when the app quits
fmt.Println("\nFinishing up...")
2019-11-21 23:45:04 +00:00
msg := slack.Message{}
msg.Type = "control"
msg.Text = "quit"
a.m.messages <- NewBotMessage("main", "main", msg)
2019-11-13 00:45:56 +00:00
}()
for a.running {
time.Sleep(time.Second * 2)
}
2019-11-21 23:45:04 +00:00
fmt.Println("Model has stopped running")
2019-11-13 00:45:56 +00:00
fmt.Println("Done")
os.Exit(0)
}