2016-12-06 03:36:31 +00:00
|
|
|
package users
|
|
|
|
|
|
|
|
import (
|
2017-10-28 01:53:12 +00:00
|
|
|
"sort"
|
2017-06-10 00:19:31 +00:00
|
|
|
|
2016-12-06 03:36:31 +00:00
|
|
|
"github.com/aerogo/aero"
|
2017-06-10 00:19:31 +00:00
|
|
|
"github.com/animenotifier/arn"
|
2016-12-06 03:36:31 +00:00
|
|
|
"github.com/animenotifier/notify.moe/components"
|
2017-11-30 15:40:52 +00:00
|
|
|
"github.com/animenotifier/notify.moe/utils"
|
2016-12-06 03:36:31 +00:00
|
|
|
)
|
|
|
|
|
2017-07-19 11:08:12 +00:00
|
|
|
// Active ...
|
|
|
|
func Active(ctx *aero.Context) string {
|
2017-10-27 07:11:56 +00:00
|
|
|
users := arn.FilterUsers(func(user *arn.User) bool {
|
2018-03-04 14:20:21 +00:00
|
|
|
return user.HasAvatar() && user.HasNick() && user.IsActive()
|
2017-10-27 07:11:56 +00:00
|
|
|
})
|
2017-07-19 11:08:12 +00:00
|
|
|
|
2018-03-08 00:45:55 +00:00
|
|
|
followCount := arn.UserFollowerCountMap()
|
2017-11-18 10:28:53 +00:00
|
|
|
|
2017-11-03 08:34:21 +00:00
|
|
|
sort.Slice(users, func(i, j int) bool {
|
2017-11-30 15:40:52 +00:00
|
|
|
if users[i].HasAvatar() != users[j].HasAvatar() {
|
2018-04-25 23:14:23 +00:00
|
|
|
return users[i].HasAvatar()
|
2017-11-30 15:40:52 +00:00
|
|
|
}
|
|
|
|
|
2018-03-08 00:45:55 +00:00
|
|
|
followersA := followCount[users[i].ID]
|
|
|
|
followersB := followCount[users[j].ID]
|
2017-11-17 14:16:47 +00:00
|
|
|
|
|
|
|
if followersA == followersB {
|
2017-11-17 14:21:56 +00:00
|
|
|
return users[i].Nick < users[j].Nick
|
2017-11-17 14:16:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return followersA > followersB
|
2017-11-03 08:34:21 +00:00
|
|
|
})
|
|
|
|
|
2018-03-10 15:42:39 +00:00
|
|
|
return ctx.HTML(components.Users(users, ctx.URI()))
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pro ...
|
|
|
|
func Pro(ctx *aero.Context) string {
|
|
|
|
users := arn.FilterUsers(func(user *arn.User) bool {
|
|
|
|
return user.IsPro()
|
|
|
|
})
|
|
|
|
|
|
|
|
sort.Slice(users, func(i, j int) bool {
|
|
|
|
return users[i].Registered > users[j].Registered
|
|
|
|
})
|
|
|
|
|
|
|
|
return ctx.HTML(components.ProUsers(users, ctx.URI()))
|
|
|
|
}
|
|
|
|
|
|
|
|
// Editors ...
|
|
|
|
func Editors(ctx *aero.Context) string {
|
|
|
|
score := map[string]int{}
|
|
|
|
users := []*arn.User{}
|
|
|
|
|
|
|
|
for entry := range arn.StreamEditLogEntries() {
|
|
|
|
entryScore := entry.EditorScore()
|
|
|
|
|
|
|
|
if entryScore == 0 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
current, exists := score[entry.UserID]
|
|
|
|
|
|
|
|
if !exists {
|
|
|
|
users = append(users, entry.User())
|
|
|
|
}
|
|
|
|
|
|
|
|
score[entry.UserID] = current + entryScore
|
|
|
|
}
|
|
|
|
|
2018-03-10 16:32:28 +00:00
|
|
|
for ignore := range arn.StreamIgnoreAnimeDifferences() {
|
|
|
|
score[ignore.CreatedBy] += arn.IgnoreAnimeDifferenceEditorScore
|
|
|
|
}
|
|
|
|
|
2018-03-10 15:42:39 +00:00
|
|
|
sort.Slice(users, func(i, j int) bool {
|
|
|
|
scoreA := score[users[i].ID]
|
|
|
|
scoreB := score[users[j].ID]
|
|
|
|
|
|
|
|
if scoreA == scoreB {
|
|
|
|
return users[i].Registered > users[j].Registered
|
|
|
|
}
|
|
|
|
|
|
|
|
return scoreA > scoreB
|
|
|
|
})
|
|
|
|
|
2018-11-01 03:57:11 +00:00
|
|
|
if len(users) > 10 {
|
|
|
|
users = users[:10]
|
|
|
|
}
|
|
|
|
|
2018-03-10 15:43:57 +00:00
|
|
|
return ctx.HTML(components.EditorRankingList(users, score, ctx.URI()))
|
2017-11-30 15:40:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ActiveNoAvatar ...
|
|
|
|
func ActiveNoAvatar(ctx *aero.Context) string {
|
|
|
|
users := arn.FilterUsers(func(user *arn.User) bool {
|
|
|
|
return user.IsActive() && !user.HasAvatar()
|
|
|
|
})
|
|
|
|
|
2018-03-08 00:45:55 +00:00
|
|
|
followCount := arn.UserFollowerCountMap()
|
2017-11-30 15:40:52 +00:00
|
|
|
|
|
|
|
sort.Slice(users, func(i, j int) bool {
|
|
|
|
if users[i].HasAvatar() != users[j].HasAvatar() {
|
2018-04-25 23:14:23 +00:00
|
|
|
return users[i].HasAvatar()
|
2017-11-30 15:40:52 +00:00
|
|
|
}
|
|
|
|
|
2018-03-08 00:46:19 +00:00
|
|
|
followersA := followCount[users[i].ID]
|
|
|
|
followersB := followCount[users[j].ID]
|
2017-11-30 15:40:52 +00:00
|
|
|
|
|
|
|
if followersA == followersB {
|
|
|
|
return users[i].Nick < users[j].Nick
|
|
|
|
}
|
|
|
|
|
|
|
|
return followersA > followersB
|
|
|
|
})
|
2017-07-19 11:08:12 +00:00
|
|
|
|
2018-03-10 15:42:39 +00:00
|
|
|
return ctx.HTML(components.Users(users, ctx.URI()))
|
2017-07-19 11:08:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Osu ...
|
|
|
|
func Osu(ctx *aero.Context) string {
|
2017-10-28 01:53:12 +00:00
|
|
|
users := arn.FilterUsers(func(user *arn.User) bool {
|
2018-03-04 14:20:21 +00:00
|
|
|
return user.HasAvatar() && user.HasNick() && user.IsActive() && user.Accounts.Osu.PP > 0
|
2017-10-28 01:53:12 +00:00
|
|
|
})
|
2017-07-19 11:08:12 +00:00
|
|
|
|
2017-10-28 01:53:12 +00:00
|
|
|
// Sort by pp
|
|
|
|
sort.Slice(users, func(i, j int) bool {
|
|
|
|
return users[i].Accounts.Osu.PP > users[j].Accounts.Osu.PP
|
|
|
|
})
|
2017-07-19 11:08:12 +00:00
|
|
|
|
2018-11-01 03:57:11 +00:00
|
|
|
if len(users) > 10 {
|
|
|
|
users = users[:10]
|
2017-10-07 08:52:59 +00:00
|
|
|
}
|
|
|
|
|
2018-03-10 15:42:39 +00:00
|
|
|
return ctx.HTML(components.OsuRankingList(users, ctx.URI()))
|
2017-07-19 11:08:12 +00:00
|
|
|
}
|
|
|
|
|
2017-11-30 15:40:52 +00:00
|
|
|
// Overwatch ...
|
|
|
|
func Overwatch(ctx *aero.Context) string {
|
|
|
|
users := arn.FilterUsers(func(user *arn.User) bool {
|
2018-03-04 14:20:21 +00:00
|
|
|
return user.HasAvatar() && user.HasNick() && user.IsActive() && user.Accounts.Overwatch.SkillRating > 0
|
2017-11-30 15:40:52 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
// Sort by Skill Ratings
|
|
|
|
sort.Slice(users, func(i, j int) bool {
|
|
|
|
return users[i].Accounts.Overwatch.SkillRating > users[j].Accounts.Overwatch.SkillRating
|
|
|
|
})
|
|
|
|
|
2018-11-01 03:57:11 +00:00
|
|
|
if len(users) > 10 {
|
|
|
|
users = users[:10]
|
2017-11-30 15:40:52 +00:00
|
|
|
}
|
|
|
|
|
2018-03-10 15:42:39 +00:00
|
|
|
return ctx.HTML(components.OverwatchRankingList(users, ctx.URI()))
|
2017-11-30 15:40:52 +00:00
|
|
|
}
|
|
|
|
|
2018-10-30 20:24:12 +00:00
|
|
|
// FFXIV ...
|
|
|
|
func FFXIV(ctx *aero.Context) string {
|
|
|
|
users := arn.FilterUsers(func(user *arn.User) bool {
|
|
|
|
return user.HasAvatar() && user.HasNick() && user.IsActive() && user.Accounts.FinalFantasyXIV.ItemLevel > 0
|
|
|
|
})
|
|
|
|
|
|
|
|
// Sort by item level
|
|
|
|
sort.Slice(users, func(i, j int) bool {
|
|
|
|
return users[i].Accounts.FinalFantasyXIV.ItemLevel > users[j].Accounts.FinalFantasyXIV.ItemLevel
|
|
|
|
})
|
|
|
|
|
2018-11-01 03:57:11 +00:00
|
|
|
if len(users) > 10 {
|
|
|
|
users = users[:10]
|
2018-10-30 20:24:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ctx.HTML(components.FinalFantasyXIVRankingList(users, ctx.URI()))
|
|
|
|
}
|
|
|
|
|
2017-07-19 11:08:12 +00:00
|
|
|
// Staff ...
|
|
|
|
func Staff(ctx *aero.Context) string {
|
2017-10-28 01:53:12 +00:00
|
|
|
users := arn.FilterUsers(func(user *arn.User) bool {
|
2018-03-04 14:20:21 +00:00
|
|
|
return user.HasAvatar() && user.HasNick() && user.IsActive() && user.Role != ""
|
2017-10-28 01:53:12 +00:00
|
|
|
})
|
2017-07-19 11:08:12 +00:00
|
|
|
|
2017-11-30 15:40:52 +00:00
|
|
|
// Make order deterministic
|
2017-10-28 01:53:12 +00:00
|
|
|
sort.Slice(users, func(i, j int) bool {
|
2017-11-30 15:40:52 +00:00
|
|
|
return users[i].Nick < users[j].Nick
|
|
|
|
})
|
|
|
|
|
|
|
|
admins := &utils.UserList{
|
|
|
|
Name: "Developer",
|
|
|
|
Users: []*arn.User{},
|
|
|
|
}
|
|
|
|
|
|
|
|
contributors := &utils.UserList{
|
|
|
|
Name: "Contributors",
|
|
|
|
Users: []*arn.User{},
|
|
|
|
}
|
|
|
|
|
|
|
|
// contributors.Users = append(contributors.Users, )
|
|
|
|
|
|
|
|
editors := &utils.UserList{
|
|
|
|
Name: "Editors",
|
|
|
|
Users: []*arn.User{},
|
|
|
|
}
|
|
|
|
|
2018-10-28 01:53:57 +00:00
|
|
|
contributorIDs := []string{
|
|
|
|
"VJOK1ckvx", // Scott
|
|
|
|
"SUQOAFFkR", // Allen
|
|
|
|
"KQgtMWOiR", // Franksks
|
|
|
|
"9NMYrAHiR", // Amatrelan
|
|
|
|
}
|
|
|
|
|
2017-11-30 15:40:52 +00:00
|
|
|
for _, user := range users {
|
|
|
|
if user.Role == "admin" {
|
|
|
|
admins.Users = append(admins.Users, user)
|
|
|
|
continue
|
2017-10-28 01:53:12 +00:00
|
|
|
}
|
|
|
|
|
2018-10-28 01:53:57 +00:00
|
|
|
if arn.Contains(contributorIDs, user.ID) {
|
2017-11-30 15:40:52 +00:00
|
|
|
contributors.Users = append(contributors.Users, user)
|
|
|
|
continue
|
2017-10-28 01:53:12 +00:00
|
|
|
}
|
|
|
|
|
2017-11-30 15:40:52 +00:00
|
|
|
if user.Role == "editor" {
|
|
|
|
editors.Users = append(editors.Users, user)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
2017-07-19 11:08:12 +00:00
|
|
|
|
2017-11-30 15:40:52 +00:00
|
|
|
userLists := []*utils.UserList{
|
|
|
|
admins,
|
|
|
|
contributors,
|
|
|
|
editors,
|
|
|
|
}
|
|
|
|
|
2018-03-10 15:42:39 +00:00
|
|
|
return ctx.HTML(components.UserLists(userLists, ctx.URI()) + components.StaffRecruitment())
|
2017-07-19 11:08:12 +00:00
|
|
|
}
|