/
theme.go
79 lines (66 loc) · 1.92 KB
/
theme.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package heist
import (
"encoding/json"
"fmt"
"github.com/rbrabson/heist/pkg/store"
log "github.com/sirupsen/logrus"
)
const (
THEME = "theme"
)
// Theme is a heist theme.
type Theme struct {
ID string `json:"_id" bson:"_id"`
Good []GoodMessage `json:"good"`
Bad []BadMessage `json:"bad"`
Jail string `json:"jail" bson:"jail"`
OOB string `json:"oob" bson:"oob"`
Police string `json:"police" bson:"police"`
Bail string `json:"bail" bson:"bail"`
Crew string `json:"crew" bson:"crew"`
Sentence string `json:"sentence" bson:"sentence"`
Heist string `json:"heist" bson:"heist"`
Vault string `json:"vault" bson:"vault"`
}
type GoodMessage struct {
Message string `json:"message" bson:"message"`
Amount int `json:"amount" bson:"amount"`
}
type BadMessage struct {
Message string `json:"message" bson:"message"`
Result string `json:"result" bson:"result"`
}
// GetThemeNames returns a list of available themes.
func GetThemeNames(map[string]*Theme) ([]string, error) {
var fileNames []string
for _, theme := range themes {
fileNames = append(fileNames, theme.ID)
}
return fileNames, nil
}
// LoadThemes loads the themes that may be used by the heist bot.
func LoadThemes() map[string]*Theme {
themes := make(map[string]*Theme)
themeIDs := store.Store.ListDocuments(THEME)
for _, themeID := range themeIDs {
var theme Theme
store.Store.Load(THEME, themeID, &theme)
themes[theme.ID] = &theme
}
return themes
}
// GetTheme gets the specified theme and returns.
func GetTheme(themeName string) (*Theme, error) {
theme, ok := themes[themeName]
if !ok {
msg := "Theme " + themeName + " does not exist."
log.Warning(msg)
return nil, fmt.Errorf(msg)
}
return theme, nil
}
// String returns a string representation of the theme.
func (t *Theme) String() string {
out, _ := json.Marshal(*t)
return string(out)
}