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
2 changes: 1 addition & 1 deletion backend/app/http/endpoints/api/admin/gallery/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type adminListingResponse struct {
SnapshotData stdjson.RawMessage `json:"snapshot_data,omitempty"`
Title string `json:"title"`
Content string `json:"content"`
Colour int32 `json:"colour"`
Colour *int32 `json:"colour"`
ImageUrl *string `json:"image_url"`
ThumbnailUrl *string `json:"thumbnail_url"`
ButtonStyle *int16 `json:"button_style"`
Expand Down
2 changes: 1 addition & 1 deletion backend/app/http/endpoints/api/gallery/galleryimport.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func ImportHandler(ctx *gin.Context) {
e := embed.NewEmbed().
SetTitle(panel.Title).
SetDescription(panel.Content).
SetColor(int(panel.Colour))
SetColorPtr(utils.ConvertPtr[int](panel.Colour))

if panel.ImageUrl != nil {
e.SetImage(*panel.ImageUrl)
Expand Down
2 changes: 1 addition & 1 deletion backend/app/http/endpoints/api/gallery/submit_form.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func SubmitFormHandler(ctx *gin.Context) {
// Panel fields left at zero values for non-panel listings
Title: "",
Content: "",
Colour: 0,
Colour: nil,
ButtonLabel: "",
}

Expand Down
2 changes: 1 addition & 1 deletion backend/app/http/endpoints/api/gallery/submit_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func SubmitTagHandler(ctx *gin.Context) {
// Panel fields left at zero values for non-panel listings
Title: "",
Content: "",
Colour: 0,
Colour: nil,
ButtonLabel: "",
}

Expand Down
4 changes: 2 additions & 2 deletions backend/app/http/endpoints/api/gallery/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ type galleryListingPublicResponse struct {
SnapshotData stdjson.RawMessage `json:"snapshot_data,omitempty"`
Title string `json:"title"`
Content string `json:"content"`
Colour int32 `json:"colour"`
Colour *int32 `json:"colour"`
ImageUrl *string `json:"image_url,omitempty"`
ThumbnailUrl *string `json:"thumbnail_url,omitempty"`
ButtonStyle *int16 `json:"button_style"`
Expand Down Expand Up @@ -99,7 +99,7 @@ type galleryListingResponse struct {
SnapshotData stdjson.RawMessage `json:"snapshot_data,omitempty"`
Title string `json:"title"`
Content string `json:"content"`
Colour int32 `json:"colour"`
Colour *int32 `json:"colour"`
ImageUrl *string `json:"image_url,omitempty"`
ThumbnailUrl *string `json:"thumbnail_url,omitempty"`
ButtonStyle *int16 `json:"button_style"`
Expand Down
2 changes: 1 addition & 1 deletion backend/app/http/endpoints/api/panel/multipanelget.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func MultiPanelGet(ctx *gin.Context) {
if multiPanel.Embed != nil && multiPanel.Embed.CustomEmbed != nil {
transformedEmbed = types.NewCustomEmbed(multiPanel.Embed.CustomEmbed, multiPanel.Embed.Fields)
} else {
transformedEmbed = &types.CustomEmbed{Colour: 0x5865f2}
transformedEmbed = &types.CustomEmbed{Colour: utils.Ptr(types.Colour(0x5865f2))}
}

panels, err := dbclient.Client.MultiPanelTargets.GetPanels(ctx, multiPanelId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ func multiPanelDiscordSubPanelError(action, detail string) string {
}

func multiPanelIntoMessageData(panel database.MultiPanel, footer footerPolicy) multiPanelMessageData {
custom := &types.CustomEmbed{Colour: 0x5865f2}
blurple := types.Colour(0x5865f2)
custom := &types.CustomEmbed{Colour: &blurple}
if panel.Embed != nil && panel.Embed.CustomEmbed != nil {
custom = types.NewCustomEmbed(panel.Embed.CustomEmbed, panel.Embed.Fields)
}
Expand Down
6 changes: 3 additions & 3 deletions backend/app/http/endpoints/api/panel/panelcreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type panelBody struct {
MessageId uint64 `json:"message_id,string"`
Title string `json:"title"`
Content string `json:"content"`
Colour uint32 `json:"colour"`
Colour *uint32 `json:"colour" validate:"omitempty,max=16777215"`
CategoryId uint64 `json:"category_id,string"`
Emoji types.Emoji `json:"emote"`
WelcomeMessage *types.CustomEmbed `json:"welcome_message" validate:"omitempty"`
Expand Down Expand Up @@ -86,7 +86,7 @@ func (p *panelBody) IntoPanelMessageData(customId string, showBranding bool) pan
Title: p.Title,
Content: p.Content,
CustomId: customId,
Colour: int(p.Colour),
Colour: utils.ConvertPtr[int](p.Colour),
ImageUrl: p.ImageUrl,
ThumbnailUrl: p.ThumbnailUrl,
Emoji: p.getEmoji(),
Expand Down Expand Up @@ -290,7 +290,7 @@ func CreatePanel(c *gin.Context) {
GuildId: guildId,
Title: data.Title,
Content: data.Content,
Colour: int32(data.Colour),
Colour: utils.ConvertPtr[int32](data.Colour),
TargetCategory: data.CategoryId,
EmojiId: emojiId,
EmojiName: emojiName,
Expand Down
2 changes: 1 addition & 1 deletion backend/app/http/endpoints/api/panel/panellist.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func ListPanels(c *gin.Context) {
PanelId int `json:"panel_id"`
ChannelId uint64 `json:"channel_id,string"`
Title string `json:"title"`
Colour int32 `json:"colour"`
Colour *int32 `json:"colour"`
ButtonLabel string `json:"button_label"`
ButtonStyle int `json:"button_style,string"`
EmojiName *string `json:"emoji_name,omitempty"`
Expand Down
9 changes: 5 additions & 4 deletions backend/app/http/endpoints/api/panel/panelmessagedata.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ import (
"github.com/ticketsbot-cloud/dashboard/backend/app"
"github.com/ticketsbot-cloud/dashboard/backend/botcontext"
"github.com/ticketsbot-cloud/dashboard/backend/config"
"github.com/ticketsbot-cloud/dashboard/backend/utils"
)

type panelMessageData struct {
ChannelId uint64

Title, Content, CustomId string
Colour int
Colour *int
ImageUrl, ThumbnailUrl *string
Emoji *emoji.Emoji
ButtonStyle component.ButtonStyle
Expand Down Expand Up @@ -47,7 +48,7 @@ func panelIntoMessageData(panel database.Panel, showBranding bool) panelMessageD
Title: panel.Title,
Content: panel.Content,
CustomId: panel.CustomId,
Colour: int(panel.Colour),
Colour: utils.ConvertPtr[int](panel.Colour),
ImageUrl: panel.ImageUrl,
ThumbnailUrl: panel.ThumbnailUrl,
Emoji: emote,
Expand All @@ -62,7 +63,7 @@ func (p *panelMessageData) send(c *botcontext.BotContext) (uint64, error) {
e := embed.NewEmbed().
SetTitle(p.Title).
SetDescription(p.Content).
SetColor(p.Colour)
SetColorPtr(p.Colour)

if p.ImageUrl != nil {
e.SetImage(*p.ImageUrl)
Expand Down Expand Up @@ -105,7 +106,7 @@ func (p *panelMessageData) edit(c *botcontext.BotContext, messageId uint64) erro
e := embed.NewEmbed().
SetTitle(p.Title).
SetDescription(p.Content).
SetColor(p.Colour)
SetColorPtr(p.Colour)

if p.ImageUrl != nil {
e.SetImage(*p.ImageUrl)
Expand Down
2 changes: 1 addition & 1 deletion backend/app/http/endpoints/api/panel/panelupdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ func UpdatePanel(c *gin.Context) {
GuildId: guildId,
Title: data.Title,
Content: data.Content,
Colour: int32(data.Colour),
Colour: utils.ConvertPtr[int32](data.Colour),
TargetCategory: data.CategoryId,
EmojiName: emojiName,
EmojiId: emojiId,
Expand Down
29 changes: 21 additions & 8 deletions backend/app/http/endpoints/api/panel/supporthours.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type supportHoursResponse struct {
OutOfHoursBehaviour string `json:"out_of_hours_behaviour"`
OutOfHoursTitle string `json:"out_of_hours_title"`
OutOfHoursMessage string `json:"out_of_hours_message"`
OutOfHoursColour int `json:"out_of_hours_colour"`
OutOfHoursColour *int `json:"out_of_hours_colour"`
}

// supportHoursAuditData is used for audit log old/new data to include both hours and settings
Expand Down Expand Up @@ -98,14 +98,10 @@ func GetSupportHours(c *gin.Context) {
outOfHoursBehaviour := string(database.OutOfHoursBehaviourBlockCreation)
var outOfHoursTitle string
var outOfHoursMessage string
outOfHoursColour := 0xFC3F35
if settingsExist {
outOfHoursBehaviour = string(settings.OutOfHoursBehaviour)
outOfHoursTitle = settings.OutOfHoursTitle
outOfHoursMessage = settings.OutOfHoursMessage
if settings.OutOfHoursColour != 0 {
outOfHoursColour = settings.OutOfHoursColour
}
}

response := supportHoursResponse{
Expand All @@ -114,12 +110,20 @@ func GetSupportHours(c *gin.Context) {
OutOfHoursBehaviour: outOfHoursBehaviour,
OutOfHoursTitle: outOfHoursTitle,
OutOfHoursMessage: outOfHoursMessage,
OutOfHoursColour: outOfHoursColour,
OutOfHoursColour: outOfHoursColourResponse(settings, settingsExist),
}

c.JSON(http.StatusOK, response)
}

func outOfHoursColourResponse(settings database.PanelSupportHoursSettings, settingsExist bool) *int {
if !settingsExist {
return utils.Ptr(0xFC3F35)
}

return settings.OutOfHoursColour
}

// supportHoursPayload represents individual hour configuration in requests
type supportHoursPayload struct {
DayOfWeek int `json:"day_of_week"`
Expand All @@ -135,7 +139,11 @@ type supportHoursRequestBody struct {
OutOfHoursBehaviour string `json:"out_of_hours_behaviour"`
OutOfHoursTitle string `json:"out_of_hours_title"`
OutOfHoursMessage string `json:"out_of_hours_message"`
OutOfHoursColour int `json:"out_of_hours_colour"`
OutOfHoursColour *int `json:"out_of_hours_colour"`
}

func isValidOutOfHoursColour(colour *int) bool {
return colour == nil || (*colour >= 0 && *colour <= 0xFFFFFF)
}

func SetSupportHours(c *gin.Context) {
Expand Down Expand Up @@ -223,6 +231,11 @@ func SetSupportHours(c *gin.Context) {
return
}

if !isValidOutOfHoursColour(requestBody.OutOfHoursColour) {
c.JSON(http.StatusBadRequest, utils.ErrorStr("Invalid out of hours colour"))
return
}

// Fetch existing data for audit log
oldHours, err := dbclient.Client.PanelSupportHours.GetByPanelId(c, panelId)
if err != nil {
Expand Down Expand Up @@ -319,7 +332,7 @@ func SetSupportHours(c *gin.Context) {
if string(oldSettings.OutOfHoursBehaviour) != behaviour ||
oldSettings.OutOfHoursTitle != outOfHoursTitle ||
oldSettings.OutOfHoursMessage != outOfHoursMessage ||
oldSettings.OutOfHoursColour != requestBody.OutOfHoursColour {
!utils.PtrEqual(oldSettings.OutOfHoursColour, requestBody.OutOfHoursColour) {
hasChanges = true
}

Expand Down
12 changes: 8 additions & 4 deletions backend/app/http/endpoints/api/settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type (
Language *string `json:"language"`
}

ColourMap map[customisation.Colour]utils.HexColour
ColourMap map[customisation.Colour]*utils.HexColour
)

func loadSettings(ctx context.Context, guildId uint64) (Settings, error) {
Expand Down Expand Up @@ -101,20 +101,24 @@ func getColourMap(guildId uint64) (ColourMap, error) {
return nil, err
}

return newColourMap(raw), nil
}

func newColourMap(raw map[int16]*int) ColourMap {
colours := make(ColourMap)
for id, hex := range raw {
if !utils.Exists(activeColours, customisation.Colour(id)) {
continue
}

colours[customisation.Colour(id)] = utils.HexColour(hex)
colours[customisation.Colour(id)] = utils.ConvertPtr[utils.HexColour](hex)
}

for _, id := range activeColours {
if _, ok := colours[id]; !ok {
colours[id] = utils.HexColour(customisation.DefaultColours[id])
colours[id] = utils.Ptr(utils.HexColour(customisation.DefaultColours[id]))
}
}

return colours, nil
return colours
}
6 changes: 3 additions & 3 deletions backend/app/http/endpoints/api/settings/updatesettings.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (s *Settings) Validate(ctx context.Context, guildId uint64, premiumTier pre

for _, colourCode := range activeColours {
if _, ok := s.Colours[colourCode]; !ok {
s.Colours[colourCode] = utils.HexColour(customisation.DefaultColours[colourCode])
s.Colours[colourCode] = utils.Ptr(utils.HexColour(customisation.DefaultColours[colourCode]))
}
}

Expand Down Expand Up @@ -171,9 +171,9 @@ func (s *Settings) updateLanguage(guildId uint64) error {

func (s *Settings) updateColours(guildId uint64) error {
// Convert ColourMap to primitives
converted := make(map[int16]int)
converted := make(map[int16]*int)
for colour, hex := range s.Colours {
converted[int16(colour)] = int(hex)
converted[int16(colour)] = utils.ConvertPtr[int](hex)
}

return dbclient.Client.CustomColours.BatchSet(context.Background(), guildId, converted)
Expand Down
2 changes: 1 addition & 1 deletion backend/app/http/endpoints/api/ticket/closerequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func buildCloseRequestMessage(locale *i18n.Locale, requesterId uint64, reason *s
msgEmbed := &embed.Embed{
Title: i18n.GetMessage(locale, i18n.TitleCloseRequest),
Description: description,
Color: 0x2ECC71,
Color: utils.Ptr(0x2ECC71),
}

components := []component.Component{
Expand Down
Loading
Loading