generated from Tnze/CoolQ-Golang-Plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
conf.go
45 lines (35 loc) · 902 Bytes
/
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
package main
import (
"github.com/BurntSushi/toml"
"github.com/miaoscraft/Check-MC-Version/resfile"
"time"
)
type config struct {
Frequency duration
GroupID []uint64
Template string
}
type duration struct{ time.Duration }
func (d *duration) UnmarshalText(text []byte) (err error) {
d.Duration, err = time.ParseDuration(string(text))
return
}
func getConfig() (config, error) {
var c config
f, err := resfile.GetFile("config.toml", []byte(defaultConfig))
if err != nil {
return c, err
}
_, err = toml.DecodeReader(f, &c)
return c, err
}
const defaultConfig = `# MC版本更新推送姬配置文件
# 检查频率
Frequency = "10m"
# 群号(支持多个群)
GroupID = [123456]
# 提醒模版
Template = '''
{{ .Time.Format "2006-01-02 15:04:05" }}
Minecraft {{ .ID }}{{ if eq .Type "snapshot" }}快照版{{ else if eq .Type "release" }}正式版{{ end }}发布了!!'''
`