/
main.go
45 lines (34 loc) · 795 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
package main
import (
"log"
"os"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
"github.com/joho/godotenv"
"github.com/scherbakovx/wishlist_bot/app/db"
tghandler "github.com/scherbakovx/wishlist_bot/app/tg_handler"
"gorm.io/gorm"
)
func main() {
err := godotenv.Load()
if err != nil {
log.Panic("failed to open .env file")
}
var database *gorm.DB = db.Init()
bot_token := os.Getenv("TG_BOT_TOKEN")
bot, err := tgbotapi.NewBotAPI(bot_token)
if err != nil {
log.Panic(err)
}
bot.Debug = true
u := tgbotapi.NewUpdate(0)
u.Timeout = 60
updates := bot.GetUpdatesChan(u)
for update := range updates {
updateHandler := tghandler.UpdateHandler{
Update: update,
Database: database,
Bot: bot,
}
updateHandler.HandleAnyMessage()
}
}