Sort chanenls + multi-line action rows

This commit is contained in:
rxdn 2021-05-29 17:04:23 +01:00
parent 10852a01e2
commit 3bfb958f15
3 changed files with 19 additions and 1 deletions

View File

@ -4,6 +4,7 @@ import (
"github.com/TicketsBot/GoPanel/rpc/cache" "github.com/TicketsBot/GoPanel/rpc/cache"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/rxdn/gdl/objects/channel" "github.com/rxdn/gdl/objects/channel"
"sort"
) )
func ChannelsHandler(ctx *gin.Context) { func ChannelsHandler(ctx *gin.Context) {
@ -12,6 +13,10 @@ func ChannelsHandler(ctx *gin.Context) {
channels := cache.Instance.GetGuildChannels(guildId) channels := cache.Instance.GetGuildChannels(guildId)
if channels == nil { if channels == nil {
channels = make([]channel.Channel, 0) // don't serve null channels = make([]channel.Channel, 0) // don't serve null
} else {
sort.Slice(channels, func(i,j int) bool {
return channels[i].Position < channels[j].Position
})
} }
ctx.JSON(200, channels) ctx.JSON(200, channels)

View File

@ -18,6 +18,7 @@ import (
"github.com/rxdn/gdl/rest" "github.com/rxdn/gdl/rest"
"github.com/rxdn/gdl/rest/request" "github.com/rxdn/gdl/rest/request"
"golang.org/x/sync/errgroup" "golang.org/x/sync/errgroup"
"math"
) )
type multiPanelCreateData struct { type multiPanelCreateData struct {
@ -210,6 +211,18 @@ func (d *multiPanelCreateData) sendEmbed(ctx *botcontext.BotContext, isPremium b
}) })
} }
var rows []component.Component
for i := 0; i < int(math.Ceil(float64(len(buttons) / 5))); i++ {
lb := i * 5
ub := lb + 5
if ub > len(buttons) {
ub = len(buttons) - 1
}
row := component.BuildActionRow(buttons[lb:ub]...)
rows = append(rows, row)
}
data := rest.CreateMessageData{ data := rest.CreateMessageData{
Embed: e, Embed: e,
Components: []component.Component{ Components: []component.Component{

2
go.mod
View File

@ -6,7 +6,7 @@ require (
github.com/BurntSushi/toml v0.3.1 github.com/BurntSushi/toml v0.3.1
github.com/TicketsBot/archiverclient v0.0.0-20210220155137-a562b2f1bbbb github.com/TicketsBot/archiverclient v0.0.0-20210220155137-a562b2f1bbbb
github.com/TicketsBot/common v0.0.0-20210527174309-f7344004ae32 github.com/TicketsBot/common v0.0.0-20210527174309-f7344004ae32
github.com/TicketsBot/database v0.0.0-20210528165404-2addee803304 github.com/TicketsBot/database v0.0.0-20210529142156-eafeb876ca9a
github.com/TicketsBot/worker v0.0.0-20210528135955-34744f610804 github.com/TicketsBot/worker v0.0.0-20210528135955-34744f610804
github.com/apex/log v1.1.2 github.com/apex/log v1.1.2
github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff // indirect github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff // indirect