rename account data keys, rearrange code

This commit is contained in:
Aine
2022-08-30 14:42:07 +03:00
parent 5ed3a53223
commit 627e090afd
4 changed files with 47 additions and 55 deletions

View File

@@ -7,7 +7,7 @@ import (
)
// account data key
const botsettingskey = "cc.etke.postmoogle.config"
const acBotSettingsKey = "cc.etke.postmoogle.config"
// bot options keys
const (
@@ -48,26 +48,26 @@ func (b *Bot) migrateBotSettings(users []string) error {
}
func (b *Bot) getBotSettings() botsettings {
cfg := b.botcfg.Get(botsettingskey)
cfg := b.botcfg.Get(acBotSettingsKey)
if cfg != nil {
return cfg
}
config := botsettings{}
err := b.lp.GetClient().GetAccountData(botsettingskey, &config)
err := b.lp.GetClient().GetAccountData(acBotSettingsKey, &config)
if err != nil {
if strings.Contains(err.Error(), "M_NOT_FOUND") {
err = nil
}
b.log.Error("cannot get bot settings: %v", utils.UnwrapError(err))
} else {
b.botcfg.Set(botsettingskey, config)
b.botcfg.Set(acBotSettingsKey, config)
}
return config
}
func (b *Bot) setBotSettings(cfg botsettings) error {
b.botcfg.Set(botsettingskey, cfg)
return utils.UnwrapError(b.lp.GetClient().SetAccountData(botsettingskey, cfg))
b.botcfg.Set(acBotSettingsKey, cfg)
return utils.UnwrapError(b.lp.GetClient().SetAccountData(acBotSettingsKey, cfg))
}