2020-06-09 13:04:44 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"syscall"
|
|
|
|
|
2021-07-09 20:23:40 +00:00
|
|
|
"git.canopymc.net/Etzelia/canopeas/config"
|
|
|
|
"git.canopymc.net/Etzelia/canopeas/database"
|
|
|
|
"git.canopymc.net/Etzelia/canopeas/discord"
|
2020-06-09 13:04:44 +00:00
|
|
|
|
|
|
|
"go.jolheiser.com/beaver"
|
|
|
|
)
|
|
|
|
|
|
|
|
var configFlag string
|
|
|
|
|
|
|
|
func main() {
|
2021-05-14 03:27:39 +00:00
|
|
|
flag.StringVar(&configFlag, "config", "canopeas.toml", "Set config path")
|
2020-06-09 13:04:44 +00:00
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
beaver.Console.Format = beaver.FormatOptions{
|
|
|
|
TimePrefix: true,
|
|
|
|
StackPrefix: true,
|
|
|
|
StackLimit: 15,
|
|
|
|
LevelPrefix: true,
|
|
|
|
LevelColor: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
cfg, err := config.Load(configFlag)
|
|
|
|
if err != nil {
|
|
|
|
beaver.Fatalf("could not load config: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
db, err := database.Load(cfg.DBPath)
|
|
|
|
if err != nil {
|
|
|
|
beaver.Fatalf("could not load database: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
bot, err := discord.Bot(cfg, db)
|
|
|
|
if err != nil {
|
|
|
|
beaver.Fatalf("could not start Discord bot: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
if err := bot.Open(); err != nil {
|
|
|
|
beaver.Errorf("error running Discord bot: %v", err)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
beaver.Info("Bot is now running. Press CTRL-C to exit.")
|
|
|
|
sc := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
|
|
|
|
<-sc
|
|
|
|
|
|
|
|
if err := bot.Close(); err != nil {
|
|
|
|
beaver.Errorf("error closing Discord bot: %v", err)
|
|
|
|
}
|
|
|
|
}
|