53 lines
879 B
Go
Raw Normal View History

2017-06-14 15:16:03 +00:00
package main
import (
"fmt"
"sort"
"github.com/animenotifier/arn"
"github.com/fatih/color"
)
func main() {
color.Yellow("Caching list of active users")
cache := arn.ListOfIDs{}
// Filter out active users with an avatar
users, err := arn.FilterUsers(func(user *arn.User) bool {
2017-07-08 13:40:13 +00:00
return user.IsActive() && user.AvatarExtension != ""
2017-06-14 15:16:03 +00:00
})
if err != nil {
panic(err)
}
// Sort
sort.Slice(users, func(i, j int) bool {
2017-06-23 14:53:07 +00:00
if users[i].LastSeen < users[j].LastSeen {
return false
}
if users[i].LastSeen > users[j].LastSeen {
return true
}
return users[i].Registered > users[j].Registered
2017-06-14 15:16:03 +00:00
})
// Add users to list
for _, user := range users {
cache.IDList = append(cache.IDList, user.ID)
}
fmt.Println(len(cache.IDList), "users")
err = arn.DB.Set("Cache", "active users", cache)
if err != nil {
panic(err)
}
color.Green("Finished.")
}