-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.go
142 lines (121 loc) · 3.35 KB
/
setup.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package main
import (
"fmt"
"math/rand"
"strconv"
"time"
"github.com/lonelyevil/kook"
scribble "github.com/nanobox-io/golang-scribble"
"github.com/spf13/viper"
)
// stdout频道
var stdoutChannel string
// 转发map
var kook2qqRouteMap map[string]string
// [qqgroup] [vcsetting]
type vocechatInstance struct {
Url string
Secret string
Gid string
}
var qq2vcRouteMap map[string]vocechatInstance
var kook2vcRouteMap map[string]vocechatInstance
// 邀请map
var kookInviteUrl map[string]string
var masterID string
var botID string
var localSession *kook.Session
var token string
var db *scribble.Driver
func routeMapInit() {
qq2vcRouteMap = make(map[string]vocechatInstance, 0)
kook2vcRouteMap = make(map[string]vocechatInstance, 0)
kook2qqRouteMap = make(map[string]string, 0)
kookInviteUrl = make(map[string]string, 0)
}
func routeMapSetupOld() {
s := viper.Get("kook2qq").(map[string]any)
for k, v := range s {
vs := v.(string)
if k != v {
if _, ok := kook2qqRouteMap[k]; !ok {
kook2qqRouteMap[k] = vs
}
if _, ok := kook2qqRouteMap[vs]; !ok {
kook2qqRouteMap[vs] = k
}
}
}
}
func kookInviteUrlSetup() {
s := viper.Get("kookinvite").(map[string]any)
for k, v := range s {
vs := v.(string)
if _, ok := kookInviteUrl[k]; !ok {
kookInviteUrl[k] = vs
}
}
}
var vcCount int
func RouteMapSetup() {
vcCount = 0
s := viper.Get("routes").([]any)
for _, newmap := range s {
fmt.Println(newmap)
route := newmap.(map[string]any)
fmt.Println(route["type"])
if route["type"] == "kook2qq" {
if route["host"] != nil && route["qqgroup"] != nil {
kook2qqRouteMap[route["host"].(string)] = route["qqgroup"].(string)
kook2qqRouteMap[route["qqgroup"].(string)] = route["host"].(string)
if route["hostinvite"] != nil {
kookInviteUrl[route["host"].(string)] = route["hostinvite"].(string)
}
}
}
if route["type"] == "vc2qq" {
if route["gid"] != nil && route["vcapi"] != nil && route["secret"] != nil && route["qqgroup"] != nil {
qq2vcRouteMap[route["qqgroup"].(string)] = vocechatInstance{Url: route["vcapi"].(string), Secret: route["secret"].(string), Gid: route["gid"].(string)}
vcCount += 1
}
}
if route["type"] == "kook2vc" {
if route["gid"] != nil && route["vcapi"] != nil && route["secret"] != nil && route["host"] != nil {
kook2vcRouteMap[route["host"].(string)] = vocechatInstance{Url: route["vcapi"].(string), Secret: route["secret"].(string), Gid: route["gid"].(string)}
vcCount += 1
}
}
}
}
func GetConfig() {
rand.Seed(time.Now().UnixNano())
db, _ = scribble.New("./database", nil)
viper.SetDefault("token", "0")
viper.SetDefault("stdoutChannel", "0")
viper.SetDefault("masterID", "")
viper.SetDefault("oldversion", "0.0.0")
viper.SetConfigType("json")
viper.SetConfigName("config")
viper.AddConfigPath(".")
err := viper.ReadInConfig()
if err != nil {
panic(fmt.Errorf("fatal error config file: %s", err))
}
masterID = viper.Get("masterID").(string)
stdoutChannel = viper.Get("stdoutChannel").(string)
vcport, _ := strconv.Atoi(viper.Get("vcport").(string))
fmt.Println("stdoutChannel=" + stdoutChannel)
token = viper.Get("token").(string)
routeMapInit()
routeMapSetupOld()
RouteMapSetup()
kookInviteUrlSetup()
kookLastCacheSetup()
msgCacheSetup()
if vcCount > 0 && vcport > 0 {
go voceChatBot(vcport)
}
}
func beforeShutdown() {
msgCache.Backup()
}