-
Notifications
You must be signed in to change notification settings - Fork 0
/
getConfig.go
54 lines (50 loc) · 1.34 KB
/
getConfig.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
package main
import (
"encoding/json"
"fmt"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/driver"
"os"
)
func GetBotConfig() (BotConfig, error) {
file, readConfig := os.ReadFile("./BotConfig.json")
if readConfig != nil {
CreateConfigFile()
return BotConfig{}, readConfig
}
var Config BotConfig
uJsonErr := json.Unmarshal(file, &Config)
if uJsonErr != nil {
return BotConfig{}, uJsonErr
}
return Config, nil
}
func CreateConfigFile() {
Config := BotConfig{
CoreUrl: "ws://127.0.0.1:8765/zerobot",
CommandPrefix: "",
SuperUsers: []int64{123456789, 114514191},
ConnectGoIsClient: true,
ConnectGoCqUrl: "ws://127.0.0.1:11451",
ConnectWaitn: 16,
ConnectGoCqAccToken: "",
}
MJson, CreFile := json.MarshalIndent(Config, " ", " ")
if CreFile != nil {
return
}
err := os.WriteFile("./BotConfig.json", MJson, 0644)
if err != nil {
fmt.Println("文件创建失败,请检查权限")
return
}
fmt.Println("文件创建成功,清修改BotConfig.json后重启")
os.Exit(0)
}
func IsPositiveConnections(bool2 bool, Config BotConfig) zero.Driver {
if bool2 {
return driver.NewWebSocketClient(Config.ConnectGoCqUrl, Config.ConnectGoCqAccToken)
} else {
return driver.NewWebSocketServer(Config.ConnectWaitn, Config.ConnectGoCqUrl, Config.ConnectGoCqAccToken)
}
}