56 lines
1.1 KiB
Go
Raw Normal View History

2017-06-06 13:51:22 +00:00
package main
import (
2019-04-23 05:45:17 +00:00
"github.com/akyoto/color"
2019-06-03 09:32:43 +00:00
"github.com/animenotifier/notify.moe/arn"
2017-06-06 13:51:22 +00:00
)
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 != "" {
2019-06-05 06:45:54 +00:00
err := user.SetEmail(user.Email)
if err != nil {
color.Red(err.Error())
}
2017-06-08 09:51:34 +00:00
}
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.")
}