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.
This commit is contained in:
parent
b76b2c72f1
commit
8b42761cf0
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