-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
48 lines (38 loc) · 866 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
package main
import (
"time"
_ "github.com/go-sql-driver/mysql"
"github.com/joho/godotenv"
"github.com/labstack/gommon/log"
_ "github.com/lib/pq"
"github.com/yanzay/tbot/v2"
)
func init() {
err := godotenv.Load()
if err != nil {
log.Error("Error loading .env ", err)
}
}
func main() {
token := GetEnv("TELEGRAM_TOKEN", "")
bot := tbot.New(token)
app := &application{
tgClient: &TbotWrapper{bot.Client()},
attachmentsDir: GetEnv("ATTACHMENTS_DIR", "attachments"),
token: token,
vmFactory: VmFactoryImpl{},
}
if e := app.initialize(); e != nil {
log.Fatal("Error initializing app ", e)
}
//bind handlers
bot.HandleMessage("", app.messageHandler)
bot.HandleCallback(app.callbackHandler)
go func() {
//let bot connect
time.Sleep(time.Second * 3)
app.onInit()
}()
//start bot
log.Fatal(bot.Start())
}