new changes to notification system
This commit is contained in:
parent
6c07bd9d13
commit
c29389e8f2
4 changed files with 55 additions and 29 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -8,5 +8,6 @@ timetable*.json
|
||||||
timetableFilled*.json
|
timetableFilled*.json
|
||||||
accounts.json
|
accounts.json
|
||||||
login_*.json
|
login_*.json
|
||||||
|
AGENTS.md
|
||||||
untislogger
|
untislogger
|
||||||
untislogger*
|
untislogger*
|
||||||
|
|
@ -199,7 +199,8 @@ func checkTimetableChangesForUser(user Account, decPwd string, s *discordgo.Sess
|
||||||
|
|
||||||
// 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!")
|
// The main.go now handles detailed change notifications
|
||||||
|
// This function is kept for compatibility but no longer sends generic messages
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
58
main.go
58
main.go
|
|
@ -101,6 +101,7 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
godotenv.Load(".env")
|
godotenv.Load(".env")
|
||||||
// Untis.Main() //starting API calls function| happens in schedule func
|
// Untis.Main() //starting API calls function| happens in schedule func
|
||||||
// Run()
|
// Run()
|
||||||
|
|
@ -315,6 +316,7 @@ func Run(userID string) {
|
||||||
nowOld := time.Now()
|
nowOld := time.Now()
|
||||||
nowOld = nowOld.Add(1 * time.Hour)
|
nowOld = nowOld.Add(1 * time.Hour)
|
||||||
now := nowOld.Format("15:04")
|
now := nowOld.Format("15:04")
|
||||||
|
|
||||||
nextTime, room, foundRoom := NextRoomForTime(roomByStartTime, now)
|
nextTime, room, foundRoom := NextRoomForTime(roomByStartTime, now)
|
||||||
if !foundRoom {
|
if !foundRoom {
|
||||||
return // No upcoming lessons
|
return // No upcoming lessons
|
||||||
|
|
@ -353,6 +355,10 @@ func NextRoomForTime(roomByStartTime map[string]string, current string) (string,
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", "", false
|
return "", "", false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Calculate 30 minutes from now
|
||||||
|
thirtyMinutesLater := now.Add(30 * time.Minute)
|
||||||
|
|
||||||
var times []time.Time
|
var times []time.Time
|
||||||
timeToStr := make(map[time.Time]string)
|
timeToStr := make(map[time.Time]string)
|
||||||
for t := range roomByStartTime {
|
for t := range roomByStartTime {
|
||||||
|
|
@ -360,16 +366,20 @@ func NextRoomForTime(roomByStartTime map[string]string, current string) (string,
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
// Only include times within the next 30 minutes
|
||||||
|
if parsed.After(now) && parsed.Before(thirtyMinutesLater) {
|
||||||
times = append(times, parsed)
|
times = append(times, parsed)
|
||||||
timeToStr[parsed] = t
|
timeToStr[parsed] = t
|
||||||
}
|
}
|
||||||
sort.Slice(times, func(i, j int) bool { return times[i].Before(times[j]) })
|
|
||||||
for _, t := range times {
|
|
||||||
if t.After(now) {
|
|
||||||
return timeToStr[t], roomByStartTime[timeToStr[t]], true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(times) == 0 {
|
||||||
return "", "", false
|
return "", "", false
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Slice(times, func(i, j int) bool { return times[i].Before(times[j]) })
|
||||||
|
// Return the first (earliest) room within the 30-minute window
|
||||||
|
return timeToStr[times[0]], roomByStartTime[timeToStr[times[0]]], true
|
||||||
}
|
}
|
||||||
|
|
||||||
func NextSubjectForTime(subjectByStartTime map[string]string, current string) (string, bool) {
|
func NextSubjectForTime(subjectByStartTime map[string]string, current string) (string, bool) {
|
||||||
|
|
@ -378,6 +388,10 @@ func NextSubjectForTime(subjectByStartTime map[string]string, current string) (s
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Calculate 30 minutes from now
|
||||||
|
thirtyMinutesLater := now.Add(30 * time.Minute)
|
||||||
|
|
||||||
var times []time.Time
|
var times []time.Time
|
||||||
timeToStr := make(map[time.Time]string)
|
timeToStr := make(map[time.Time]string)
|
||||||
for t := range subjectByStartTime {
|
for t := range subjectByStartTime {
|
||||||
|
|
@ -385,16 +399,20 @@ func NextSubjectForTime(subjectByStartTime map[string]string, current string) (s
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
// Only include times within the next 30 minutes
|
||||||
|
if parsed.After(now) && parsed.Before(thirtyMinutesLater) {
|
||||||
times = append(times, parsed)
|
times = append(times, parsed)
|
||||||
timeToStr[parsed] = t
|
timeToStr[parsed] = t
|
||||||
}
|
}
|
||||||
sort.Slice(times, func(i, j int) bool { return times[i].Before(times[j]) })
|
|
||||||
for _, t := range times {
|
|
||||||
if t.After(now) {
|
|
||||||
return subjectByStartTime[timeToStr[t]], true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(times) == 0 {
|
||||||
return "", false
|
return "", false
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Slice(times, func(i, j int) bool { return times[i].Before(times[j]) })
|
||||||
|
// Return the first (earliest) subject within the 30-minute window
|
||||||
|
return subjectByStartTime[timeToStr[times[0]]], true
|
||||||
}
|
}
|
||||||
|
|
||||||
func NextCodeForTime(codeByStartTime map[string]string, current string) (string, bool) {
|
func NextCodeForTime(codeByStartTime map[string]string, current string) (string, bool) {
|
||||||
|
|
@ -403,6 +421,10 @@ func NextCodeForTime(codeByStartTime map[string]string, current string) (string,
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Calculate 30 minutes from now
|
||||||
|
thirtyMinutesLater := now.Add(30 * time.Minute)
|
||||||
|
|
||||||
var times []time.Time
|
var times []time.Time
|
||||||
timeToStr := make(map[time.Time]string)
|
timeToStr := make(map[time.Time]string)
|
||||||
for t := range codeByStartTime {
|
for t := range codeByStartTime {
|
||||||
|
|
@ -410,16 +432,20 @@ func NextCodeForTime(codeByStartTime map[string]string, current string) (string,
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
// Only include times within the next 30 minutes
|
||||||
|
if parsed.After(now) && parsed.Before(thirtyMinutesLater) {
|
||||||
times = append(times, parsed)
|
times = append(times, parsed)
|
||||||
timeToStr[parsed] = t
|
timeToStr[parsed] = t
|
||||||
}
|
}
|
||||||
sort.Slice(times, func(i, j int) bool { return times[i].Before(times[j]) })
|
|
||||||
for _, t := range times {
|
|
||||||
if t.After(now) {
|
|
||||||
return codeByStartTime[timeToStr[t]], true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(times) == 0 {
|
||||||
return "", false
|
return "", false
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Slice(times, func(i, j int) bool { return times[i].Before(times[j]) })
|
||||||
|
// Return the first (earliest) code within the 30-minute window
|
||||||
|
return codeByStartTime[timeToStr[times[0]]], true
|
||||||
}
|
}
|
||||||
|
|
||||||
func MapTimeToRoom(path string) (map[string]string, error) {
|
func MapTimeToRoom(path string) (map[string]string, error) {
|
||||||
|
|
@ -454,11 +480,9 @@ func MapTimeToCode(path string) (map[string]string, error) {
|
||||||
codeByStartTime := make(map[string]string)
|
codeByStartTime := make(map[string]string)
|
||||||
for _, entry := range table {
|
for _, entry := range table {
|
||||||
if len(entry.Code) > 0 {
|
if len(entry.Code) > 0 {
|
||||||
if _, exists := codeByStartTime[entry.StartTime]; !exists {
|
|
||||||
codeByStartTime[entry.StartTime] = entry.Code
|
codeByStartTime[entry.StartTime] = entry.Code
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return codeByStartTime, nil
|
return codeByStartTime, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
BIN
untislogger
BIN
untislogger
Binary file not shown.
Loading…
Reference in a new issue