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"