-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathloadconf.go
More file actions
76 lines (70 loc) · 1.87 KB
/
Copy pathloadconf.go
File metadata and controls
76 lines (70 loc) · 1.87 KB
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
package main
import (
"encoding/json"
"io/ioutil"
"log"
"os"
"strings"
)
var config ConfigFile
type ConfigHead struct {
Video string `json:"video"`
Animation string `json:"animation"`
Photo string `json:"photo"`
Document string `json:"document"`
Text string `json:"text"`
}
type ConfigFile struct {
Ver int8 `json:"ver"`
Debug int64 `json:"debug"`
HealthCheck string `json:"healthcheck"`
TimeZone int8 `json:"timezone"`
Proxy string `json:"proxy"`
Apikey string `json:"apikey"`
Timeout int `json:"timeout"`
Whitelist []int64 `json:"whitelist"`
To map[string]string `json:"to"`
DefTo int64 `json:"defto"`
Nitter []string `json:"nitterHost"`
Head ConfigHead `json:"head"`
}
func cmdTChat(cmd string) (bool, string) {
if len(cmd) == 0 {
return false, ""
}
var cmdU []string = strings.Split(cmd[1:], "@")
if len(cmdU) > 1 && cmdU[1] != bot.Self.UserName {
return false, ""
}
for k, v := range config.To {
if cmdU[0] == k {
return strings.HasPrefix(v, "C"), v[1:]
}
}
log.Println("找不到预设发送目标: ", cmd)
return false, ""
}
func loadConfig() bool {
f, err := os.OpenFile("config.json", os.O_RDONLY, 0600)
if err != nil {
log.Println("開啟配置檔案失敗: ", err)
return false
} else {
contentByte, err := ioutil.ReadAll(f)
if err != nil {
log.Println("讀取配置檔案失敗: ", err)
return false
} else {
err = json.Unmarshal(contentByte, &config)
if err != nil {
log.Println("解析配置檔案失敗: ", err)
return false
}
}
}
if config.Ver != 2 {
log.Println("配置檔案版本不符: ", config.Ver)
return false
}
return true
}