diff --git a/app/http/endpoints/api/panel/multipanelmessagedata.go b/app/http/endpoints/api/panel/multipanelmessagedata.go index 273f747..727ce41 100644 --- a/app/http/endpoints/api/panel/multipanelmessagedata.go +++ b/app/http/endpoints/api/panel/multipanelmessagedata.go @@ -66,7 +66,7 @@ func (d *multiPanelMessageData) send(ctx *botcontext.BotContext, panels []databa } options[i] = component.SelectOption{ - Label: panel.Title, + Label: panel.ButtonLabel, Value: panel.CustomId, Emoji: emote, } @@ -96,7 +96,7 @@ func (d *multiPanelMessageData) send(ctx *botcontext.BotContext, panels []databa } buttons[i] = component.BuildButton(component.Button{ - Label: panel.Title, + Label: panel.ButtonLabel, CustomId: panel.CustomId, Style: component.ButtonStyle(panel.ButtonStyle), Emoji: buttonEmoji, diff --git a/app/http/endpoints/api/panel/panelcreate.go b/app/http/endpoints/api/panel/panelcreate.go index f349f50..3c375fc 100644 --- a/app/http/endpoints/api/panel/panelcreate.go +++ b/app/http/endpoints/api/panel/panelcreate.go @@ -36,6 +36,7 @@ type panelBody struct { ImageUrl *string `json:"image_url,omitempty"` ThumbnailUrl *string `json:"thumbnail_url,omitempty"` ButtonStyle component.ButtonStyle `json:"button_style,string"` + ButtonLabel string `json:"button_label"` FormId *int `json:"form_id"` } @@ -55,6 +56,7 @@ func (p *panelBody) IntoPanelMessageData(customId string, isPremium bool) panelM ThumbnailUrl: p.ThumbnailUrl, Emoji: emoji, ButtonStyle: p.ButtonStyle, + ButtonLabel: p.ButtonLabel, IsPremium: isPremium, } } @@ -100,10 +102,7 @@ func CreatePanel(ctx *gin.Context) { } if len(panels) >= freePanelLimit { - ctx.AbortWithStatusJSON(402, gin.H{ - "success": false, - "error": "You have exceeded your panel quota. Purchase premium to unlock more panels.", - }) + ctx.AbortWithStatusJSON(402, utils.ErrorStr("You have exceeded your panel quota. Purchase premium to unlock more panels.")) return } } @@ -150,6 +149,7 @@ func CreatePanel(ctx *gin.Context) { ImageUrl: data.ImageUrl, ThumbnailUrl: data.ThumbnailUrl, ButtonStyle: int(data.ButtonStyle), + ButtonLabel: data.ButtonLabel, FormId: data.FormId, } @@ -279,6 +279,11 @@ func (p *panelBody) doValidations(ctx *gin.Context, guildId uint64) bool { return false } + if !p.verifyButtonLabel() { + ctx.AbortWithStatusJSON(400, utils.ErrorStr("Button labels cannot be longer than 80 characters")) + return false + } + { valid, err := p.verifyTeams(guildId) if err != nil { @@ -384,6 +389,14 @@ func (p *panelBody) verifyButtonStyle() bool { return p.ButtonStyle >= component.ButtonStylePrimary && p.ButtonStyle <= component.ButtonStyleDanger } +func (p *panelBody) verifyButtonLabel() bool { + if len(p.ButtonLabel) == 0 { + p.ButtonLabel = p.Title // Title already checked for 80 char max + } + + return len(p.ButtonLabel) <= 80 +} + func (p *panelBody) verifyFormId(guildId uint64) (bool, error) { if p.FormId == nil { return true, nil diff --git a/app/http/endpoints/api/panel/panelmessagedata.go b/app/http/endpoints/api/panel/panelmessagedata.go index 7e54e23..c537824 100644 --- a/app/http/endpoints/api/panel/panelmessagedata.go +++ b/app/http/endpoints/api/panel/panelmessagedata.go @@ -16,6 +16,7 @@ type panelMessageData struct { Colour int ImageUrl, ThumbnailUrl, Emoji *string ButtonStyle component.ButtonStyle + ButtonLabel string IsPremium bool } @@ -35,6 +36,7 @@ func panelIntoMessageData(panel database.Panel, isPremium bool) panelMessageData ThumbnailUrl: panel.ThumbnailUrl, Emoji: emoji, ButtonStyle: component.ButtonStyle(panel.ButtonStyle), + ButtonLabel: panel.ButtonLabel, IsPremium: isPremium, } } @@ -68,7 +70,7 @@ func (p *panelMessageData) send(ctx *botcontext.BotContext) (uint64, error) { Embeds: []*embed.Embed{e}, Components: []component.Component{ component.BuildActionRow(component.BuildButton(component.Button{ - Label: p.Title, + Label: p.ButtonLabel, CustomId: p.CustomId, Style: p.ButtonStyle, Emoji: buttonEmoji, diff --git a/app/http/endpoints/api/panel/panelupdate.go b/app/http/endpoints/api/panel/panelupdate.go index 37feee9..569005d 100644 --- a/app/http/endpoints/api/panel/panelupdate.go +++ b/app/http/endpoints/api/panel/panelupdate.go @@ -20,35 +20,32 @@ func UpdatePanel(ctx *gin.Context) { botContext, err := botcontext.ContextForGuild(guildId) if err != nil { - ctx.AbortWithStatusJSON(500, utils.ErrorJson(err)) + ctx.JSON(500, utils.ErrorJson(err)) return } var data panelBody if err := ctx.BindJSON(&data); err != nil { - ctx.AbortWithStatusJSON(400, utils.ErrorJson(err)) + ctx.JSON(400, utils.ErrorJson(err)) return } panelId, err := strconv.Atoi(ctx.Param("panelid")) if err != nil { - ctx.AbortWithStatusJSON(400, utils.ErrorJson(err)) + ctx.JSON(400, utils.ErrorJson(err)) return } // get existing existing, err := dbclient.Client.Panel.GetById(panelId) if err != nil { - ctx.AbortWithStatusJSON(500, utils.ErrorJson(err)) + ctx.JSON(500, utils.ErrorJson(err)) return } // check guild ID matches if existing.GuildId != guildId { - ctx.AbortWithStatusJSON(400, gin.H{ - "success": false, - "error": "Guild ID does not match", - }) + ctx.JSON(400, utils.ErrorStr("Guild ID does not match")) return } @@ -109,7 +106,8 @@ func UpdatePanel(ctx *gin.Context) { existing.ReactionEmote != data.Emote || existing.ImageUrl != data.ImageUrl || existing.ThumbnailUrl != data.ThumbnailUrl || - component.ButtonStyle(existing.ButtonStyle) != data.ButtonStyle + component.ButtonStyle(existing.ButtonStyle) != data.ButtonStyle || + existing.ButtonLabel != data.ButtonLabel emoji, _ := data.getEmoji() // already validated newMessageId := existing.MessageId @@ -123,13 +121,10 @@ func UpdatePanel(ctx *gin.Context) { if err != nil { var unwrapped request.RestError if errors.As(err, &unwrapped) && unwrapped.StatusCode == 403 { - ctx.AbortWithStatusJSON(500, gin.H{ - "success": false, - "error": "I do not have permission to send messages in the specified channel", - }) + ctx.JSON(500, utils.ErrorStr("I do not have permission to send messages in the specified channel")) } else { // TODO: Most appropriate error? - ctx.AbortWithStatusJSON(500, utils.ErrorJson(err)) + ctx.JSON(500, utils.ErrorJson(err)) } return diff --git a/frontend/src/components/manage/PanelCreationForm.svelte b/frontend/src/components/manage/PanelCreationForm.svelte index 3dd80c9..257efae 100644 --- a/frontend/src/components/manage/PanelCreationForm.svelte +++ b/frontend/src/components/manage/PanelCreationForm.svelte @@ -4,7 +4,7 @@