forked from akshettrj/watgbridge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
75 lines (62 loc) · 1.49 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"log"
"os"
"time"
"watgbridge/database"
"watgbridge/state"
"watgbridge/telegram"
"watgbridge/utils"
"watgbridge/whatsapp"
)
func main() {
// Load config file
cfg := state.State.Config
if len(os.Args) > 1 {
cfg.Path = os.Args[1]
} else {
cfg.Path = "config.yaml"
}
cfg.LoadConfig()
if cfg.TimeZone == "" {
cfg.TimeZone = "Asia/Kolkata"
}
localLoc, err := time.LoadLocation(cfg.TimeZone)
if err != nil {
log.Fatalln("Couldn't set timezone to " + cfg.TimeZone + ": " + err.Error())
}
state.State.LocalLocation = localLoc
db, err := database.Connect()
if err != nil {
log.Fatalln("Couldn't connect to the database : " + err.Error())
}
state.State.Database = db
err = database.AutoMigrate()
if err != nil {
log.Fatalln("Couldn't migrate the database tables : " + err.Error())
}
err = telegram.NewClient()
if err != nil {
panic(err)
}
log.Printf(
"[telegram] logged in as : %s [ @%s ]\n",
state.State.TelegramBot.FirstName,
state.State.TelegramBot.Username,
)
err = whatsapp.NewClient()
if err != nil {
panic(err)
}
log.Printf(
"[whatsapp] logged in as : %s [ %s ]\n",
state.State.WhatsAppClient.Store.PushName,
state.State.WhatsAppClient.Store.ID.User,
)
state.State.StartTime = time.Now()
waClient := state.State.WhatsAppClient
waClient.AddEventHandler(whatsapp.WhatsAppEventHandler)
telegram.AddHandlers()
utils.RegisterBotCommand(state.State.TelegramBot, state.State.TelegramCommands...)
state.State.TelegramUpdater.Idle()
}