This repository was archived by the owner on Mar 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
99 lines (81 loc) · 2.13 KB
/
main.go
File metadata and controls
99 lines (81 loc) · 2.13 KB
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
package main
import (
"flag"
"github.com/zshorz/ezlog"
"github.com/zshorz/fkbro/bot"
"github.com/zshorz/fkbro/btcinfo"
"github.com/zshorz/fkbro/data"
"github.com/zshorz/fkbro/marketinfo"
"github.com/zshorz/fkbro/util"
"os"
"os/signal"
"syscall"
"time"
)
var Log = ezlog.New(os.Stdout, "", ezlog.BitDefault, ezlog.LogAll)
var Bot *bot.Bot
var API *btcinfo.BTC_com_api
var HuobiAPI *marketinfo.Huobi
var WhaleAPI *marketinfo.WhaleAPI
var configfile string
func main() {
flag.StringVar(&configfile, "c", "config.json", "specify config file")
flag.Parse()
util.Config.Reload(configfile)
API = btcinfo.NewBTC_com_api(util.Config.ApiHost, util.Config.CacheSize)
HuobiAPI = marketinfo.NewHuobi(util.Config.Proxy)
WhaleAPI = marketinfo.NewWhaleAPI()
for {
bot, error := bot.NewBot(util.Config.BotToken, util.Config.Proxy)
if error != nil {
Log.Warn(error, "will retry...")
<- time.After(5*time.Second)
} else {
Bot = bot
break
}
}
if !util.Config.Debug {
Log.SetLogLevel(ezlog.LogInfo)
API.Logger.SetLogLevel(ezlog.LogInfo)
Bot.Logger.SetLogLevel(ezlog.LogInfo)
data.Log.SetLogLevel(ezlog.LogInfo)
WhaleAPI.Logger.SetLogLevel(ezlog.LogInfo)
}
doConfig()
Log.Info("create bot success")
Bot.Router.AddHandle("/help", help)
Bot.Router.AddHandle("/newest", newest)
Bot.Router.AddHandle("/q", q)
Bot.Router.AddHandle("unknow", unknow)
Bot.Router.AddHandle("/recent", recent)
Bot.Router.AddHandle("/quotes", quotes)
Bot.Router.AddHandle("/exchange", exchange)
Bot.Router.AddHandle("/market", market)
Bot.Router.AddHandle("/rss", rss)
Bot.Router.AddHandle("/now", now)
Bot.Router.AddHandle("/test", test)
Bot.CallbackQueryRouter.AddHandle("showQuotes", showQuotes)
LoadTemplate(util.Config.StaticPath)
go doSignal()
go live()
Bot.Loop()
Log.Info("good bye: api query cnt", API.QueryCnt)
}
func doConfig() {
for _, s := range util.Config.Rss {
addRss(s)
}
}
func doSignal() {
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGHUP)
for sig := range sigs{
if sig == syscall.SIGINT {
liveExitChan <- 1
Bot.ExitChan <- 1
} else if sig == syscall.SIGHUP {
;
}
}
}