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

@@ -12,3 +12,28 @@ type appservice struct {
ASToken string `yaml:"as_token"`
HSToken string `yaml:"hs_token"`
}
func (a *appservice) setDefaults() error {
if a.ID == "" {
a.ID = "discord"
}
if err := a.Bot.setDefaults(); err != nil {
return err
}
return nil
}
func (a *appservice) UnmarshalYAML(unmarshal func(interface{}) error) error {
type rawAppservice appservice
raw := rawAppservice{}
if err := unmarshal(&raw); err != nil {
return err
}
*a = appservice(raw)
return a.setDefaults()
}