add some copypasted code to make admins come first in /users
This commit is contained in:
parent
360b96b40a
commit
31f82aa928
@ -5,6 +5,7 @@ import (
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@ -36,6 +37,22 @@ type Userinfo struct {
|
||||
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 {
|
||||
regex := "(^| )" + username + "($| )"
|
||||
isonline, err := regexp.MatchString(string(regex), string(usersonline))
|
||||
@ -154,6 +171,7 @@ func UsersPage(c *fiber.Ctx) error {
|
||||
),
|
||||
)
|
||||
}
|
||||
sort.Sort(ByAdminAndName(userinfostruct))
|
||||
data := Userstruct{
|
||||
Status: c.Response().StatusCode(),
|
||||
Online: output,
|
||||
|
Loading…
Reference in New Issue
Block a user