From c9a5dd2ff5938daf6ad87b4cd47b5bdaf3e2aad4 Mon Sep 17 00:00:00 2001 From: Jannover5000r Date: Fri, 14 Nov 2025 09:10:35 +0100 Subject: [PATCH] fixed the account creation --- Botrun/BotStart.go | 7 +++++++ main.go | 27 +++++++++++++-------------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/Botrun/BotStart.go b/Botrun/BotStart.go index 6338df3..acf7067 100644 --- a/Botrun/BotStart.go +++ b/Botrun/BotStart.go @@ -12,6 +12,7 @@ import ( "io" "os" "os/signal" + "path/filepath" "sync" "syscall" "time" @@ -108,6 +109,12 @@ func decrypt(encrypted string) (string, error) { func saveAccount(userID, username, password string) error { var accounts []Account + // Ensure the accounts directory exists + accountsDir := filepath.Dir(accountsFile) + if err := os.MkdirAll(accountsDir, 0755); err != nil { + return fmt.Errorf("failed to create accounts directory: %v", err) + } + // Load existing accounts if file exists if data, err := os.ReadFile(accountsFile); err == nil && len(data) > 0 { _ = json.Unmarshal(data, &accounts) diff --git a/main.go b/main.go index 398dc06..5b8c983 100644 --- a/main.go +++ b/main.go @@ -101,7 +101,6 @@ func init() { } func main() { - godotenv.Load(".env") // Untis.Main() //starting API calls function| happens in schedule func // Run() @@ -316,7 +315,7 @@ func Run(userID string) { nowOld := time.Now() nowOld = nowOld.Add(1 * time.Hour) now := nowOld.Format("15:04") - + nextTime, room, foundRoom := NextRoomForTime(roomByStartTime, now) if !foundRoom { return // No upcoming lessons @@ -355,10 +354,10 @@ func NextRoomForTime(roomByStartTime map[string]string, current string) (string, if err != nil { return "", "", false } - + // Calculate 30 minutes from now thirtyMinutesLater := now.Add(30 * time.Minute) - + var times []time.Time timeToStr := make(map[time.Time]string) for t := range roomByStartTime { @@ -372,11 +371,11 @@ func NextRoomForTime(roomByStartTime map[string]string, current string) (string, timeToStr[parsed] = t } } - + if len(times) == 0 { 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 @@ -388,10 +387,10 @@ func NextSubjectForTime(subjectByStartTime map[string]string, current string) (s if err != nil { return "", false } - + // Calculate 30 minutes from now thirtyMinutesLater := now.Add(30 * time.Minute) - + var times []time.Time timeToStr := make(map[time.Time]string) for t := range subjectByStartTime { @@ -405,11 +404,11 @@ func NextSubjectForTime(subjectByStartTime map[string]string, current string) (s timeToStr[parsed] = t } } - + if len(times) == 0 { 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 @@ -421,10 +420,10 @@ func NextCodeForTime(codeByStartTime map[string]string, current string) (string, if err != nil { return "", false } - + // Calculate 30 minutes from now thirtyMinutesLater := now.Add(30 * time.Minute) - + var times []time.Time timeToStr := make(map[time.Time]string) for t := range codeByStartTime { @@ -438,11 +437,11 @@ func NextCodeForTime(codeByStartTime map[string]string, current string) (string, timeToStr[parsed] = t } } - + if len(times) == 0 { 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