-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
executable file
·51 lines (43 loc) · 1006 Bytes
/
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
package main
import (
"flag"
"sync"
"github.com/go-telegram-bot-api/telegram-bot-api"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"
"jiandanBot/bot"
"jiandanBot/channel"
"jiandanBot/crawler"
"jiandanBot/maker"
)
func init() {
viper.SetConfigName("config") // 配置文件名
viper.AddConfigPath("config") // 配置文件所在的路径
viper.SetConfigType("json") // 配置文件类型
err := viper.ReadInConfig()
if err != nil {
logrus.Panic(err)
}
debug := flag.Bool("debug", false, "debug")
flag.Parse()
if !*debug {
errorMsg := new(ErrorMsg)
logrus.SetOutput(errorMsg)
}
}
func main() {
go bot.Run()
go crawler.GetJianDan()
go maker.Jiandan()
// 暴力的防止主进程退出
wg := sync.WaitGroup{}
wg.Add(1)
wg.Wait()
}
type ErrorMsg struct {
}
func (e *ErrorMsg) Write(p []byte) (n int, err error) {
newErrorMessage := tgbotapi.NewMessage(viper.GetInt64("AdminID"), string(p))
channel.NormalMessageChannel <- newErrorMessage
return len(p), nil
}