This repository has been archived by the owner on Oct 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cron.go
61 lines (53 loc) · 1.37 KB
/
cron.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
package main
import (
"fmt"
_ "github.com/joho/godotenv/autoload"
"github.com/neo4j/neo4j-go-driver/neo4j"
"github.com/sinnrrr/schoolbot/db"
"net/http"
"os"
"time"
)
func cronAlerts() {
var (
alerts = make(map[int64]map[string]interface{})
users = make(map[int64][]map[string]interface{})
)
result, err := db.Session.Run(
"MATCH (a:Alert)-[:BELONGS_TO]->(:Class)<-[:STUDYING_IN]-(s:Student)"+
"\n"+
"RETURN a, s",
map[string]interface{}{},
)
if err != nil {
panic(err)
}
for result.Next() {
alertID := result.Record().Values()[0].(neo4j.Node).Id()
alerts[alertID] = result.Record().Values()[0].(neo4j.Node).Props()
users[alertID] = append(users[alertID], result.Record().Values()[1].(neo4j.Node).Props())
}
for alertID, alert := range alerts {
for _, user := range users[alertID] {
currentDate := time.Now()
alertDate := time.Unix(alert["date"].(int64), 0)
if alertDate.Hour() == currentDate.Hour() && alertDate.Minute() == currentDate.Minute() {
fmt.Println(GenerateMessageURL(
os.Getenv("BOT_TOKEN"),
user["id"].(int),
GenerateCronAlert(alert["content"].(string)),
))
_, err := http.Get(
GenerateMessageURL(
os.Getenv("BOT_TOKEN"),
user["id"].(int),
GenerateCronAlert(alert["content"].(string)),
),
)
if err != nil {
panic(err)
}
}
}
}
}