Make sure we always load our default config values

This commit is contained in:
Gary Kramlich
2021-11-19 16:31:19 -06:00
parent 09911a11e3
commit 5a11f49dbe
4 changed files with 96 additions and 6 deletions

View File

@@ -5,3 +5,29 @@ type bot struct {
Displayname string `yaml:"displayname"`
Avatar string `yaml:"avatar"`
}
func (b *bot) setDefaults() error {
if b.Username == "" {
b.Username = "discordbot"
}
if b.Displayname == "" {
b.Displayname = "Discord Bridge Bot"
}
return nil
}
func (b *bot) UnmarshalYAML(unmarshal func(interface{}) error) error {
type rawBot bot
raw := rawBot{}
if err := unmarshal(&raw); err != nil {
return err
}
*b = bot(raw)
return b.setDefaults()
}