Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions app/http/endpoints/api/channels.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func ChannelsHandler(ctx *gin.Context) {
if ctx.Query("refresh") == "true" {
hasToken, err := redis.Client.TakeChannelRefreshToken(ctx, guildId)
if err != nil {
ctx.JSON(500, utils.ErrorStr("Failed to take channel refresh token for guild %d. Please try again."))
ctx.JSON(500, utils.ErrorStr("Failed to take channel refresh token for guild %d. Please try again.", guildId))
return
}

Expand All @@ -37,7 +37,7 @@ func ChannelsHandler(ctx *gin.Context) {
}

if err := cache.Instance.StoreChannels(ctx, channels); err != nil {
ctx.JSON(500, utils.ErrorStr("Failed to store channels in cache for guild %d. Please try again."))
ctx.JSON(500, utils.ErrorStr("Failed to store channels in cache for guild %d. Please try again.", guildId))
return
}
} else {
Expand All @@ -59,17 +59,17 @@ func ChannelsHandler(ctx *gin.Context) {
filtered := make([]channel.Channel, 0, len(channels))
for _, ch := range channels {
// Filter out threads
if ch.Type == channel.ChannelTypeGuildNewsThread ||
ch.Type == channel.ChannelTypeGuildPrivateThread ||
ch.Type == channel.ChannelTypeGuildPublicThread {
if ch.Type == channel.ChannelTypeAnnouncementThread ||
ch.Type == channel.ChannelTypePrivateThread ||
ch.Type == channel.ChannelTypePublicThread {
continue
}

filtered = append(filtered, ch)
}

sort.Slice(filtered, func(i, j int) bool {
return filtered[i].Position < filtered[j].Position
return *filtered[i].Position < *filtered[j].Position
})

ctx.JSON(200, filtered)
Expand Down
17 changes: 7 additions & 10 deletions app/http/endpoints/api/forms/updateinputs.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func UpdateInputs(c *gin.Context) {
}

formatted := "Your input contained the following errors:\n" + utils.FormatValidationErrors(validationErrors)
c.JSON(400, utils.ErrorStr(formatted))
c.JSON(400, utils.ErrorStr("%s", formatted))
return
}

Expand Down Expand Up @@ -270,21 +270,22 @@ func validateInputOptions(input inputCreateBody, optionTypes map[int]string) err
}

// Radio Group (type 21) requires 2-10 options, Checkbox Group (type 22) requires 1-10 options
if input.Type == 21 {
switch input.Type {
case 21:
if len(input.Options) < 2 {
return fmt.Errorf("Radio group inputs must have at least 2 options")
}
if len(input.Options) > 10 {
return fmt.Errorf("Radio group inputs must have at most 10 options")
}
} else if input.Type == 22 {
case 22:
if len(input.Options) == 0 {
return fmt.Errorf("%s inputs must have at least one option", typeName)
}
if len(input.Options) > 10 {
return fmt.Errorf("Checkbox group inputs must have at most 10 options")
}
} else {
default:
if len(input.Options) == 0 {
return fmt.Errorf("%s inputs must have at least one option", typeName)
}
Expand Down Expand Up @@ -321,9 +322,7 @@ func saveInputs(ctx context.Context, formId int, data updateInputsBody, existing
// Handle select types (3, 5-8, 22)
if input.Type == 3 || (input.Type >= 5 && input.Type <= 8) || input.Type == 22 {
// Enforce min_length constraints (0-25)
if minLength < 0 {
minLength = 0
} else if minLength > 25 {
if minLength > 25 {
minLength = 25
}

Expand Down Expand Up @@ -426,9 +425,7 @@ func saveInputs(ctx context.Context, formId int, data updateInputsBody, existing
// Handle select types (3, 5-8, 22)
if input.Type == 3 || (input.Type >= 5 && input.Type <= 8) || input.Type == 22 {
// Enforce min_length constraints (0-25)
if minLength < 0 {
minLength = 0
} else if minLength > 25 {
if minLength > 25 {
minLength = 25
}

Expand Down
4 changes: 2 additions & 2 deletions app/http/endpoints/api/guild.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ func GuildHandler(ctx *gin.Context) {

guild, err := botContext.GetGuild(ctx, guildId)
if err != nil {
ctx.JSON(500, utils.ErrorStr("Failed to fetch guild information from Discord for guild %d. Please try again."))
ctx.JSON(500, utils.ErrorStr("Failed to fetch guild information from Discord for guild %d. Please try again.", guildId))
return
}

ctx.JSON(200, gin.H{
"id": guild.Id,
"name": guild.Name,
"icon": guild.Icon,
"icon": guild.IconUrl(),
})
}
4 changes: 2 additions & 2 deletions app/http/endpoints/api/integrations/createintegration.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func CreateIntegrationHandler(ctx *gin.Context) {
}

formatted := "Your input contained the following errors:\n" + utils.FormatValidationErrors(validationErrors)
ctx.JSON(400, utils.ErrorStr(formatted))
ctx.JSON(400, utils.ErrorStr("%s", formatted))
return
}

Expand Down Expand Up @@ -159,5 +159,5 @@ func isSameValidationUrlHost(webhookUrl, validationUrl string) (bool, error) {
return false, errors.New("invalid webhook or validation URL")
}

return strings.ToLower(utils.SecondLevelDomain(webhookStripped)) == strings.ToLower(utils.SecondLevelDomain(validationStripped)), nil
return strings.EqualFold(utils.SecondLevelDomain(webhookStripped), utils.SecondLevelDomain(validationStripped)), nil
}
5 changes: 0 additions & 5 deletions app/http/endpoints/api/integrations/listintegrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,5 @@ func ListIntegrationsHandler(ctx *gin.Context) {
}
}

// Don't serve null
if integrations == nil {
integrations = make([]integrationWithMetadata, 0)
}

ctx.JSON(200, integrations)
}
2 changes: 1 addition & 1 deletion app/http/endpoints/api/integrations/updateintegration.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func UpdateIntegrationHandler(ctx *gin.Context) {
}

formatted = strings.TrimSuffix(formatted, "\n")
ctx.JSON(400, utils.ErrorStr(formatted))
ctx.JSON(400, utils.ErrorStr("%s", formatted))
return
}

Expand Down
6 changes: 3 additions & 3 deletions app/http/endpoints/api/panel/multipanelcreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func MultiPanelCreate(c *gin.Context) {
}

formatted := "Your input contained the following errors:\n" + utils.FormatValidationErrors(validationErrors)
c.JSON(400, utils.ErrorStr(formatted))
c.JSON(400, utils.ErrorStr("%s", formatted))
return
}

Expand All @@ -99,7 +99,7 @@ func MultiPanelCreate(c *gin.Context) {
effectiveLabel := getEffectiveLabelForValidation(panel.ButtonLabel, panelConfig.CustomLabel)

if effectiveLabel == "" {
c.JSON(400, utils.ErrorStr(fmt.Sprintf("Panel '%s' must have a label when using dropdown mode. Please add a custom label or ensure the panel has a button label.", panel.Title)))
c.JSON(400, utils.ErrorStr("Panel '%s' must have a label when using dropdown mode. Please add a custom label or ensure the panel has a button label.", panel.Title))
return
}
}
Expand Down Expand Up @@ -232,7 +232,7 @@ func (d *multiPanelCreateData) validateChannel(guildId uint64) func() error {

var valid bool
for _, ch := range channels {
if ch.Id == d.ChannelId && (ch.Type == channel.ChannelTypeGuildText || ch.Type == channel.ChannelTypeGuildNews) {
if ch.Id == d.ChannelId && (ch.Type == channel.ChannelTypeGuildText || ch.Type == channel.ChannelTypeGuildAnnouncement) {
valid = true
break
}
Expand Down
16 changes: 8 additions & 8 deletions app/http/endpoints/api/panel/multipanellist.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ func MultiPanelList(ctx *gin.Context) {
}

type multiPanelResponse struct {
Id int `json:"id"`
MessageId uint64 `json:"message_id,string"`
ChannelId uint64 `json:"channel_id,string"`
GuildId uint64 `json:"guild_id,string"`
SelectMenu bool `json:"select_menu"`
SelectMenuPlaceholder *string `json:"select_menu_placeholder"`
Embed *types.CustomEmbed `json:"embed"`
Panels []panelConfiguration `json:"panels"`
Id int `json:"id"`
MessageId uint64 `json:"message_id,string"`
ChannelId uint64 `json:"channel_id,string"`
GuildId uint64 `json:"guild_id,string"`
SelectMenu bool `json:"select_menu"`
SelectMenuPlaceholder *string `json:"select_menu_placeholder"`
Embed *types.CustomEmbed `json:"embed"`
Panels []panelConfiguration `json:"panels"`
}

guildId := ctx.Keys["guildid"].(uint64)
Expand Down
4 changes: 2 additions & 2 deletions app/http/endpoints/api/panel/multipanelmessagedata.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package api

import (
"context"
"math"
"fmt"
"math"

"github.com/TicketsBot-cloud/dashboard/botcontext"
"github.com/TicketsBot-cloud/dashboard/utils/types"
"github.com/TicketsBot-cloud/dashboard/config"
"github.com/TicketsBot-cloud/dashboard/utils/types"
"github.com/TicketsBot-cloud/database"
"github.com/TicketsBot-cloud/gdl/objects/channel/embed"
"github.com/TicketsBot-cloud/gdl/objects/interaction/component"
Expand Down
5 changes: 2 additions & 3 deletions app/http/endpoints/api/panel/multipanelupdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package api
import (
"context"
"errors"
"fmt"
"net/http"
"strconv"

Expand Down Expand Up @@ -67,7 +66,7 @@ func MultiPanelUpdate(c *gin.Context) {
}

formatted := "Your input contained the following errors:\n" + utils.FormatValidationErrors(validationErrors)
c.JSON(400, utils.ErrorStr(formatted))
c.JSON(400, utils.ErrorStr("%s", formatted))
return
}

Expand Down Expand Up @@ -97,7 +96,7 @@ func MultiPanelUpdate(c *gin.Context) {
}

if effectiveLabel == "" {
c.JSON(400, utils.ErrorStr(fmt.Sprintf("Panel '%s' must have a label when using dropdown mode. Please add a custom label or ensure the panel has a button label.", panel.Title)))
c.JSON(400, utils.ErrorStr("Panel '%s' must have a label when using dropdown mode. Please add a custom label or ensure the panel has a button label.", panel.Title))
return
}
}
Expand Down
17 changes: 8 additions & 9 deletions app/http/endpoints/api/panel/panelcreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func CreatePanel(c *gin.Context) {
if err := ValidatePanelBody(validationContext); err != nil {
var validationError *validation.InvalidInputError
if errors.As(err, &validationError) {
c.JSON(400, utils.ErrorStr(validationError.Error()))
c.JSON(400, utils.ErrorStr("%s", validationError.Error()))
} else {
_ = c.AbortWithError(http.StatusInternalServerError, app.NewError(err, "Panel validation failed unexpectedly"))
}
Expand All @@ -170,7 +170,7 @@ func CreatePanel(c *gin.Context) {
}

formatted := "Your input contained the following errors:\n" + utils.FormatValidationErrors(validationErrors)
c.JSON(400, utils.ErrorStr(formatted))
c.JSON(400, utils.ErrorStr("%s", formatted))
return
}

Expand Down Expand Up @@ -202,7 +202,7 @@ func CreatePanel(c *gin.Context) {
{
emoji := data.getEmoji()
if emoji != nil {
emojiName = &emoji.Name
emojiName = emoji.Name

if emoji.Id.Value != 0 {
emojiId = &emoji.Id.Value
Expand Down Expand Up @@ -265,7 +265,6 @@ func CreatePanel(c *gin.Context) {
HideClaimButton: data.HideClaimButton,
}


createOptions := panelCreateOptions{
TeamIds: data.Teams, // Already validated
AccessControlRules: data.AccessControlList, // Already validated
Expand All @@ -275,21 +274,21 @@ func CreatePanel(c *gin.Context) {
// string is role ID or "user" to mention the ticket opener or "here" to mention @here
validRoles := utils.ToSet(utils.Map(roles, utils.RoleToId))

var roleMentions []uint64
for _, mention := range data.Mentions {
if mention == "user" {
switch mention {
case "user":
createOptions.ShouldMentionUser = true
} else if mention == "here" {
case "here":
createOptions.ShouldMentionHere = true
} else {
default:
roleId, err := strconv.ParseUint(mention, 10, 64)
if err != nil {
c.JSON(400, utils.ErrorStr("Invalid role ID in mentions: %s", mention))
return
}

if validRoles.Contains(roleId) {
createOptions.RoleMentions = append(roleMentions, roleId)
createOptions.RoleMentions = append(createOptions.RoleMentions, roleId)
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions app/http/endpoints/api/panel/paneldelete.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package api

import (
"errors"
"fmt"
"net/http"
"strconv"

Expand Down Expand Up @@ -42,7 +41,7 @@ func DeletePanel(c *gin.Context) {
}

if panel.PanelId == 0 {
c.JSON(404, utils.ErrorStr(fmt.Sprintf("Panel not found: %d", panelId)))
c.JSON(404, utils.ErrorStr("Panel not found: %d", panelId))
return
}

Expand Down
6 changes: 3 additions & 3 deletions app/http/endpoints/api/panel/panelmessagedata.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ func panelIntoMessageData(panel database.Panel, isPremium bool) panelMessageData
if panel.EmojiName != nil { // No emoji = nil
if panel.EmojiId == nil { // Unicode emoji
emote = &emoji.Emoji{
Name: *panel.EmojiName,
Name: panel.EmojiName,
}
} else { // Custom emoji
emote = &emoji.Emoji{
Id: objects.NewNullableSnowflake(*panel.EmojiId),
Name: *panel.EmojiName,
Name: panel.EmojiName,
}
}
}
Expand Down Expand Up @@ -120,7 +120,7 @@ func (p *panelMessageData) edit(c *botcontext.BotContext, messageId uint64) erro
}

data := rest.EditMessageData{
Embeds: []*embed.Embed{e},
Embeds: []*embed.Embed{e},
Components: []component.Component{
component.BuildActionRow(component.BuildButton(component.Button{
Label: p.ButtonLabel,
Expand Down
3 changes: 1 addition & 2 deletions app/http/endpoints/api/panel/panelresend.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package api
import (
"context"
"errors"
"fmt"
"strconv"

"github.com/TicketsBot-cloud/common/premium"
Expand Down Expand Up @@ -42,7 +41,7 @@ func ResendPanel(ctx *gin.Context) {
}

if panel.PanelId == 0 {
ctx.JSON(404, utils.ErrorStr(fmt.Sprintf("Panel not found: %d", panelId)))
ctx.JSON(404, utils.ErrorStr("Panel not found: %d", panelId))
return
}

Expand Down
Loading
Loading