Skip to content

Commit

Permalink
Allow for no config file
Browse files Browse the repository at this point in the history
  • Loading branch information
yeslayla committed Oct 27, 2022
1 parent 3641eab commit c919527
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions app/bot.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package app

import (
"errors"
"fmt"
"log"
"os"
Expand All @@ -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
Expand Down

0 comments on commit c919527

Please sign in to comment.