Fix multipanel creation

This commit is contained in:
rxdn 2021-05-28 16:20:16 +01:00
parent faf55caef6
commit ffe7dbb1f9
3 changed files with 11 additions and 13 deletions

View File

@ -16,16 +16,15 @@ import (
"github.com/rxdn/gdl/objects/channel/message" "github.com/rxdn/gdl/objects/channel/message"
"github.com/rxdn/gdl/rest" "github.com/rxdn/gdl/rest"
"github.com/rxdn/gdl/rest/request" "github.com/rxdn/gdl/rest/request"
gdlutils "github.com/rxdn/gdl/utils"
"golang.org/x/sync/errgroup" "golang.org/x/sync/errgroup"
) )
type multiPanelCreateData struct { type multiPanelCreateData struct {
Title string `json:"title"` Title string `json:"title"`
Content string `json:"content"` Content string `json:"content"`
Colour int32 `json:"colour"` Colour int32 `json:"colour"`
ChannelId uint64 `json:"channel_id,string"` ChannelId uint64 `json:"channel_id,string"`
Panels gdlutils.Uint64StringSlice `json:"panels"` Panels []int `json:"panels"`
} }
func MultiPanelCreate(ctx *gin.Context) { func MultiPanelCreate(ctx *gin.Context) {
@ -71,7 +70,7 @@ func MultiPanelCreate(ctx *gin.Context) {
if err := data.addReactions(&botContext, data.ChannelId, messageId, panels); err != nil { if err := data.addReactions(&botContext, data.ChannelId, messageId, panels); err != nil {
var unwrapped request.RestError var unwrapped request.RestError
if errors.As(err, &unwrapped); unwrapped.StatusCode == 403{ if errors.As(err, &unwrapped); unwrapped.StatusCode == 403 {
ctx.JSON(500, utils.ErrorJson(errors.New("I do not have permission to add reactions in the provided channel"))) ctx.JSON(500, utils.ErrorJson(errors.New("I do not have permission to add reactions in the provided channel")))
} else { } else {
ctx.JSON(500, utils.ErrorJson(err)) ctx.JSON(500, utils.ErrorJson(err))
@ -111,7 +110,7 @@ func MultiPanelCreate(ctx *gin.Context) {
ctx.JSON(200, gin.H{ ctx.JSON(200, gin.H{
"success": true, "success": true,
"data": multiPanel, "data": multiPanel,
}) })
} }
@ -184,7 +183,7 @@ func (d *multiPanelCreateData) validatePanels(guildId uint64) (panels []database
var valid bool var valid bool
// find panel struct // find panel struct
for _, panel := range existingPanels { for _, panel := range existingPanels {
if panel.MessageId == panelId { if panel.PanelId == panelId {
// check there isn't a panel with the same reaction emote // check there isn't a panel with the same reaction emote
for _, previous := range panels { for _, previous := range panels {
if previous.ReactionEmote == panel.ReactionEmote { if previous.ReactionEmote == panel.ReactionEmote {
@ -226,7 +225,6 @@ func (d *multiPanelCreateData) sendEmbed(ctx *botcontext.BotContext, isPremium b
return return
} }
func (d *multiPanelCreateData) addReactions(ctx *botcontext.BotContext, channelId, messageId uint64, panels []database.Panel) (err error) { func (d *multiPanelCreateData) addReactions(ctx *botcontext.BotContext, channelId, messageId uint64, panels []database.Panel) (err error) {
for _, panel := range panels { for _, panel := range panels {
if err = rest.CreateReaction(ctx.Token, ctx.RateLimiter, channelId, messageId, panel.ReactionEmote); err != nil { if err = rest.CreateReaction(ctx.Token, ctx.RateLimiter, channelId, messageId, panel.ReactionEmote); err != nil {
@ -235,4 +233,4 @@ func (d *multiPanelCreateData) addReactions(ctx *botcontext.BotContext, channelI
} }
return return
} }

View File

@ -125,7 +125,7 @@
'content': getValue('multi-edit-content'), 'content': getValue('multi-edit-content'),
'colour': parseInt(`0x${getValue('multi-edit-colour').slice(1)}`), 'colour': parseInt(`0x${getValue('multi-edit-colour').slice(1)}`),
'channel_id': channelContainer.options[channelContainer.selectedIndex].value, 'channel_id': channelContainer.options[channelContainer.selectedIndex].value,
'panels': $('#multi-edit-panels').val() 'panels': $('#multi-edit-panels').val().map((id) => parseInt(id))
}; };
$('#multieditmodal').modal('hide'); $('#multieditmodal').modal('hide');

View File

@ -317,7 +317,7 @@
'content': getValue('multi-content'), 'content': getValue('multi-content'),
'colour': parseInt(`0x${getValue('multi-colour').slice(1)}`), 'colour': parseInt(`0x${getValue('multi-colour').slice(1)}`),
'channel_id': channelContainer.options[channelContainer.selectedIndex].value, 'channel_id': channelContainer.options[channelContainer.selectedIndex].value,
'panels': $('#multi-panels').val() 'panels': $('#multi-panels').val().map((id) => parseInt(id))
}; };
const res = await axios.post('/api/{{.guildId}}/multipanels', data); const res = await axios.post('/api/{{.guildId}}/multipanels', data);