52 lines
1.0 KiB
Go
Raw Normal View History

2017-06-06 13:51:22 +00:00
package main
import (
"github.com/animenotifier/arn"
"github.com/fatih/color"
)
func main() {
color.Yellow("Updating user references")
2017-11-01 19:11:05 +00:00
defer arn.Node.Close()
2017-06-06 13:51:22 +00:00
2017-11-01 19:11:05 +00:00
arn.DB.Clear("NickToUser")
arn.DB.Clear("EmailToUser")
arn.DB.Clear("GoogleToUser")
arn.DB.Clear("FacebookToUser")
2017-06-06 13:51:22 +00:00
// Iterate over the stream
count := 0
2017-11-01 19:11:05 +00:00
2018-11-08 18:41:54 +00:00
users, err := arn.AllUsers()
arn.PanicOnError(err)
// Make the most recently seen users overwrite the references of older accounts.
// Some people accidentally created 2 accounts and in case of overlaps we want
// to keep the references for the account that is more likely used.
arn.SortUsersLastSeenLast(users)
// Write new references
for _, user := range users {
2017-06-06 13:51:22 +00:00
count++
println(count, user.Nick)
2017-06-24 00:10:04 +00:00
user.ForceSetNick(user.Nick)
2017-06-08 09:51:34 +00:00
if user.Email != "" {
user.SetEmail(user.Email)
}
2017-06-15 21:03:55 +00:00
if user.Accounts.Google.ID != "" {
2017-07-02 21:42:46 +00:00
user.ConnectGoogle(user.Accounts.Google.ID)
}
if user.Accounts.Facebook.ID != "" {
user.ConnectFacebook(user.Accounts.Facebook.ID)
2017-06-15 21:03:55 +00:00
}
2018-11-08 18:41:54 +00:00
user.Save()
2017-06-06 13:51:22 +00:00
}
color.Green("Finished.")
}