helperbot/cmd/main.go

44 lines
771 B
Go
Raw Normal View History

2019-11-13 00:45:56 +00:00
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
"time"
slack "git.bullercodeworks.com/brian/go-slack"
)
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...")
a.m.messages <- NewBotMessage("main", "main", slack.Message{Type: "control", Name: "quit"})
}()
for a.running {
time.Sleep(time.Second * 2)
}
fmt.Println("Done")
os.Exit(0)
}