forked from yqchilde/wxbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
51 lines (45 loc) · 1.58 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/qianxun"
"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 "千寻", "qianxun":
f = robot.IFramework(qianxun.New(c.ServerPort, 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] 无法连接到千寻框架,网络无法Ping通,请检查网络")
}
}
case "VLW", "vlw":
f = robot.IFramework(vlw.New(c.ServerPort, 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)
}