60 lines
1.2 KiB
Go
60 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
|
|
"git.birbmc.com/canopeas/config"
|
|
"git.birbmc.com/canopeas/database"
|
|
"git.birbmc.com/canopeas/discord"
|
|
|
|
"go.jolheiser.com/beaver"
|
|
)
|
|
|
|
var configFlag string
|
|
|
|
func main() {
|
|
flag.StringVar(&configFlag, "config", "canopeas.toml", "Set config path")
|
|
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)
|
|
}
|
|
}
|