mirror of
https://github.com/ultrasn0w/huso.git
synced 2025-12-14 02:29:53 +01:00
Clear expired appointments
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user