diff --git a/praktikant.go b/praktikant.go index a510c49..b473bf9 100644 --- a/praktikant.go +++ b/praktikant.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "strconv" + "strings" "time" "github.com/gookit/color" @@ -17,6 +18,34 @@ func Arbeiten() { } func Arbeit() { + // check appointments + appoints, err := ReadAppointments() + if err != nil { + if !strings.Contains(err.Error(), "not found") && err != nutsdb.ErrBucketEmpty { + color.Errorln(err.Error()) + logOut.WriteError(err) + } + } else { + cleared := 0 + for _, a := range appoints { + if a.Time.Before(time.Now()) { + // appointment expired + keyBytes := Int64AndDateToBytes(a.Anime, a.Time) + err = DbDelete(bucketAppoint, string(keyBytes)) + if err != nil { + color.Errorln(err.Error()) + logOut.WriteError(err) + } else { + cleared++ + } + } + } + if cleared > 0 { + color.Infof("Cleared %d expired appointments\n", cleared) + logOut.WriteLine(fmt.Sprintf("♻️ Cleared %d expired appointments", cleared)) + } + } + // refresh animelist of users animesUsers, err := ReadAnimeUsers() if err != nil {