mirror of
https://git.sr.ht/~ashkeel/strimertul
synced 2024-09-18 01:50:50 +00:00
fix: fix misuses of wrapped values
This commit is contained in:
parent
2f9f8e1fe9
commit
3bc662796f
3 changed files with 10 additions and 5 deletions
|
@ -14,7 +14,6 @@ import (
|
|||
"go.uber.org/zap"
|
||||
|
||||
"github.com/strimertul/strimertul/database"
|
||||
"github.com/strimertul/strimertul/utils"
|
||||
)
|
||||
|
||||
var json = jsoniter.ConfigFastest
|
||||
|
@ -40,8 +39,12 @@ func NewServer(db *database.LocalDBClient, logger *zap.Logger) (*Server, error)
|
|||
Config: sync.NewRWSync(ServerConfig{}),
|
||||
}
|
||||
|
||||
err := utils.LoadJSONToWrapped[ServerConfig](ServerConfigKey, server.Config)
|
||||
var config ServerConfig
|
||||
err := db.GetJSON(ServerConfigKey, &config)
|
||||
if err != nil {
|
||||
if err != database.ErrEmptyKey {
|
||||
logger.Warn("HTTP config is corrupted or could not be read", zap.Error(err))
|
||||
}
|
||||
// Initialize with default config
|
||||
server.Config.Set(ServerConfig{
|
||||
Bind: "localhost:4337",
|
||||
|
@ -49,10 +52,12 @@ func NewServer(db *database.LocalDBClient, logger *zap.Logger) (*Server, error)
|
|||
KVPassword: "",
|
||||
})
|
||||
// Save
|
||||
err = db.PutJSON(ServerConfigKey, server.Config)
|
||||
err = db.PutJSON(ServerConfigKey, server.Config.Get())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
server.Config.Set(config)
|
||||
}
|
||||
|
||||
// Set hub
|
||||
|
|
|
@ -147,7 +147,7 @@ func newBot(api *Client, config BotConfig) *Bot {
|
|||
history = history[len(history)-bot.Config.ChatHistory+1:]
|
||||
}
|
||||
bot.chatHistory.Set(append(history, message))
|
||||
err = bot.api.db.PutJSON(ChatHistoryKey, bot.chatHistory)
|
||||
err = bot.api.db.PutJSON(ChatHistoryKey, bot.chatHistory.Get())
|
||||
if err != nil {
|
||||
bot.logger.Warn("could not save message to chat history", zap.Error(err))
|
||||
}
|
||||
|
|
|
@ -92,7 +92,7 @@ func (m *BotTimerModule) runTimers() {
|
|||
timeUntilNextTick := nextTick.Sub(currentTime)
|
||||
time.Sleep(timeUntilNextTick)
|
||||
|
||||
err := m.bot.api.db.PutJSON(ChatActivityKey, m.messages)
|
||||
err := m.bot.api.db.PutJSON(ChatActivityKey, m.messages.Get())
|
||||
if err != nil {
|
||||
m.bot.logger.Warn("error saving chat activity", zap.Error(err))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue