mirror of
https://github.com/diamondburned/arikawa.git
synced 2025-11-28 07:11:06 +00:00
discord: Add SortRolesByPosition helper function
This commit is contained in:
parent
796b798f6a
commit
1782301df9
|
|
@ -1,6 +1,9 @@
|
||||||
package discord
|
package discord
|
||||||
|
|
||||||
import "time"
|
import (
|
||||||
|
"sort"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
// https://discord.com/developers/docs/resources/guild#guild-object
|
// https://discord.com/developers/docs/resources/guild#guild-object
|
||||||
type Guild struct {
|
type Guild struct {
|
||||||
|
|
@ -363,6 +366,15 @@ func (r Role) IconURLWithType(t ImageType) string {
|
||||||
return "https://cdn.discordapp.com/role-icons/" + r.ID.String() + "/" + t.format(r.Icon)
|
return "https://cdn.discordapp.com/role-icons/" + r.ID.String() + "/" + t.format(r.Icon)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SortRolesByPosition sorts the roles by their position.
|
||||||
|
// Roles with a higher position will be first in the slice, similar to how
|
||||||
|
// Discord sorts roles in the client.
|
||||||
|
func SortRolesByPosition(roles []Role) {
|
||||||
|
sort.Slice(roles, func(i, j int) bool {
|
||||||
|
return roles[i].Position > roles[j].Position
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// https://discord.com/developers/docs/resources/guild#guild-member-object
|
// https://discord.com/developers/docs/resources/guild#guild-member-object
|
||||||
//
|
//
|
||||||
// The field user won't be included in the member object attached to
|
// The field user won't be included in the member object attached to
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue