2024-11-06 16:01:38 -08:00
|
|
|
package config
|
2024-11-06 13:32:37 -08:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type AppConfig struct {
|
|
|
|
|
LogFile string `yaml:"log_file"`
|
|
|
|
|
LogDir string `yaml:"log_dir"`
|
|
|
|
|
LogMaxSizeMB int `yaml:"log_max_size_mb"`
|
|
|
|
|
LogMaxBackups int `yaml:"log_max_backups"`
|
|
|
|
|
LogMaxAgeDays int `yaml:"log_max_age_days"`
|
|
|
|
|
LogCompression bool `yaml:"log_compression"`
|
2024-11-06 14:19:45 -08:00
|
|
|
LogAddSource bool `yaml:"log_add_source"`
|
2024-11-13 16:32:58 -08:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
how long (in seconds) a user needs to be in vc in order to generate a
|
|
|
|
|
UserActive event
|
|
|
|
|
*/
|
|
|
|
|
VoiceActivityThresholdSeconds int `yaml:"voice_activity_threshold_seconds"`
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
how long (in milliseconds) a voice activity timer sleeps at a time between
|
|
|
|
|
context cancellation checks.
|
|
|
|
|
|
|
|
|
|
a higher value means the function sleeps longer which could be
|
|
|
|
|
useful for some reason in the future
|
|
|
|
|
|
|
|
|
|
a higher value also means that the timer could take longer to cancel.
|
|
|
|
|
|
|
|
|
|
current recommended value is 1000ms.
|
|
|
|
|
*/
|
|
|
|
|
VoiceActivityTimerSleepIntervalMillis int `yaml:"voice_activity_timer_sleep_interval_millis"`
|
2024-11-06 13:32:37 -08:00
|
|
|
}
|
|
|
|
|
|
2024-11-13 22:03:57 +00:00
|
|
|
var config *AppConfig
|
2024-11-06 16:01:38 -08:00
|
|
|
|
2024-11-14 10:27:45 -08:00
|
|
|
func init() {
|
|
|
|
|
setDefaults()
|
|
|
|
|
viper.Unmarshal(&config)
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-13 22:03:57 +00:00
|
|
|
func Get() *AppConfig {
|
|
|
|
|
return config
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-14 10:27:45 -08:00
|
|
|
func GetDefaultConfig() *AppConfig {
|
|
|
|
|
var config *AppConfig
|
|
|
|
|
setDefaults()
|
|
|
|
|
viper.Unmarshal(&config)
|
|
|
|
|
return config
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-13 22:03:57 +00:00
|
|
|
func Init() error {
|
2024-11-06 13:32:37 -08:00
|
|
|
setDefaults()
|
|
|
|
|
|
|
|
|
|
// automatically populate config with any matching environment vars
|
|
|
|
|
viper.SetEnvPrefix("BB")
|
|
|
|
|
viper.AutomaticEnv()
|
|
|
|
|
|
|
|
|
|
viper.SetConfigName("config")
|
|
|
|
|
viper.SetConfigType("yaml")
|
|
|
|
|
viper.AddConfigPath(".")
|
|
|
|
|
|
|
|
|
|
err := viper.ReadInConfig()
|
|
|
|
|
if err != nil {
|
2024-11-13 22:03:57 +00:00
|
|
|
return fmt.Errorf("error reading configs: %s", err)
|
2024-11-06 13:32:37 -08:00
|
|
|
}
|
|
|
|
|
|
2024-11-13 22:03:57 +00:00
|
|
|
err = viper.Unmarshal(&config)
|
2024-11-06 13:32:37 -08:00
|
|
|
if err != nil {
|
2024-11-13 22:03:57 +00:00
|
|
|
return fmt.Errorf("error unmarshaling configs: %s", err)
|
2024-11-06 13:32:37 -08:00
|
|
|
}
|
|
|
|
|
|
2024-11-13 22:03:57 +00:00
|
|
|
return nil
|
2024-11-06 13:32:37 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func setDefaults() {
|
|
|
|
|
viper.SetDefault("LogFile", "bingobot.log")
|
2024-11-06 14:19:45 -08:00
|
|
|
viper.SetDefault("LogDir", "log")
|
2024-11-06 13:32:37 -08:00
|
|
|
viper.SetDefault("LogMaxSizeMB", 500)
|
|
|
|
|
viper.SetDefault("LogMaxBackups", 3)
|
|
|
|
|
viper.SetDefault("LogMaxAgeDays", 365)
|
|
|
|
|
viper.SetDefault("LogCompression", false)
|
2024-11-06 14:19:45 -08:00
|
|
|
viper.SetDefault("LogAddSource", true)
|
2024-11-13 16:32:58 -08:00
|
|
|
viper.SetDefault("VoiceActivityThresholdSeconds", 600)
|
|
|
|
|
viper.SetDefault("VoiceActivityTimerSleepIntervalMillis", 1000)
|
2024-11-06 13:32:37 -08:00
|
|
|
}
|