From 9d3ca54ad41ea0e2b9f2dc5fae9dff82d95ba52e Mon Sep 17 00:00:00 2001 From: Ava Affine Date: Sat, 30 Nov 2024 00:31:25 -0800 Subject: [PATCH] initialize state package in main.go This commit adds config values to the config package for state configuration. This commit also adds a call to state.Init() to the main function. Signed-off-by: Ava Affine --- internal/config/config.go | 8 ++++++++ main.go | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/internal/config/config.go b/internal/config/config.go index 00e1983..01e1e40 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -33,6 +33,12 @@ type AppConfig struct { current recommended value is 1000ms. */ VoiceActivityTimerSleepIntervalMillis int `yaml:"voice_activity_timer_sleep_interval_millis"` + + /* persistent state file store */ + PersistentCacheStore string `yaml:"persistent_cache_store"` + + /* number of internal state events to cache in memory */ + InMemoryEventCacheSize int `yaml:"InMemoryEventCacheSize"` } var config *AppConfig @@ -87,4 +93,6 @@ func setDefaults() { viper.SetDefault("LogAddSource", true) viper.SetDefault("VoiceActivityThresholdSeconds", 600) viper.SetDefault("VoiceActivityTimerSleepIntervalMillis", 1000) + viper.SetDefault("PersistentCacheStore", "/tmp/bingobot") + viper.SetDefault("InMemoryEventCacheSize", 512) } diff --git a/main.go b/main.go index 1c072cb..ea3952c 100644 --- a/main.go +++ b/main.go @@ -9,6 +9,7 @@ import ( "gitlab.com/whom/bingobot/internal/config" "gitlab.com/whom/bingobot/internal/discord" "gitlab.com/whom/bingobot/internal/logging" + "gitlab.com/whom/bingobot/internal/state" ) var ( @@ -28,6 +29,13 @@ func main() { logging.Init() + if err := state.Init( + config.Get().InMemoryEventCacheSize, + config.Get().PersistentCacheStore, + ); err != nil { + log.Fatalf("couldn't initialize state engine: %s", err.Error()) + } + err = startBot() if err != nil {