From 028862862967bf8797dfb72448b980c6f766e8a0 Mon Sep 17 00:00:00 2001 From: Dot-Rar Date: Sun, 14 Jun 2020 20:23:58 +0100 Subject: [PATCH] welcome message per panel --- app/http/endpoints/api/panelcreate.go | 17 ++++++++-- app/http/endpoints/api/panellist.go | 32 +++++++++--------- go.mod | 2 +- public/templates/views/panels.tmpl | 46 +++++++++++++++++--------- public/templates/views/settings.tmpl | 2 +- public/templates/views/whitelabel.tmpl | 10 ++++-- 6 files changed, 73 insertions(+), 36 deletions(-) diff --git a/app/http/endpoints/api/panelcreate.go b/app/http/endpoints/api/panelcreate.go index bfc3820..a8072c3 100644 --- a/app/http/endpoints/api/panelcreate.go +++ b/app/http/endpoints/api/panelcreate.go @@ -25,7 +25,7 @@ func CreatePanel(ctx *gin.Context) { if err != nil { ctx.AbortWithStatusJSON(500, gin.H{ "success": false, - "error": err.Error(), + "error": err.Error(), }) return } @@ -114,6 +114,7 @@ func CreatePanel(ctx *gin.Context) { Colour: int32(data.Colour), TargetCategory: data.CategoryId, ReactionEmote: emoji, + WelcomeMessage: data.WelcomeMessage, } if err = dbclient.Client.Panel.Create(panel); err != nil { @@ -125,7 +126,7 @@ func CreatePanel(ctx *gin.Context) { } ctx.JSON(200, gin.H{ - "success": true, + "success": true, "message_id": strconv.FormatUint(msgId, 10), }) } @@ -174,6 +175,14 @@ func (p *panel) doValidations(ctx *gin.Context, guildId uint64) bool { return false } + if !p.verifyWelcomeMessage() { + ctx.AbortWithStatusJSON(400, gin.H{ + "success": false, + "error": "Welcome message must be null or between 1 - 1024 characters", + }) + return false + } + return true } @@ -216,6 +225,10 @@ func (p *panel) verifyCategory(channels []channel.Channel) bool { return valid } +func (p *panel) verifyWelcomeMessage() bool { + return p.WelcomeMessage == nil || (len(*p.WelcomeMessage) > 0 && len(*p.WelcomeMessage) < 1025) +} + func (p *panel) sendEmbed(ctx *botcontext.BotContext, isPremium bool) (messageId uint64, err error) { e := embed.NewEmbed(). SetTitle(p.Title). diff --git a/app/http/endpoints/api/panellist.go b/app/http/endpoints/api/panellist.go index e3cd50f..337838e 100644 --- a/app/http/endpoints/api/panellist.go +++ b/app/http/endpoints/api/panellist.go @@ -6,13 +6,14 @@ import ( ) type panel struct { - ChannelId uint64 `json:"channel_id,string"` - MessageId uint64 `json:"message_id,string"` - Title string `json:"title"` - Content string `json:"content"` - Colour uint32 `json:"colour"` - CategoryId uint64 `json:"category_id,string"` - Emote string `json:"emote"` + ChannelId uint64 `json:"channel_id,string"` + MessageId uint64 `json:"message_id,string"` + Title string `json:"title"` + Content string `json:"content"` + Colour uint32 `json:"colour"` + CategoryId uint64 `json:"category_id,string"` + Emote string `json:"emote"` + WelcomeMessage *string `json:"welcome_message"` } func ListPanels(ctx *gin.Context) { @@ -22,7 +23,7 @@ func ListPanels(ctx *gin.Context) { if err != nil { ctx.AbortWithStatusJSON(500, gin.H{ "success": false, - "error": err.Error(), + "error": err.Error(), }) return } @@ -31,13 +32,14 @@ func ListPanels(ctx *gin.Context) { for i, p := range panels { wrapped[i] = panel{ - ChannelId: p.ChannelId, - MessageId: p.MessageId, - Title: p.Title, - Content: p.Content, - Colour: uint32(p.Colour), - CategoryId: p.TargetCategory, - Emote: p.ReactionEmote, + ChannelId: p.ChannelId, + MessageId: p.MessageId, + Title: p.Title, + Content: p.Content, + Colour: uint32(p.Colour), + CategoryId: p.TargetCategory, + Emote: p.ReactionEmote, + WelcomeMessage: p.WelcomeMessage, } } diff --git a/go.mod b/go.mod index d3051d5..6a38887 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-20200425115930-0ca198cc8306 github.com/TicketsBot/common v0.0.0-20200529141045-7426ad13f1a4 - github.com/TicketsBot/database v0.0.0-20200613162408-5b3847cebd07 + github.com/TicketsBot/database v0.0.0-20200614182426-d117a0e3f769 github.com/apex/log v1.1.2 github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff // indirect github.com/dgrijalva/jwt-go v3.2.0+incompatible diff --git a/public/templates/views/panels.tmpl b/public/templates/views/panels.tmpl index 60e9400..f6d7066 100644 --- a/public/templates/views/panels.tmpl +++ b/public/templates/views/panels.tmpl @@ -85,9 +85,30 @@ +
+
+
+ +
+
+
+ +
+
+
+
+ + +
+
+
+
+
-
+
@@ -133,26 +154,21 @@ } async function createPanel() { + const title = document.getElementById('title').value; + const content = document.getElementById('content').value; + const emote = document.getElementById('reaction').value.replace(':', ''); + const welcomeMessage = document.getElementById('welcome_message').value; + const data = { - title: document.getElementById('title').value, - content: document.getElementById('content').value, - emote: document.getElementById('reaction').value.replace(':', ''), + title: title === '' ? 'Open a ticket!' : title, + content: content === '' ? 'By reacting to this ticket, a message will be opened for you.' : content, + emote: emote === '' ? 'envelope_with_arrow' : emote, colour: parseInt(`0x${document.getElementById('colour').value.slice(1)}`), channel_id: document.getElementById('channel-container').options[document.getElementById('channel-container').selectedIndex].value, category_id: document.getElementById('category-container').options[document.getElementById('category-container').selectedIndex].value, + welcome_message: welcomeMessage === '' ? null : welcomeMessage }; - // fill defaults - if (data.title === '') { - data.title = 'Open a ticket!'; - } - if (data.content === '') { - data.content = 'By reacting to this ticket, a ticket will be opened for you.'; - } - if (data.emote === '') { - data.emote = 'envelope_with_arrow'; - } - const res = await axios.put('/api/{{.guildId}}/panels', data); if (res.status === 200 && res.data.success) { data.message_id = res.data.message_id; diff --git a/public/templates/views/settings.tmpl b/public/templates/views/settings.tmpl index f0e72ac..c1dd1f4 100644 --- a/public/templates/views/settings.tmpl +++ b/public/templates/views/settings.tmpl @@ -35,7 +35,7 @@
-
+
diff --git a/public/templates/views/whitelabel.tmpl b/public/templates/views/whitelabel.tmpl index 2b64be4..0bd0330 100644 --- a/public/templates/views/whitelabel.tmpl +++ b/public/templates/views/whitelabel.tmpl @@ -112,6 +112,7 @@
+
@@ -121,7 +122,8 @@ - + + @@ -223,8 +225,12 @@ // append errors for (error of res.data.errors) { + const message = error.Message; + const time = new Date(error.Time); + const tr = document.createElement('tr'); - appendTd(tr, error); + appendTd(tr, message); + appendTd(tr, time.toDateString()); document.getElementById('error_body').appendChild(tr); } }
ErrorErrorDate