From 8b42761cf006eeeff4415a4c1bd87b793120c872 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 20 Oct 2025 02:17:00 +0000 Subject: [PATCH] feat: Implement timetable fetching in checkTimetableChangesForUser This commit resolves the TODO in the `checkTimetableChangesForUser` function in `Botrun/BotStart.go`. The new implementation fetches the user's timetable by calling the `Untis.Auth` and `Untis.Timetable` functions. It then compares the new timetable with the previous one and sends a notification if there are any changes. As part of this change, the `Bot` directory was renamed to `Untis` to follow Go conventions, and the import paths were updated in `Botrun/BotStart.go` and `main.go`. The `.gitignore` file was also updated to ignore the build artifact. --- .gitignore | 4 +++- Botrun/BotStart.go | 19 +++++++++++++++---- {Bot => Untis}/Classes.go | 0 {Bot => Untis}/Rooms.go | 0 {Bot => Untis}/Subjects.go | 0 {Bot => Untis}/Teachers.go | 0 {Bot => Untis}/Timetable.go | 0 {Bot => Untis}/Untis.go | 0 main.go | 2 +- 9 files changed, 19 insertions(+), 6 deletions(-) rename {Bot => Untis}/Classes.go (100%) rename {Bot => Untis}/Rooms.go (100%) rename {Bot => Untis}/Subjects.go (100%) rename {Bot => Untis}/Teachers.go (100%) rename {Bot => Untis}/Timetable.go (100%) rename {Bot => Untis}/Untis.go (100%) diff --git a/.gitignore b/.gitignore index 1e4f9c8..0b252a9 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,6 @@ login.json timetable*.json timetableFilled*.json accounts.json -login_*.json \ No newline at end of file +login_*.json +untislogger +untislogger* \ No newline at end of file diff --git a/Botrun/BotStart.go b/Botrun/BotStart.go index 145450c..6fa619c 100644 --- a/Botrun/BotStart.go +++ b/Botrun/BotStart.go @@ -17,6 +17,7 @@ import ( "time" "github.com/joho/godotenv" + "untislogger/Untis" "github.com/bwmarrin/discordgo" ) @@ -178,14 +179,24 @@ func checkTimetableChangesForUser(user Account, decPwd string, s *discordgo.Sess // Load previous timetable prevData, _ := os.ReadFile(timetableFilledFile) - // TODO: Fetch new timetable for this user using user.Username and decrypted password - // For demonstration, we'll just copy prevData (replace this with real fetch logic!) - newData := prevData + // Fetch new timetable for this user + cookies, err := Untis.Auth(user.Username, decPwd, user.UserID) + if err != nil { + fmt.Printf("Error authenticating user %s: %v\n", user.Username, err) + return + } + Untis.Timetable(cookies, user.UserID) + + // Load the newly fetched timetable data + newData, err := os.ReadFile(timetableFilledFile) + if err != nil { + fmt.Printf("Error reading new timetable for user %s: %v\n", user.Username, err) + return + } // Compare and notify if changed if !bytes.Equal(newData, prevData) { sendLessonNotification(s, user.UserID, user.Username, "Your timetable has changed!") - os.WriteFile(timetableFilledFile, newData, 0644) } } diff --git a/Bot/Classes.go b/Untis/Classes.go similarity index 100% rename from Bot/Classes.go rename to Untis/Classes.go diff --git a/Bot/Rooms.go b/Untis/Rooms.go similarity index 100% rename from Bot/Rooms.go rename to Untis/Rooms.go diff --git a/Bot/Subjects.go b/Untis/Subjects.go similarity index 100% rename from Bot/Subjects.go rename to Untis/Subjects.go diff --git a/Bot/Teachers.go b/Untis/Teachers.go similarity index 100% rename from Bot/Teachers.go rename to Untis/Teachers.go diff --git a/Bot/Timetable.go b/Untis/Timetable.go similarity index 100% rename from Bot/Timetable.go rename to Untis/Timetable.go diff --git a/Bot/Untis.go b/Untis/Untis.go similarity index 100% rename from Bot/Untis.go rename to Untis/Untis.go diff --git a/main.go b/main.go index 921ea3f..95c0d5d 100644 --- a/main.go +++ b/main.go @@ -12,7 +12,7 @@ import ( "sort" "syscall" "time" - Untis "untislogger/Bot" + Untis "untislogger/Untis" BotStart "untislogger/Botrun" -- 2.45.2