Improved user sort
This commit is contained in:
parent
8c182f8a4e
commit
8bee2f4e10
@ -24,7 +24,15 @@ func main() {
|
|||||||
|
|
||||||
// Sort
|
// Sort
|
||||||
sort.Slice(users, func(i, j int) bool {
|
sort.Slice(users, func(i, j int) bool {
|
||||||
return users[i].LastSeen > users[j].LastSeen
|
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
|
||||||
})
|
})
|
||||||
|
|
||||||
// Add users to list
|
// Add users to list
|
||||||
|
29
patches/add-last-seen/main.go
Normal file
29
patches/add-last-seen/main.go
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/animenotifier/arn"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
// Get a stream of all users
|
||||||
|
allUsers, err := arn.AllUsers()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Iterate over the stream
|
||||||
|
for user := range allUsers {
|
||||||
|
if user.LastSeen != "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
user.LastSeen = user.LastLogin
|
||||||
|
|
||||||
|
if user.LastSeen == "" {
|
||||||
|
user.LastSeen = user.Registered
|
||||||
|
}
|
||||||
|
|
||||||
|
user.Save()
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user