From b2833ad503c1003d11e535549478a468ceb3f23b Mon Sep 17 00:00:00 2001 From: Jannover5000r <90698896+Jannover5000r@users.noreply.github.com> Date: Mon, 3 Nov 2025 14:27:05 +0100 Subject: [PATCH 1/4] main.go aktualisieren --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 3d9223a..43551d9 100644 --- a/main.go +++ b/main.go @@ -72,7 +72,7 @@ func main() { } func isScheduledTime(now time.Time) bool { - scheduled := []string{"07:45", "08:35", "09:35", "10:25", "11:25", "12:15", "13:45", "14:25"} + scheduled := []string{"07:45", "08:35", "09:35", "10:25", "11:25", "12:15", "13:40", "14:25"} current := now.Format("15:04") for _, t := range scheduled { if t == current { From 1b47e7ac0488857fa78e363fd49b44e26ec6941b Mon Sep 17 00:00:00 2001 From: Jannover5000r <90698896+Jannover5000r@users.noreply.github.com> Date: Fri, 5 Dec 2025 08:54:59 +0000 Subject: [PATCH 2/4] Fix URL structure in README for clarity --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c89aba6..867f180 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ - ENC_KEY (generated via head -c 32 /dev/urandom | base64) - URL -### URL can be found by following this structure: "]" while SchoolName can be found by visiting the official website, going to the login for your school and it will be: "" +### URL can be found by following this structure: "" # This is a project for me, issues will be resolved as i find the motivation to do so, improvements may follow in the future From 8d243869ea1eb28582e8e48536cf4b4651e5e746 Mon Sep 17 00:00:00 2001 From: Jannover5000r <90698896+Jannover5000r@users.noreply.github.com> Date: Mon, 30 Mar 2026 05:24:33 +0200 Subject: [PATCH 3/4] added timezone managment --- README.md | 3 +-- exampleEnv | 7 +++++++ main.go | 51 ++++++++++++++++++++++----------------------------- 3 files changed, 30 insertions(+), 31 deletions(-) create mode 100644 exampleEnv diff --git a/README.md b/README.md index 867f180..81e9ef3 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,6 @@ ### For multi user support: using the command **!addaccount** in the discord server the bot is used in, it will than dm you with the sign up process prompting you to enter your untis Username and password (no email neededd just untis username). The username is stored as plain text and the password is hashed on the device hosting the bot, so currently it is **not secure** since the host will have access to the hashed password and the hash used! Deleting an account is done by using **!removeaccount** which will delete the account and the password, created with your discord account -## In case your school is using a different timing for the Lessons than mine, you can change the times where you will be notified with the next room and Lesson for the day in **Line 71 in the main.go** file. The bot may not send you a message if there is no lesson after the specified time so that you can leave empty lessons as is for the days +## For your timezone setup an ENV called "LOCATION_ENV" with your timezone as explained in the example env file. In case your school is using a different timing for the Lessons than mine, you can change the times where you will be notified with the next room and Lesson for the day in **Line 71 in the main.go** file. The bot may not send you a message if there is no lesson after the specified time so that you can leave empty lessons as is for the days # I am neither a representative of Untis, Untis Baden-Württemberg GmbH nor a Developer in their team. This project is based on their API and my code and is not affiliated with them - diff --git a/exampleEnv b/exampleEnv new file mode 100644 index 0000000..a58fcf8 --- /dev/null +++ b/exampleEnv @@ -0,0 +1,7 @@ +DISCORD_WEBHOOK_URL=[Paste Webhook] +UNTIS_PASSWORD=[Default user passwd] +UNTIS_USER=[Default user username] +DISCORD_BOT_TOKEN=[Paste Bot token] +ENC_KEY=[Generate enc key and paste] +URL=[Untis url, create from tutorial in readme] +LOCATION_ENV=Europe/Berlin [change to your timezone, needs to be usable by go's time package via time.LoadLocation()] diff --git a/main.go b/main.go index 43551d9..49636c0 100644 --- a/main.go +++ b/main.go @@ -33,6 +33,8 @@ type NamedTimetableEntry struct { ActivityType string `json:"activityType"` } +var location *time.Location + // init and main// func init() { godotenv.Load(".env") @@ -50,6 +52,21 @@ func init() { } else { log.Println("No Discord webhook provided, Discord notifications will be disabled") } + + locEnv := os.Getenv("LOCATION_ENV") + + var locErr error + + location, locErr = time.LoadLocation(locEnv) + + if locErr != nil { + log.Fatalf("Failed to load timezone: %v", locErr) + } + log.Printf("Timezone set to: %s", location) +} + +func getTime() time.Time { + return time.Now().In(location) } func main() { @@ -132,7 +149,7 @@ func scheduleTimetableUpdate() { updateAllUsers() // Ticker for periodic updates - hourTicker := time.NewTicker(1 * time.Minute) // For testing, 1 minute. Change to 1 * time.Hour for production. + hourTicker := time.NewTicker(30 * time.Minute) go func() { for range hourTicker.C { updateAllUsers() @@ -141,7 +158,7 @@ func scheduleTimetableUpdate() { // Ticker for scheduled lesson notifications startMinuteTicker(func() { - now := time.Now() + now := getTime() if isScheduledTime(now) { log.Println("Scheduled time reached, running notifications...") accounts, _ := BotStart.LoadAndDecryptAccounts() @@ -156,7 +173,7 @@ func scheduleTimetableUpdate() { } func startMinuteTicker(f func()) { - now := time.Now() + now := getTime() next := now.Truncate(time.Minute).Add(time.Minute) time.Sleep(time.Until(next)) ticker := time.NewTicker(1 * time.Minute) @@ -185,7 +202,7 @@ func Run(userID string) { roomByStartTime, _ := MapTimeToRoom(timetableFile) subjectByStartTime, _ := MapTimeToSubject(timetableFile) - now := time.Now().Format("15:04") + now := getTime().Format("15:04") nextTime, room, foundRoom := NextRoomForTime(roomByStartTime, now) if !foundRoom { return // No upcoming lessons @@ -417,31 +434,7 @@ func sendUpdateDiscordWebhook() { log.Println("Sending Discord webhook notification...") // Create a rich embed message message := "A lesson on your timetable has changed" - /*embed := Embed{ - Title: "Next Lesson ", - Description: "The next lesson is starting soon: ", - Color: 3066993, // Green color - Timestamp: time.Now().Format(time.RFC3339), - Fields: []Field{ - { - Name: "New Lesson", - // Value: fmt.Sprintf("`%s`", ip), - Value: fmt.Sprintf("Room: %s", room), - Inline: true, - }, - { - Name: "Start-Time", - Value: fmt.Sprintf("Start time: %s", nextTime), - Inline: true, - }, - { - Name: "Status", - Value: fmt.Sprintf("Status: %s", Status), - Inline: true, - }, - }, - } - */ + payload := DiscordWebhookPayload{ Content: message, } From 17baaaf0874cc649dc1b7e2752533345ea6fb163 Mon Sep 17 00:00:00 2001 From: Jannover5000r <90698896+Jannover5000r@users.noreply.github.com> Date: Tue, 31 Mar 2026 03:36:19 +0200 Subject: [PATCH 4/4] timezone database added --- main.go | 1 + 1 file changed, 1 insertion(+) diff --git a/main.go b/main.go index 49636c0..bfa0b52 100644 --- a/main.go +++ b/main.go @@ -12,6 +12,7 @@ import ( "sort" "syscall" "time" + _ "time/tzdata" Untis "untislogger/Untis"