add some copypasted code to make admins come first in /users

This commit is contained in:
Arya 2023-07-14 15:54:20 +05:30
parent 360b96b40a
commit 31f82aa928
Signed by untrusted user: arya
GPG Key ID: 842D12BDA50DF120

View File

@ -5,6 +5,7 @@ import (
"os/exec" "os/exec"
"regexp" "regexp"
"runtime" "runtime"
"sort"
"strconv" "strconv"
"strings" "strings"
@ -36,6 +37,22 @@ type Userinfo struct {
Loc string `json:"loc"` Loc string `json:"loc"`
} }
type ByAdminAndName []Userinfo
func (a ByAdminAndName) Len() int { return len(a) }
func (a ByAdminAndName) Less(i, j int) bool {
// If one person is an admin and the other is not, place the admin first
if a[i].Op && !a[j].Op {
return true
} else if !a[i].Op && a[j].Op {
return false
}
// If both persons are admins or both are not, sort by name
return a[i].Name < a[j].Name
}
func (a ByAdminAndName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func userdata(username, usersonline, ops string) Userinfo { func userdata(username, usersonline, ops string) Userinfo {
regex := "(^| )" + username + "($| )" regex := "(^| )" + username + "($| )"
isonline, err := regexp.MatchString(string(regex), string(usersonline)) isonline, err := regexp.MatchString(string(regex), string(usersonline))
@ -154,6 +171,7 @@ func UsersPage(c *fiber.Ctx) error {
), ),
) )
} }
sort.Sort(ByAdminAndName(userinfostruct))
data := Userstruct{ data := Userstruct{
Status: c.Response().StatusCode(), Status: c.Response().StatusCode(),
Online: output, Online: output,