Temp timezone fix #11
1 changed files with 37 additions and 35 deletions
72
main.go
72
main.go
|
|
@ -222,20 +222,20 @@ func scheduleTimetableUpdate() {
|
||||||
changes = append(changes, fmt.Sprintf("Room changed for %s: %s → %s", subject, oldRoom, newRoom))
|
changes = append(changes, fmt.Sprintf("Room changed for %s: %s → %s", subject, oldRoom, newRoom))
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, e := range currentEntries {
|
for _, e := range currentEntries {
|
||||||
key := lessonKey(e)
|
key := lessonKey(e)
|
||||||
currMap[key] = e
|
currMap[key] = e
|
||||||
// Create timeslot key (date + startTime + endTime)
|
// Create timeslot key (date + startTime + endTime)
|
||||||
timeslotKey := e.Date + "|" + e.StartTime + "|" + e.EndTime
|
timeslotKey := e.Date + "|" + e.StartTime + "|" + e.EndTime
|
||||||
currTimeslotMap[timeslotKey] = e
|
currTimeslotMap[timeslotKey] = e
|
||||||
}
|
}
|
||||||
for _, e := range prevEntries {
|
for _, e := range prevEntries {
|
||||||
key := lessonKey(e)
|
key := lessonKey(e)
|
||||||
prevMap[key] = e
|
prevMap[key] = e
|
||||||
// Create timeslot key (date + startTime + endTime)
|
// Create timeslot key (date + startTime + endTime)
|
||||||
timeslotKey := e.Date + "|" + e.StartTime + "|" + e.EndTime
|
timeslotKey := e.Date + "|" + e.StartTime + "|" + e.EndTime
|
||||||
prevTimeslotMap[timeslotKey] = e
|
prevTimeslotMap[timeslotKey] = e
|
||||||
}
|
}
|
||||||
|
|
||||||
// Code/status change?
|
// Code/status change?
|
||||||
if prev.Code != curr.Code {
|
if prev.Code != curr.Code {
|
||||||
|
|
@ -615,31 +615,33 @@ func sendDiscordWebhook(subject string, room string, nextTime string, Status str
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendUpdateDiscordWebhookWithDetails(changes []string) {
|
func sendUpdateDiscordWebhookWithDetails(changes []string) {
|
||||||
log.Println("Sending detailed Discord webhook notification...")
|
if BotStart.WebHook {
|
||||||
|
log.Println("Sending detailed Discord webhook notification...")
|
||||||
|
|
||||||
message := "**Timetable Update**\n\n" + strings.Join(changes, "\n")
|
message := "**Timetable Update**\n\n" + strings.Join(changes, "\n")
|
||||||
|
|
||||||
payload := DiscordWebhookPayload{
|
payload := DiscordWebhookPayload{
|
||||||
Content: message,
|
Content: message,
|
||||||
}
|
}
|
||||||
|
|
||||||
jsonData, err := json.Marshal(payload)
|
jsonData, err := json.Marshal(payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error marshaling webhook payload: %v", err)
|
log.Printf("Error marshaling webhook payload: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := http.Post(discordWebhookURL, "application/json", bytes.NewBuffer(jsonData))
|
resp, err := http.Post(discordWebhookURL, "application/json", bytes.NewBuffer(jsonData))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error sending Discord webhook: %v", err)
|
log.Printf("Error sending Discord webhook: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
if resp.StatusCode >= 200 && resp.StatusCode < 300 {
|
if resp.StatusCode >= 200 && resp.StatusCode < 300 {
|
||||||
log.Println("Detailed Discord webhook sent successfully")
|
log.Println("Detailed Discord webhook sent successfully")
|
||||||
} else {
|
} else {
|
||||||
body, _ := ioutil.ReadAll(resp.Body)
|
body, _ := ioutil.ReadAll(resp.Body)
|
||||||
log.Printf("Discord webhook failed with status %d: %s", resp.StatusCode, string(body))
|
log.Printf("Discord webhook failed with status %d: %s", resp.StatusCode, string(body))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue