-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
50 lines (41 loc) · 907 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
package main
import (
"flag"
"log"
"time"
"github.com/go-telegram-bot-api/telegram-bot-api"
)
var configPath = flag.String("config", "", "Path to config file")
func main() {
flag.Parse()
config, err := GetConfig(*configPath)
if err != nil {
log.Panic(err)
return
}
kclient := NewKudaGoClient("https://kudago.com/public-api/v1.4")
bot, err := tgbotapi.NewBotAPI(config.Token)
if err != nil {
log.Panic(err)
return
}
handler := NewMessageHandler(&kclient, bot)
bot.Debug = true
log.Printf("Authorized on account %s", bot.Self.UserName)
u := tgbotapi.NewUpdate(0)
u.Timeout = 60
updates, err := bot.GetUpdatesChan(u)
if err != nil {
log.Panic(err)
return
}
// Do not handle a large backlog of old messages
time.Sleep(time.Millisecond * 500)
updates.Clear()
for update := range updates {
if update.Message == nil {
continue
}
go handler.Handle(update)
}
}