/
settings.go
50 lines (40 loc) · 1.56 KB
/
settings.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package spellingbee
import (
"fmt"
"github.com/bbeck/puzzles-with-chat/api/db"
"github.com/bbeck/puzzles-with-chat/api/model"
"github.com/gomodule/redigo/redis"
)
// Settings represents the optional behaviors that can be enabled or disabled
// by a streamer for their channel's spelling bee solves.
type Settings struct {
// When enabled unofficial answers will be allowed.
AllowUnofficialAnswers bool `json:"allow_unofficial_answers"`
// Whether or not to show answer placeholders.
ShowAnswerPlaceholders bool `json:"show_answer_placeholders"`
// What font size words should be rendered with.
FontSize model.FontSize `json:"font_size"`
}
// SettingsKey returns the key that should be used in redis to store a
// particular channel's settings.
func SettingsKey(name string) string {
return fmt.Sprintf("%s:spellingbee:settings", name)
}
// GetSettings will load settings for the provided channel name. If the
// settings can't be properly loaded then an error will be returned.
func GetSettings(conn redis.Conn, channel string) (Settings, error) {
var settings Settings
if testSettingsLoadError != nil {
return settings, testSettingsLoadError
}
err := db.Get(conn, SettingsKey(channel), &settings)
return settings, err
}
// SetSettings will write settings for the provided channel name. If the
// settings can't be properly written then an error will be returned.
func SetSettings(conn redis.Conn, channel string, settings Settings) error {
if testSettingsSaveError != nil {
return testSettingsSaveError
}
return db.Set(conn, SettingsKey(channel), settings)
}