mirror of
https://github.com/mautrix/discord.git
synced 2025-03-14 14:15:37 +00:00

This allows us to check for some required values and give an easy to respond to error at startup rather than a lot of validation during run time.
33 lines
528 B
Go
33 lines
528 B
Go
package config
|
|
|
|
type bot struct {
|
|
Username string `yaml:"username"`
|
|
Displayname string `yaml:"displayname"`
|
|
Avatar string `yaml:"avatar"`
|
|
}
|
|
|
|
func (b *bot) validate() 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.validate()
|
|
}
|