This repository has been archived by the owner on Feb 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.go
164 lines (146 loc) · 3.23 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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
package main
import (
"crypto/tls"
"flag"
"fmt"
"math/rand"
"net/http"
"os"
"os/signal"
"sync"
"syscall"
"time"
"github.com/lizongshen/gocommand"
"github.com/sirupsen/logrus"
)
func init() {
// Logger
vkLog := NewVkLogHook()
logger = logrus.New()
logger.SetOutput(os.Stdout)
logger.AddHook(vkLog)
tr = &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
randSrc = rand.NewSource(time.Now().UnixNano())
// Flag Parse
flag.BoolVar(&refresh, "r", false, "Refresh Cache")
flag.BoolVar(&debug, "d", false, "Debug Mode")
flag.BoolVar(&verbose, "v", false, "Verbose logging")
flag.BoolVar(&justListen, "l", false, "Just Run Listener")
flag.Parse()
if debug {
logger.SetLevel(logrus.DebugLevel)
} else if verbose {
logger.SetLevel(logrus.InfoLevel)
} else {
logger.SetLevel(logrus.ErrorLevel)
}
// Config
config, err := loadConf()
if err != nil {
logger.Errorln("[-] ", err.Error())
return
}
logger.Infoln("[+] Load Conf")
for key, value := range config {
logger.Infof("[+] %-10s = %-.50s\n", key, value)
}
logger.Infof("[+] %-10s = %-.50s\n", "areaNext", areaNext)
}
func main() {
if debug {
logger.Debug("[D] Start As Debug Mode")
logger.Debug("[D] But Nothing...")
// return
}
logger.Infoln("[+] Load SKU Meta Data...")
// 获取 SKU 元数据
if refresh {
masks, err := loadMask()
if err != nil {
logger.Errorln("[-] ", err.Error())
return
}
if !getSkuMeta(masks) {
return
}
saveSkuMetaCache()
} else {
if !loadSkuMetaCache() {
return
}
}
logger.Infoln("[+] Start to Listening...")
go sendBotMsg("[ABML] Start to Listening...")
wg := &sync.WaitGroup{}
ch = make(chan os.Signal, 1)
signal.Notify(ch, os.Interrupt, syscall.SIGTERM)
var o *OrderJD
if !justListen {
o = RunOrderJD()
wg.Add(1)
go func(wg *sync.WaitGroup, o *OrderJD) {
defer wg.Done()
for {
if stop {
logger.Infoln("[+] Heartbeat stopping...")
break
}
o.heartbeat()
time.Sleep(60 * time.Second)
}
logger.Infoln("[+] Heartbeat stopped")
}(wg, o)
wg.Add(1)
go func(wg *sync.WaitGroup, o *OrderJD) {
defer wg.Done()
o.orderSku()
}(wg, o)
}
time.Sleep(1 * time.Second)
// lm := RunListenMaskV1()
lm := RunListenMaskV2()
lm.doAction = func(skuid string) {
// Auto Order
if len(config["cookies"]) > 0 && !justListen {
o.addSkuID(skuid)
}
go func(skuid string) {
// Run Command
if len(config["command"]) > 0 {
_, _, err := gocommand.NewCommand().Exec(config["command"])
if err != nil {
logger.Errorln("[!] Command Error", err.Error())
} else {
logger.Infoln("[!] Command [", command, "] Exec success!")
}
}
// Webhook
if len(config["webhook"]) > 0 {
_, _ = http.Get(fmt.Sprintf("%s%s", config["webhook"], skuid))
msg := fmt.Sprintf("[ABML] Push [%s] To WebHook", skuid)
logger.Infoln("[*]", msg)
sendBotMsg(msg)
}
}(skuid)
}
wg.Add(1)
go func(wg *sync.WaitGroup, lm *ListenMaskV2) {
defer wg.Done()
lm.listenMask()
}(wg, lm)
// Finish
wg.Add(1)
go func(wg *sync.WaitGroup, o *OrderJD) {
defer wg.Done()
<-ch
if !justListen {
o.addSkuID("0")
}
stop = true
}(wg, o)
wg.Wait()
sendBotMsg("[ABML] Stoped Listen")
logger.Infoln("[+] Finish AutoBuyMask")
}