helperbot/cmd/main.go

50 lines
946 B
Go

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)
}
// Monitor the Advent of Code Boards
//go m.MonitorAoCBoards()
// Monitor incoming Slack messages
//go m.MonitorSlackMessages()
// 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("Model has stopped running")
fmt.Println("Done")
os.Exit(0)
}