-
Notifications
You must be signed in to change notification settings - Fork 125
/
main.go
51 lines (45 loc) · 1.53 KB
/
main.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
package main
import (
"time"
"github.com/spf13/viper"
"github.com/yqchilde/wxbot/engine/pkg/log"
"github.com/yqchilde/wxbot/engine/pkg/net"
"github.com/yqchilde/wxbot/engine/robot"
"github.com/yqchilde/wxbot/framework/dean"
"github.com/yqchilde/wxbot/framework/vlw"
// 导入插件, 变更插件请查看README
_ "github.com/yqchilde/wxbot/engine/plugins"
)
func main() {
v := viper.New()
v.SetConfigFile("config.yaml")
if err := v.ReadInConfig(); err != nil {
log.Fatalf("[main] 读取配置文件失败: %s", err.Error())
}
c := robot.NewConfig()
if err := v.Unmarshal(c); err != nil {
log.Fatalf("[main] 解析配置文件失败: %s", err.Error())
}
f := robot.IFramework(nil)
switch c.Framework.Name {
case "Dean":
f = robot.IFramework(dean.New(c.BotWxId, c.Framework.ApiUrl, c.Framework.ApiToken))
if ipPort, err := net.CheckoutIpPort(c.Framework.ApiUrl); err == nil {
if ping := net.PingConn(ipPort, time.Second*10); !ping {
c.SetConnHookStatus(false)
log.Warn("[main] 无法连接Dean框架,网络无法Ping通,请检查网络")
}
}
case "VLW", "vlw":
f = robot.IFramework(vlw.New(c.BotWxId, c.Framework.ApiUrl, c.Framework.ApiToken))
if ipPort, err := net.CheckoutIpPort(c.Framework.ApiUrl); err == nil {
if ping := net.PingConn(ipPort, time.Second*10); !ping {
c.SetConnHookStatus(false)
log.Warn("[main] 无法连接到VLW框架,网络无法Ping通,请检查网络")
}
}
default:
log.Fatalf("[main] 请在配置文件中指定机器人框架后再启动")
}
robot.Run(c, f)
}