-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
43 lines (33 loc) · 797 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
package main
import (
"github.com/go-telegram-bot-api/telegram-bot-api"
"log"
)
var done = make(chan int)
func main() {
err := readConfigFromENV()
if err != nil {
log.Fatalf("Could not load config from env, err: %v", err)
}
bot, u, err := setupBot()
if err != nil {
log.Panic(err)
}
chat := NewChat()
botClient := NewBot(bot, u, chat)
scheduler := NewScheduler(botClient, chat)
go botClient.listenMessages()
go scheduler.StartBotScheduler()
<-done
}
func setupBot() (*tgbotapi.BotAPI, tgbotapi.UpdateConfig, error) {
bot, err := tgbotapi.NewBotAPI(Config.Token)
if err != nil {
return nil, tgbotapi.UpdateConfig{}, err
}
bot.Debug = true
log.Printf("Authorized on account %s", bot.Self.UserName)
u := tgbotapi.NewUpdate(0)
u.Timeout = 60
return bot, u, nil
}