subscribe-bot/main.go

66 lines
1 KiB
Go
Raw Permalink Normal View History

2020-10-11 19:32:58 +00:00
package main
import (
"flag"
"log"
"os"
"os/signal"
"syscall"
)
var exit_chan = make(chan int)
func main() {
configPath := flag.String("config", "config.toml", "Path to the config file (defaults to config.toml)")
flag.Parse()
config, err := ReadConfig(*configPath)
requests := make(chan int)
api := NewOsuapi(&config)
db, err := OpenDb("db", api)
if err != nil {
log.Fatal(err)
}
log.Println("opened db")
2020-10-11 19:32:58 +00:00
2020-10-12 08:50:18 +00:00
bot, err := NewBot(&config, db, requests)
2020-10-11 19:32:58 +00:00
if err != nil {
log.Fatal(err)
}
go RunScraper(bot, db, api, requests)
signal_chan := make(chan os.Signal, 1)
signal.Notify(signal_chan,
syscall.SIGHUP,
syscall.SIGINT,
syscall.SIGTERM,
syscall.SIGQUIT)
go func() {
for {
s := <-signal_chan
switch s {
case syscall.SIGHUP:
fallthrough
case syscall.SIGINT:
fallthrough
case syscall.SIGTERM:
fallthrough
case syscall.SIGQUIT:
exit_chan <- 0
default:
exit_chan <- 1
}
}
}()
code := <-exit_chan
db.Close()
bot.Close()
ticker.Stop()
2020-10-11 19:32:58 +00:00
os.Exit(code)
}