-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
70 lines (56 loc) · 1.29 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
package main
import (
"log"
"time"
"github.com/joho/godotenv"
"github.com/ttimmatti/discord-tg_parser/db"
"github.com/ttimmatti/discord-tg_parser/ds_msgs"
"github.com/ttimmatti/discord-tg_parser/env"
"github.com/ttimmatti/discord-tg_parser/tg_msgs"
)
const WD = "/home/ttimmatti/my_scripts/go/discord_bot/"
const DS_REPEAT_MINUTES = 20
func main() {
err := godotenv.Load(WD + ".env")
if err != nil {
log.Fatalln("Couldnt get Environment")
}
db.OnExit()
db.DB = db.SetConn(env.GetDbEnv())
tg_msgs.TG_API = env.GetTGApiEnv()
tg_msgs.ADMIN_ID = env.GetAdminIdEnv()
go tg_msgs.StartReceiving(
env.GetTGApiEnv(),
2,
)
ds_msgs.PROXY = env.GetProxyEnv()
ds_msgs.TOKEN = env.GetDisToken()
if err := startReceivingDs(); err != nil {
log.Printf("main: %s", err)
}
}
func startReceivingDs() error {
log.Println("startReceiving")
for {
handleDsMsgs()
time.Sleep(DS_REPEAT_MINUTES * time.Minute)
}
}
func handleDsMsgs() {
chs, errs := ds_msgs.GetAllNew()
if errs != nil {
if err := tg_msgs.HandleErrors(errs); err != nil {
log.Fatal(err)
}
}
i := 0
for _, ch := range chs {
i += len(ch.Msgs)
}
log.Printf("-- handleDsMsgs: %d new msgs", i)
if errs := tg_msgs.SendNewMsgs(chs); errs != nil {
if err := tg_msgs.HandleErrors(errs); err != nil {
log.Fatal(err)
}
}
}