From 3bfb958f15c22fd85e7ebdef9fc32f8b48bfb273 Mon Sep 17 00:00:00 2001 From: rxdn <29165304+rxdn@users.noreply.github.com> Date: Sat, 29 May 2021 17:04:23 +0100 Subject: [PATCH] Sort chanenls + multi-line action rows --- app/http/endpoints/api/channels.go | 5 +++++ app/http/endpoints/api/panel/multipanelcreate.go | 13 +++++++++++++ go.mod | 2 +- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/http/endpoints/api/channels.go b/app/http/endpoints/api/channels.go index f80c7e7..18e6d23 100644 --- a/app/http/endpoints/api/channels.go +++ b/app/http/endpoints/api/channels.go @@ -4,6 +4,7 @@ import ( "github.com/TicketsBot/GoPanel/rpc/cache" "github.com/gin-gonic/gin" "github.com/rxdn/gdl/objects/channel" + "sort" ) func ChannelsHandler(ctx *gin.Context) { @@ -12,6 +13,10 @@ func ChannelsHandler(ctx *gin.Context) { channels := cache.Instance.GetGuildChannels(guildId) if channels == nil { 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) diff --git a/app/http/endpoints/api/panel/multipanelcreate.go b/app/http/endpoints/api/panel/multipanelcreate.go index 08e4e7a..4f02343 100644 --- a/app/http/endpoints/api/panel/multipanelcreate.go +++ b/app/http/endpoints/api/panel/multipanelcreate.go @@ -18,6 +18,7 @@ import ( "github.com/rxdn/gdl/rest" "github.com/rxdn/gdl/rest/request" "golang.org/x/sync/errgroup" + "math" ) 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{ Embed: e, Components: []component.Component{ diff --git a/go.mod b/go.mod index 8353018..20f01cc 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/BurntSushi/toml v0.3.1 github.com/TicketsBot/archiverclient v0.0.0-20210220155137-a562b2f1bbbb 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/apex/log v1.1.2 github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff // indirect