-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
81 lines (65 loc) · 1.35 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
package main
import (
"embed"
"flag"
"fmt"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
"github.com/json-iterator/go/extra"
"github.com/sirupsen/logrus"
embed2 "go-tgbot/comm/embed"
"go-tgbot/comm/global"
"go-tgbot/conf"
"go-tgbot/handle"
"go-tgbot/ticker"
"log"
"os"
"runtime"
"time"
)
//go:embed config
var embedConfigFiles embed.FS
//go:embed static
var embedStaticsFiles embed.FS
var (
//gitCommit string
buildAt string
)
func main() {
extra.RegisterFuzzyDecoders()
flag.Parse()
if len(os.Args) >= 2 && os.Args[1] == "version" {
print(fmt.Sprintf("Go version: %s\nBuilt: %s\nOS/Arch: %s/%s",
runtime.Version(), buildAt, runtime.GOOS, runtime.GOARCH))
return
}
time.LoadLocation("Asia/Shanghai")
var (
c *conf.AllConfig
err error
)
embed2.SetConfigFs(embedConfigFiles)
embed2.SetStaticFsFs(embedStaticsFiles)
// 加载配置文件
c, err = conf.ReadConfig()
if err != nil {
logrus.Fatal(err)
}
if c.App.Debug {
logrus.SetLevel(logrus.DebugLevel)
}
bot, err := tgbotapi.NewBotAPI(c.App.Token)
if err != nil {
log.Fatal(err.Error())
}
if c.App.Debug {
bot.Debug = true
}
global.Conf = c
updateConfig := tgbotapi.NewUpdate(0)
updateConfig.Timeout = 60
ticker.Ticker(bot)
updates := bot.GetUpdatesChan(updateConfig)
for update := range updates {
go handle.Bypass(bot, update)
}
}