From 707744de7439d563f8d013d417476a84d8a97d97 Mon Sep 17 00:00:00 2001 From: rxdn <29165304+rxdn@users.noreply.github.com> Date: Mon, 17 Apr 2023 19:42:12 +0100 Subject: [PATCH] Validate welcome message content --- app/http/endpoints/api/panel/panelcreate.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/http/endpoints/api/panel/panelcreate.go b/app/http/endpoints/api/panel/panelcreate.go index bf97317..81803c0 100644 --- a/app/http/endpoints/api/panel/panelcreate.go +++ b/app/http/endpoints/api/panel/panelcreate.go @@ -297,6 +297,11 @@ func (p *panelBody) doValidations(ctx *gin.Context, guildId uint64) bool { return false } + if !p.validateWelcomeMessage() { + ctx.JSON(400, utils.ErrorStr("The welcome message you provided has no content")) + return false + } + if !p.verifyButtonLabel() { ctx.JSON(400, utils.ErrorStr("Button labels cannot be longer than 80 characters")) return false @@ -520,6 +525,14 @@ func (p *panelBody) verifyNamingScheme() bool { return true } +func (p *panelBody) validateWelcomeMessage() bool { + return p.WelcomeMessage == nil || !(p.WelcomeMessage.Title == nil && + p.WelcomeMessage.Description == nil && + len(p.WelcomeMessage.Fields) == 0 && + p.WelcomeMessage.ImageUrl == nil && + p.WelcomeMessage.ThumbnailUrl == nil) +} + func getRoleHashSet(guildId uint64) (*collections.Set[uint64], error) { ctx, err := botcontext.ContextForGuild(guildId) if err != nil {