-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
88 lines (76 loc) · 2.04 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
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
81
82
83
84
85
86
87
88
/*
* @Author: NyanCatda
* @Date: 2021-10-03 00:51:57
* @LastEditTime: 2022-03-07 18:55:19
* @LastEditors: NyanCatda
* @Description: 主文件
* @FilePath: \ShionBot\main.go
*/
package main
import (
"flag"
"fmt"
"net/http"
"os"
"github.com/gin-gonic/gin"
"github.com/nyancatda/ShionBot/Controller/MessageProcessing"
"github.com/nyancatda/ShionBot/Controller/MessageProcessing/Struct"
"github.com/nyancatda/ShionBot/Controller/MessagePushAPI/SNSAPI/QQAPI"
"github.com/nyancatda/ShionBot/HttpAPI"
"github.com/nyancatda/ShionBot/Utils"
"github.com/nyancatda/ShionBot/Utils/Language"
"github.com/nyancatda/ShionBot/Utils/ReadConfig"
"github.com/nyancatda/ShionBot/Utils/SQLDB"
)
func Error() {
fmt.Printf(Language.DefaultLanguageMessage().MainErrorTips)
key := make([]byte, 1)
os.Stdin.Read(key)
os.Exit(1)
}
func main() {
//参数解析
ConfigPath := flag.String("config", "./config.yml", "指定配置文件路径")
flag.Parse()
//建立数据储存文件夹
_, err := os.Stat("./data")
if err != nil {
os.MkdirAll("./data", 0777)
}
//设置配置文件路径
ReadConfig.ConfigPath = *ConfigPath
//加载配置文件
if err := ReadConfig.LoadConfig(); err != nil {
fmt.Println(err)
os.Exit(1)
}
Config := ReadConfig.GetConfig
//建立数据库连接
_, err = SQLDB.SQLDBLink()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
//判断是否需要初始化QQ部分
if Config.SNS.QQ.Switch {
QQAPI.StartQQAPI()
}
//启动WebHook接收
gin.SetMode(gin.ReleaseMode)
r := gin.Default()
Port := Config.Run.WebHookPort
fmt.Println(Utils.StringVariable(Language.DefaultLanguageMessage().RunOK, []string{Port}))
WebHookKey := Config.Run.WebHookKey
r.POST("/"+WebHookKey, func(c *gin.Context) {
var json Struct.WebHookJson
if err := c.ShouldBindJSON(&json); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
fmt.Println(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
MessageProcessing.MessageProcessing(c, json)
})
//启动API
HttpAPI.HttpAPIStart(r)
r.Run(":" + Port)
}