-
Notifications
You must be signed in to change notification settings - Fork 0
/
conf.go
58 lines (50 loc) · 1.63 KB
/
conf.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
package main
import (
dry "github.com/ungerik/go-dry"
"gopkg.in/yaml.v2"
)
type answer struct {
Txt string `yaml:"txt"`
Correct bool `yaml:"correct"`
}
type question struct {
Txt string `yaml:"txt"`
Img string `yaml:"img"`
}
type Conf struct {
// Обратный отчет в секундах
Timeout int `yaml:"timeout"`
KickCaption string `yaml:"kickCaption"`
Question question `yaml:"question"`
Answers []*answer `yaml:"answers"`
CountVoted int `yaml:"countVoted"`
}
func LoadConfFromFile(confpath string) (result *Conf, err error) {
if b, err := dry.FileGetBytes(confpath); err == nil {
return LoadConf(b)
} else {
return nil, err
}
}
func LoadConf(conf []byte) (result *Conf, err error) {
result = new(Conf)
err = yaml.Unmarshal(conf, &result)
if result.CountVoted == 0 {
result.CountVoted = 5
}
return result, err
}
func confExample() string {
return `timeout: 60 # время на ответ в секундах, не обязательный параметр, по дефолту 60 секунд
kickCaption: "Я пожалуй пойду" # Заголовок кнопки с обратным отсчетом, не обязательный параметр, по дефолту заголовок "не знаю"
question:
txt: "Что вы видите на картинке?"
img: "https://i.imgur.com/UUMAx2Zm.jpg" # не обязательный параметр
answers:
- txt: "Бабочку"
correct: true
- txt: "Цветы"
- txt: "Лицо"
correct: true
countVoted: 10 # количество проголосовавщих за бан. По умолчанию 5`
}