Separate button labels

This commit is contained in:
rxdn 2022-06-16 14:45:23 +01:00
parent 0ba71b9361
commit d54dbe10f5
7 changed files with 39 additions and 27 deletions

View File

@ -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,

View File

@ -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

View File

@ -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,

View File

@ -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

View File

@ -4,7 +4,7 @@
<Input label="Panel Title" placeholder="Open a ticket!" col1=true bind:value={data.title}/>
</div>
<div class="col-2-3">
<Textarea col1=true label="Panel Content" placeholder="By clicking the button, a ticket will be opened for you."
<Textarea col1=true label="Panel Content" placeholder="By clicking the button, a ticket will be opened for you."
bind:value={data.content}/>
</div>
</div>
@ -15,14 +15,16 @@
<EmojiInput label="Button Emoji" col4=true bind:value={data.emote}/>
</div>
<div class="row">
<Dropdown col4=true label="Button Style" bind:value={data.button_style}>
<Dropdown col3=true label="Button Style" bind:value={data.button_style}>
<option value="1">Blue</option>
<option value="2">Grey</option>
<option value="3">Green</option>
<option value="4">Red</option>
</Dropdown>
<Dropdown col4=true label="Form" bind:value={data.form_id}>
<Input col3={true} label="Button Text" placeholder="Open a ticket!" bind:value={data.button_label} />
<Dropdown col3=true label="Form" bind:value={data.form_id}>
<option value=null>None</option>
{#each forms as form}
<option value={form.form_id}>{form.title}</option>

2
go.mod
View File

@ -6,7 +6,7 @@ require (
github.com/BurntSushi/toml v0.3.1
github.com/TicketsBot/archiverclient v0.0.0-20220326163414-558fd52746dc
github.com/TicketsBot/common v0.0.0-20220609182514-8d43f86e8253
github.com/TicketsBot/database v0.0.0-20220615120431-32ea29720357
github.com/TicketsBot/database v0.0.0-20220616133502-42690a5719dd
github.com/TicketsBot/logarchiver v0.0.0-20220326162808-cdf0310f5e1c
github.com/TicketsBot/worker v0.0.0-20220614162334-f81bf3f39aa5
github.com/apex/log v1.1.2

4
go.sum
View File

@ -5,8 +5,8 @@ github.com/TicketsBot/archiverclient v0.0.0-20220326163414-558fd52746dc h1:n15W8
github.com/TicketsBot/archiverclient v0.0.0-20220326163414-558fd52746dc/go.mod h1:2KcfHS0JnSsgcxZBs3NyWMXNQzEo67mBSGOyzHPWOCc=
github.com/TicketsBot/common v0.0.0-20220609182514-8d43f86e8253 h1:HbL0OBZHmU0TbB/lAQ9RY0TqxhAKRO8JNh2XUe0NH8c=
github.com/TicketsBot/common v0.0.0-20220609182514-8d43f86e8253/go.mod h1:ZAoYcDD7SQLTsZT7dbo/X0J256+pogVRAReunCGng+U=
github.com/TicketsBot/database v0.0.0-20220615120431-32ea29720357 h1:gTpRYmI/Oq87tHHmeIpT5UYOS5PuLxj2teP5Jb7RvdY=
github.com/TicketsBot/database v0.0.0-20220615120431-32ea29720357/go.mod h1:F57cywrZsnper1cy56Bx0c/HEsxQBLHz3Pl98WXblWw=
github.com/TicketsBot/database v0.0.0-20220616133502-42690a5719dd h1:tcPXP5Jd/K3/lavUyZYZDCFRNrPCtbgh6JlVTi9nIzQ=
github.com/TicketsBot/database v0.0.0-20220616133502-42690a5719dd/go.mod h1:F57cywrZsnper1cy56Bx0c/HEsxQBLHz3Pl98WXblWw=
github.com/TicketsBot/logarchiver v0.0.0-20220326162808-cdf0310f5e1c h1:OqGjFH6mbE6gd+NqI2ARJdtH3UUvhiAkD0r0fhGJK2s=
github.com/TicketsBot/logarchiver v0.0.0-20220326162808-cdf0310f5e1c/go.mod h1:jgi2OXQKsd5nUnTIRkwvPmeuD/i7OhN68LKMssuQY1c=
github.com/TicketsBot/ttlcache v1.6.1-0.20200405150101-acc18e37b261 h1:NHD5GB6cjlkpZFjC76Yli2S63/J2nhr8MuE6KlYJpQM=