-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
53 lines (44 loc) · 1.03 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
package main
import (
"encoding/json"
"github.com/docker/docker/client"
"github.com/petuhovskiy/telegram"
"github.com/petuhovskiy/telegram/updates"
"log"
"github.com/rwlist/ovpn-bot/app"
"github.com/rwlist/ovpn-bot/conf"
)
func main() {
cfg, err := conf.ParseEnv()
if err != nil {
log.Fatal(err)
}
dockerClient, err := client.NewEnvClient()
if err != nil {
log.Fatal(err)
}
bot := telegram.NewBotWithOpts(cfg.BotToken, &telegram.Opts{
Middleware: func(handler telegram.RequestHandler) telegram.RequestHandler {
return func(methodName string, req interface{}) (message json.RawMessage, err error) {
res, err := handler(methodName, req)
if err != nil {
log.Println("Telegram response error: ", err)
}
return res, err
}
},
})
ch, err := updates.StartPolling(bot, telegram.GetUpdatesRequest{
Offset: 0,
Limit: 50,
Timeout: 10,
})
if err != nil {
log.Fatal(err)
}
l := app.NewLogic(dockerClient)
h := app.NewHandler(bot, l, cfg.AdminIDs)
for upd := range ch {
h.Handle(upd)
}
}