package main import ( "flag" "os" "os/signal" "syscall" "github.com/rs/zerolog" "github.com/rs/zerolog/log" "git.jojodev.com/Minecraft/canopeas/config" "git.jojodev.com/Minecraft/canopeas/database" "git.jojodev.com/Minecraft/canopeas/discord" ) var configFlag string func main() { log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr}) flag.StringVar(&configFlag, "config", "canopeas.toml", "Set config path") flag.Parse() cfg, err := config.Load(configFlag) if err != nil { log.Fatal().Msgf("could not load config: %v", err) } db, err := database.Load(cfg.DBPath) if err != nil { log.Fatal().Msgf("could not load database: %v", err) } bot, err := discord.Bot(cfg, db) if err != nil { log.Fatal().Msgf("could not start Discord bot: %v", err) } go func() { if err := bot.Open(); err != nil { log.Error().Msgf("error running Discord bot: %v", err) } }() log.Info().Msg("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 { log.Error().Msgf("error closing Discord bot: %v", err) } }