Do not call getSettings() for each option in help

Retrieving the settings object for each and every option was wasteful

I don't like how we're doing custom formatting for optionMailbox in many
different places. This should be redone.
This commit is contained in:
Slavi Pantaleev
2022-08-27 19:21:18 +03:00
parent 0d88de9f77
commit 972b4c11c5
2 changed files with 25 additions and 32 deletions

View File

@@ -1,7 +1,6 @@
package bot
import (
"fmt"
"strconv"
"strings"
@@ -116,24 +115,6 @@ func (b *Bot) getSettings(roomID id.RoomID) (settings, error) {
return config, err
}
func (b *Bot) getSettingsOption(roomID id.RoomID, name string) (any, error) {
cfg, err := b.getSettings(roomID)
if err != nil {
return nil, fmt.Errorf("failed to retrieve settings: %v", err)
}
value := cfg.Get(name)
if value == "" {
return nil, nil
}
if name == optionMailbox {
value = fmt.Sprintf("%s@%s", value, b.domain)
}
return value, nil
}
func (b *Bot) setSettings(roomID id.RoomID, cfg settings) error {
return b.lp.GetClient().SetRoomAccountData(roomID, settingskey, cfg)
}