-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
60 lines (51 loc) · 1.21 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
package main
import (
"net/http"
_ "net/http/pprof"
"os"
"os/signal"
"syscall"
"github.com/eaok/ashe/config"
"github.com/eaok/ashe/router"
"github.com/lonelyevil/khl"
"github.com/lonelyevil/khl/log_adapter/plog"
"github.com/phuslu/log"
)
func init() {
// Read config from configuration
config.ReadConfig("./config/config.ini")
}
func main() {
go func() {
if config.Data.RunMod == "debug" {
http.ListenAndServe(":8081", nil)
} else {
http.ListenAndServe(":8080", nil)
}
}()
s := khl.New(config.Data.Token, plog.NewLogger(&log.Logger{
Level: log.WarnLevel,
TimeFormat: "2006-01-02 15:04:05",
Caller: 1,
// Writer: &log.ConsoleWriter{
// ColorOutput: true,
// QuoteString: true,
// EndWithMessage: true,
// },
}))
router.InitAction(s)
router.Route(s)
// need to open the socket
err := s.Open()
if err != nil {
s.Logger.Error().Err("", err).Msg("error opening connection")
return
}
// Wait here until CTRL-C or other term signal is received.
s.Logger.Warn().Msg("Bot is now running. Press CTRL-C to exit.")
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
<-sc
// Cleanly close down the KHL session.
s.Close()
}