From c919527b1bc61c0dd0bdae3124fdb6753d320dac Mon Sep 17 00:00:00 2001 From: Layla Date: Thu, 27 Oct 2022 02:39:22 +0000 Subject: [PATCH] Allow for no config file --- app/bot.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/app/bot.go b/app/bot.go index 793a604..30b6d1b 100644 --- a/app/bot.go +++ b/app/bot.go @@ -1,6 +1,7 @@ package app import ( + "errors" "fmt" "log" "os" @@ -26,13 +27,21 @@ type Bot struct { // Initalize creates the discord session and registers handlers func (app *Bot) Initialize(config_path string) error { log.Printf("Using config: %s", config_path) - cfg := &Config{} - err := cleanenv.ReadConfig(config_path, cfg) - if err != nil { - return err - } + _, err := os.Stat(config_path) + if errors.Is(err, os.ErrNotExist) { + log.Printf("Config file not found: '%s'", config_path) + err := cleanenv.ReadEnv(&cfg) + if err != nil { + return nil + } + } else { + err := cleanenv.ReadConfig(config_path, cfg) + if err != nil { + return err + } + } // Load directly from config app.guildID = cfg.Discord.GuildID app.eventCategoryID = cfg.Discord.EventCategory