-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCocoa.go
80 lines (66 loc) · 1.67 KB
/
Cocoa.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
80
package main
import (
// internal packages
"fmt"
"os"
"os/signal"
// external packages
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/driver"
// custom packages
"github.com/DaydreamCafe/Cocoa/V2/src/config"
_ "github.com/DaydreamCafe/Cocoa/V2/src/init"
// high priority
_ "github.com/DaydreamCafe/Cocoa/V2/builtin/help"
_ "github.com/DaydreamCafe/Cocoa/V2/builtin/user_manager"
// normal priority
_ "github.com/DaydreamCafe/Cocoa/V2/plugins/bilibili_parse"
_ "github.com/DaydreamCafe/Cocoa/V2/plugins/char_reverser"
_ "github.com/DaydreamCafe/Cocoa/V2/plugins/coser"
_ "github.com/DaydreamCafe/Cocoa/V2/plugins/github_parse"
_ "github.com/DaydreamCafe/Cocoa/V2/plugins/lolicon"
// low priority
_ "github.com/DaydreamCafe/Cocoa/V2/builtin/plugin_manager"
)
var (
// Config 全局配置
Config config.Config
// zeroConfig ZeroBot配置
zeroConfig zero.Config
)
// 初始化函数
func init() {
// 加载配置文件
Config.Load()
// 初始化ZeroBot配置
zeroConfig = zero.Config{
NickName: Config.NickNames,
CommandPrefix: Config.CommandPrefix,
SuperUsers: Config.SuperUsers,
Driver: []zero.Driver{driver.NewWebSocketClient(
fmt.Sprintf("ws://%s:%d", Config.Server.Address, Config.Server.Port),
Config.Server.Token,
),
},
}
}
// 入口函数
func main() {
// 初始化并运行ZeroBot
zero.Run(zeroConfig)
// 处理Ctrl+C退出信号
signalChan := make(chan os.Signal, 1)
cleanupDone := make(chan bool)
signal.Notify(signalChan, os.Interrupt)
go func() {
for range signalChan {
fmt.Printf("\n停止服务...\n")
cleanUp()
cleanupDone <- true
}
}()
<-cleanupDone
}
// 清理函数
func cleanUp() {
}