package config import ( "github.com/BurntSushi/toml" "github.com/rs/zerolog" "github.com/rs/zerolog/log" "os" "time" ) var BotConfig config func LoadConfig() { configFile, err := os.ReadFile("data/config.toml") if err != nil { log.Panic().Err(err).Msg("error opening data/config.toml") } _, err = toml.Decode(string(configFile), &BotConfig) if err != nil { log.Panic().Err(err).Msg("error decoding data/config.toml") } BotConfig.Shutup = make(map[int64]time.Time) if !BotConfig.DebugMode { zerolog.SetGlobalLevel(zerolog.InfoLevel) } log.Info().Msg("Loaded config") log.Trace().Interface("config", BotConfig).Msg("") } func EncodeToml() { exampleConfig := config{ APIToken: "1234567:h8Y7ma7hMG93kxDx5o", DebugMode: false, PrivilegedUsers: []int64{1234567, 9764382423}, Webserver: struct{ Port string }{ Port: "3000", }, Balonlyl: struct { EnabledChats []int64 BalonlylAT string TriggerWords []string }{ EnabledChats: []int64{353454534, 8743658}, BalonlylAT: "@Balonlyl", TriggerWords: []string{"French, France"}, }, GayPoints: struct { EnabledChats []int64 ModifyUsers []int64 }{ EnabledChats: []int64{353454534, 8743658}, ModifyUsers: []int64{3827468324, 1736576}, }, Download: struct { Prefix string }{ Prefix: "https://bloater.example.com", }, } f, err := os.Create("data/config.toml.example") if err != nil { log.Panic().Err(err).Msg("Error encoding Config File. Cannot open data/config.toml.example") } if err := toml.NewEncoder(f).Encode(exampleConfig); err != nil { log.Panic().Err(err).Msg("Error encoding Config File") } if err := f.Close(); err != nil { log.Panic().Err(err).Msg("Error encoding Config File. Cannot close data/config.toml.example") } log.Info().Msg("Writing example config to data/config.toml.example. Bye Bye") }