Added notification when there are no entries

master
alex 2022-09-03 17:46:01 +02:00
parent 449dfeca8c
commit 6ba78dddcc
2 changed files with 34 additions and 29 deletions

BIN
main

Binary file not shown.

View File

@ -4,6 +4,7 @@ import (
"encoding/base64"
"encoding/json"
"log"
"time"
"maunium.net/go/mautrix"
"maunium.net/go/mautrix/event"
@ -65,41 +66,45 @@ func SendMessage(today string, nextDay string) {
nextDayRepresentation = representation
}
if len(todayRepresentation) == 0 && len(nextDayRepresentation) == 0 {
return
}
var msg string
if len(todayRepresentation) > 0 {
msg += "<b>Vertretung - Heute</b>"
dt := time.Now()
for _, entity := range todayRepresentation {
msg += "<br>Stunde: <b>" + entity.Hour + "</b>"
msg += "<br>Klasse: <b>" + entity.Class + "</b>"
msg += "<br>Vertreter: <b>" + entity.Representative + "</b>"
msg += "<br>Lehrer: <b>" + entity.Teacher + "</b>"
msg += "<br>Fach: <b>" + entity.Subject + "</b>"
msg += "<br>Raum: <b>" + entity.Room + "</b>"
msg += "<br>Hinweis: <b>" + entity.Note + "</b>"
msg += "<br>"
if len(todayRepresentation) == 0 && len(nextDayRepresentation) == 0 { // no entries
msg += "<b>✅ Vertretung - Keine Einträge vorhanden</b>"
} else {
if len(todayRepresentation) > 0 {
msg += "<b>⚠️ Vertretung - Heute</b>"
for _, entity := range todayRepresentation {
msg += "<br>Stunde: <b>" + entity.Hour + "</b>"
msg += "<br>Klasse: <b>" + entity.Class + "</b>"
msg += "<br>Vertreter: <b>" + entity.Representative + "</b>"
msg += "<br>Lehrer: <b>" + entity.Teacher + "</b>"
msg += "<br>Fach: <b>" + entity.Subject + "</b>"
msg += "<br>Raum: <b>" + entity.Room + "</b>"
msg += "<br>Hinweis: <b>" + entity.Note + "</b>"
msg += "<br>"
}
}
if len(nextDayRepresentation) > 0 {
msg += "<br><b>⚠️ Vertretung - Nächster Tag</b>"
for _, entity := range nextDayRepresentation {
msg += "<br>Stunde: <b>" + entity.Hour + "</b>"
msg += "<br>Klasse: <b>" + entity.Class + "</b>"
msg += "<br>Vertreter: <b>" + entity.Representative + "</b>"
msg += "<br>Lehrer: <b>" + entity.Teacher + "</b>"
msg += "<br>Fach: <b>" + entity.Subject + "</b>"
msg += "<br>Raum: <b>" + entity.Room + "</b>"
msg += "<br>Hinweis: <b>" + entity.Note + "</b>"
msg += "<br>"
}
}
}
if len(nextDayRepresentation) > 0 {
msg += "<br><b>Vertretung - Nächster Tag</b>"
for _, entity := range nextDayRepresentation {
msg += "<br>Stunde: <b>" + entity.Hour + "</b>"
msg += "<br>Klasse: <b>" + entity.Class + "</b>"
msg += "<br>Vertreter: <b>" + entity.Representative + "</b>"
msg += "<br>Lehrer: <b>" + entity.Teacher + "</b>"
msg += "<br>Fach: <b>" + entity.Subject + "</b>"
msg += "<br>Raum: <b>" + entity.Room + "</b>"
msg += "<br>Hinweis: <b>" + entity.Note + "</b>"
msg += "<br>"
}
}
msg += "<br>" + dt.Format("02.01.2006 15:04:05")
botmsg := format.RenderMarkdown(msg, false, true)