feat: Implement timetable fetching in checkTimetableChangesForUser #3
9 changed files with 19 additions and 6 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -7,4 +7,6 @@ login.json
|
||||||
timetable*.json
|
timetable*.json
|
||||||
timetableFilled*.json
|
timetableFilled*.json
|
||||||
accounts.json
|
accounts.json
|
||||||
login_*.json
|
login_*.json
|
||||||
|
untislogger
|
||||||
|
untislogger*
|
||||||
|
|
@ -17,6 +17,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
|
"untislogger/Untis"
|
||||||
|
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
)
|
)
|
||||||
|
|
@ -178,14 +179,24 @@ func checkTimetableChangesForUser(user Account, decPwd string, s *discordgo.Sess
|
||||||
// Load previous timetable
|
// Load previous timetable
|
||||||
prevData, _ := os.ReadFile(timetableFilledFile)
|
prevData, _ := os.ReadFile(timetableFilledFile)
|
||||||
|
|
||||||
// TODO: Fetch new timetable for this user using user.Username and decrypted password
|
// Fetch new timetable for this user
|
||||||
// For demonstration, we'll just copy prevData (replace this with real fetch logic!)
|
cookies, err := Untis.Auth(user.Username, decPwd, user.UserID)
|
||||||
newData := prevData
|
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
|
// Compare and notify if changed
|
||||||
if !bytes.Equal(newData, prevData) {
|
if !bytes.Equal(newData, prevData) {
|
||||||
sendLessonNotification(s, user.UserID, user.Username, "Your timetable has changed!")
|
sendLessonNotification(s, user.UserID, user.Username, "Your timetable has changed!")
|
||||||
os.WriteFile(timetableFilledFile, newData, 0644)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
2
main.go
2
main.go
|
|
@ -12,7 +12,7 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
Untis "untislogger/Bot"
|
Untis "untislogger/Untis"
|
||||||
|
|
||||||
BotStart "untislogger/Botrun"
|
BotStart "untislogger/Botrun"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue