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 bot/button/handlers/closerequestaccept.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (h *CloseRequestAcceptHandler) Execute(ctx *context.ButtonContext) {
}

ctx.Edit(command.MessageResponse{
Embeds: utils.Slice(utils.BuildEmbedRaw(customisation.DefaultColours[customisation.Green], "Close Request", "Closing ticket...", nil, premium.Whitelabel)), // TODO: Translations, calculate premium level
Embeds: utils.Slice(utils.BuildEmbedRaw(utils.Ptr(customisation.DefaultColours[customisation.Green]), "Close Request", "Closing ticket...", nil, premium.Whitelabel)), // TODO: Translations, calculate premium level
})

// Avoid users cant close issue
Expand Down
2 changes: 1 addition & 1 deletion bot/button/handlers/viewsurvey.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (h *ViewSurveyHandler) Execute(ctx *context.ButtonContext) {
e := embed.NewEmbed().
SetTitle("Exit Survey"). // TODO: i18n
SetAuthor(opener.Username, "", opener.AvatarUrl(256)).
SetColor(ctx.GetColour(customisation.Green))
SetColorPtr(ctx.GetColour(customisation.Green))

for _, answer := range surveyResponse.Responses {
var title string
Expand Down
17 changes: 11 additions & 6 deletions bot/command/context/replyable.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (

type Replyable struct {
ctx registry.CommandContext
colourCodes map[customisation.Colour]int
colourCodes map[customisation.Colour]*int
}

type rateLimitResponse struct {
Expand All @@ -44,18 +44,18 @@ type rateLimitResponse struct {
}

func NewReplyable(ctx registry.CommandContext) *Replyable {
var colourCodes map[customisation.Colour]int
var colourCodes map[customisation.Colour]*int
if ctx.PremiumTier() > premium.None {
// TODO: Propagate context
tmp, err := customisation.GetColours(context.Background(), ctx.GuildId())
if err != nil {
sentry.ErrorWithContext(err, ctx.ToErrorContext())
colourCodes = customisation.DefaultColours
colourCodes = customisation.GetDefaultColours()
} else {
colourCodes = tmp
}
} else {
colourCodes = customisation.DefaultColours
colourCodes = customisation.GetDefaultColours()
}

return &Replyable{
Expand All @@ -64,8 +64,13 @@ func NewReplyable(ctx registry.CommandContext) *Replyable {
}
}

func (r *Replyable) GetColour(colour customisation.Colour) int {
return r.colourCodes[colour]
func (r *Replyable) GetColour(colour customisation.Colour) *int {
code := r.colourCodes[colour]
if code == nil {
return nil
}

return utils.Ptr(*code)
}

func (r *Replyable) buildEmbed(colour customisation.Colour, title, content i18n.MessageId, fields []embed.EmbedField, format ...interface{}) *embed.Embed {
Expand Down
2 changes: 1 addition & 1 deletion bot/command/impl/general/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (c HelpCommand) Execute(ctx registry.CommandContext) {
}

embed := embed.NewEmbed().
SetColor(ctx.GetColour(customisation.Green)).
SetColorPtr(ctx.GetColour(customisation.Green)).
SetTitle(ctx.GetMessage(i18n.TitleHelp))

for _, category := range commandCategories.Keys() {
Expand Down
7 changes: 3 additions & 4 deletions bot/command/impl/settings/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (SetupCommand) Execute(ctx registry.CommandContext) {

embed := embed.NewEmbed().
SetTitle("Setup").
SetColor(getColour(context.Background(), ctx.GuildId(), failed)). // TODO: Propagate context
SetColorPtr(getColour(context.Background(), ctx.GuildId(), failed)). // TODO: Propagate context
SetDescription(messageContent)

ctx.ReplyWithEmbed(embed)
Expand Down Expand Up @@ -132,16 +132,15 @@ func edit(ctx *cmdcontext.SlashCommandContext, e *embed.Embed) error {
return err
}

func getColour(ctx context.Context, guildId uint64, failed bool) int {
func getColour(ctx context.Context, guildId uint64, failed bool) *int {
var colour customisation.Colour
if failed {
colour = customisation.Red
} else {
colour = customisation.Green
}

hex, _ := customisation.GetColour(ctx, guildId, colour)
return hex
return customisation.GetColourOrDefault(ctx, guildId, colour)
}

func getTranscriptChannelData(guildId, supportRoleId, adminRoleId uint64) rest.CreateChannelData {
Expand Down
2 changes: 1 addition & 1 deletion bot/command/impl/tickets/switchpanel.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func (SwitchPanelCommand) Execute(ctx *cmdcontext.SlashCommandContext, panelId i
}

for i := 1; i < len(embeds); i++ {
embeds[i].Color = embeds[0].Color
embeds[i].SetColorPtr(embeds[0].Color)
}

editData := rest.EditMessageData{
Expand Down
2 changes: 1 addition & 1 deletion bot/command/registry/commandcontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type CommandContext interface {
HandleWarning(err error)

GetMessage(messageId i18n.MessageId, format ...interface{}) string
GetColour(colour customisation.Colour) int
GetColour(colour customisation.Colour) *int

// Utility functions
Channel() (channel.PartialChannel, error)
Expand Down
46 changes: 20 additions & 26 deletions bot/customisation/colour.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,55 +37,49 @@ func GetDefaultColour(colour Colour) int {
return DefaultColours[colour]
}

func GetDefaultColours() map[Colour]*int {
colours := make(map[Colour]*int, len(DefaultColours))
for id, hex := range DefaultColours {
colours[id] = &hex
}

return colours
}

func defaultColour(colour Colour) *int {
hex := GetDefaultColour(colour)
return &hex
}

func IsValidColour(colour Colour) bool {
_, valid := DefaultColours[colour]
return valid
}

func GetColours(ctx context.Context, guildId uint64) (map[Colour]int, error) {
func GetColours(ctx context.Context, guildId uint64) (map[Colour]*int, error) {
raw, err := dbclient.Client.CustomColours.GetAll(ctx, guildId)
if err != nil {
return DefaultColours, err
return GetDefaultColours(), err
}

colours := make(map[Colour]int)
colours := GetDefaultColours()
for id, hex := range raw {
colours[Colour(id)] = hex
}

for id, hex := range DefaultColours {
if _, ok := colours[id]; !ok {
colours[id] = hex
}
}

return colours, nil
}

// TODO: Premium check
func GetColour(ctx context.Context, guildId uint64, colourCode Colour) (int, error) {
colour, ok, err := dbclient.Client.CustomColours.Get(ctx, guildId, colourCode.Int16())
if err != nil {
return 0, err
}

if !ok {
return GetDefaultColour(colourCode), nil
}

return colour, nil
}

// TODO: Premium check
func GetColourOrDefault(ctx context.Context, guildId uint64, colourCode Colour) int {
func GetColourOrDefault(ctx context.Context, guildId uint64, colourCode Colour) *int {
colour, ok, err := dbclient.Client.CustomColours.Get(ctx, guildId, colourCode.Int16())
if err != nil {
sentry.Error(err)
return GetDefaultColour(colourCode)
return defaultColour(colourCode)
}

if !ok {
return GetDefaultColour(colourCode)
return defaultColour(colourCode)
}

return colour
Expand Down
2 changes: 1 addition & 1 deletion bot/listeners/guildcreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func sendIntroMessage(ctx context.Context, worker *worker.Context, guild guild.G
msg := embed.NewEmbed().
SetTitle("Tickets").
SetDescription(fmt.Sprintf("Thank you for inviting Tickets to your server! Below is a quick guide on setting up the bot, please don't hesitate to contact us in our [support server](%s) if you need any assistance!", config.Conf.Bot.SupportServerInvite)).
SetColor(customisation.GetColourOrDefault(ctx, guild.Id, customisation.Green)).
SetColorPtr(customisation.GetColourOrDefault(ctx, guild.Id, customisation.Green)).
AddField("Setup", fmt.Sprintf("You can setup the bot using `/setup`, or you can use the [web dashboard](%s) which has additional options", config.Conf.Bot.DashboardUrl), false).
AddField("Ticket Panels", fmt.Sprintf("Ticket panels are a commonly used feature of the bot. You can read about them [here](%s/setup/ticket-panels), or create one on the [web dashboard](%s/manage/%d/panels)", config.Conf.Bot.DocsUrl, config.Conf.Bot.DashboardUrl, guild.Id), false).
AddField("Adding Staff", "To allow staff to answer tickets, you must let the bot know about them first. You can do this through\n`/addsupport [@User / @Role]` and `/addadmin [@User / @Role]`. While both Support and Admin can access the dashboard, Bot Admins can change the settings of the bot.", false).
Expand Down
4 changes: 2 additions & 2 deletions bot/logic/closeembed.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,13 @@ func BuildCloseEmbed(
colour, err := utils.GetColourForGuild(ctx, worker, customisation.Green, ticket.GuildId)
if err != nil {
sentry.Error(err)
colour = customisation.Green.Default()
colour = utils.Ptr(customisation.Green.Default())
}

// TODO: Translate titles
closeEmbed := embed.NewEmbed().
SetTitle("Ticket Closed").
SetColor(colour).
SetColorPtr(colour).
AddField(formatTitle("Ticket ID", customisation.EmojiId, worker.IsWhitelabel), strconv.Itoa(ticket.Id), true).
AddField(formatTitle("Opened By", customisation.EmojiOpen, worker.IsWhitelabel), fmt.Sprintf("<@%d>", ticket.UserId), true).
AddField(formatTitle("Closed By", customisation.EmojiClose, worker.IsWhitelabel), fmt.Sprintf("<@%d>", closedBy), true).
Expand Down
7 changes: 1 addition & 6 deletions bot/logic/open.go
Original file line number Diff line number Diff line change
Expand Up @@ -615,13 +615,8 @@ func OpenTicket(ctx context.Context, cmd registry.InteractionContext, panel *dat
span := sentry.StartSpan(rootSpan.Context(), "Send out-of-hours warning")
defer span.Finish()

colourHex := customisation.GetColourOrDefault(ctx, cmd.GuildId(), customisation.Red)
if outOfHoursColour != nil {
colourHex = *outOfHoursColour
}

warningEmbed := utils.BuildEmbedRaw(
colourHex,
outOfHoursColour,
*outOfHoursTitle,
*outOfHoursWarning,
nil,
Expand Down
23 changes: 11 additions & 12 deletions bot/logic/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ func replyIfPanelUnavailable(cmd registry.InteractionContext, panel *database.Pa
// ValidatePanelAccess checks if the user can access the given panel.
// Returns (canProceed, outOfHoursWarningTitle, outOfHoursWarning, outOfHoursColour, error).
// outOfHoursWarning is non-nil when the panel is outside support hours but the behaviour is allow_with_warning.
// outOfHoursColour is non-nil when a custom colour is configured for the out-of-hours embed.
func ValidatePanelAccess(ctx registry.InteractionContext, panel database.Panel) (bool, *string, *string, *int, error) {
// Variables to hold out-of-hours warning info if behaviour is allow_with_warning
var outOfHoursWarningTitle *string
Expand Down Expand Up @@ -97,11 +96,7 @@ func ValidatePanelAccess(ctx registry.InteractionContext, panel database.Panel)
outOfHoursMessage = settings.OutOfHoursMessage
}

// Determine the custom colour (nil means use default)
var outOfHoursColour *int
if exists && settings.OutOfHoursColour != 0 {
outOfHoursColour = &settings.OutOfHoursColour
}
outOfHoursColour := resolveOutOfHoursColour(settings, exists, ctx.GetColour(customisation.Red))

behaviour := database.OutOfHoursBehaviourBlockCreation
if exists {
Expand All @@ -122,12 +117,8 @@ func ValidatePanelAccess(ctx registry.InteractionContext, panel database.Panel)
outOfHoursWarningMessage = &outOfHoursMessage
outOfHoursWarningColour = outOfHoursColour
default:
if outOfHoursColour != nil {
embed := utils.BuildEmbedRaw(*outOfHoursColour, outOfHoursTitle, outOfHoursMessage, nil, ctx.PremiumTier())
ctx.ReplyWith(command.NewEphemeralEmbedMessageResponse(embed))
} else {
ctx.ReplyRaw(customisation.Red, outOfHoursTitle, outOfHoursMessage)
}
embed := utils.BuildEmbedRaw(outOfHoursColour, outOfHoursTitle, outOfHoursMessage, nil, ctx.PremiumTier())
ctx.ReplyWith(command.NewEphemeralEmbedMessageResponse(embed))
return false, nil, nil, nil, nil
}
}
Expand Down Expand Up @@ -183,3 +174,11 @@ func ValidatePanelAccess(ctx registry.InteractionContext, panel database.Panel)

return true, outOfHoursWarningTitle, outOfHoursWarningMessage, outOfHoursWarningColour, nil
}

func resolveOutOfHoursColour(settings database.PanelSupportHoursSettings, exists bool, guildRed *int) *int {
if !exists {
return guildRed
}

return settings.OutOfHoursColour
}
7 changes: 5 additions & 2 deletions bot/logic/welcomemessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func SendWelcomeMessage(
fields := getFormDataFields(formData)
if len(fields) > 0 {
formAnswersEmbed := embed.NewEmbed().
SetColor(welcomeMessageEmbed.Color)
SetColorPtr(welcomeMessageEmbed.Color)

for _, field := range fields {
formAnswersEmbed.AddField(field.Name, utils.EscapeMarkdown(field.Value), field.Inline)
Expand Down Expand Up @@ -834,7 +834,10 @@ func BuildCustomEmbed(
Description: substitute(utils.ValueOrZero(customEmbed.Description)),
Url: resolveAvatarUrl(utils.ValueOrZero(customEmbed.Url)),
Timestamp: customEmbed.Timestamp,
Color: int(customEmbed.Colour),
}

if customEmbed.Colour != nil {
e.SetColor(int(*customEmbed.Colour))
}

if footer.ShowBranding {
Expand Down
2 changes: 1 addition & 1 deletion bot/utils/component_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func BuildContainerWithComponents[T string | i18n.MessageId](ctx registry.Comman
}

return component.BuildContainer(component.Container{
AccentColor: Ptr(ctx.GetColour(colour)),
AccentColor: ctx.GetColour(colour),
Components: components,
})
}
Expand Down
16 changes: 8 additions & 8 deletions bot/utils/messageutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func BuildEmbed(
content := i18n.GetMessageFromGuild(ctx.GuildId(), contentId, format...)

msgEmbed := embed.NewEmbed().
SetColor(ctx.GetColour(colour)).
SetColorPtr(ctx.GetColour(colour)).
SetTitle(title).
SetDescription(content)

Expand All @@ -40,10 +40,10 @@ func BuildEmbed(
}

func BuildEmbedRaw(
colourHex int, title, content string, fields []embed.EmbedField, tier premium.PremiumTier,
colour *int, title, content string, fields []embed.EmbedField, tier premium.PremiumTier,
) *embed.Embed {
msgEmbed := embed.NewEmbed().
SetColor(colourHex).
SetColorPtr(colour).
SetTitle(title).
SetDescription(content)

Expand All @@ -58,23 +58,23 @@ func BuildEmbedRaw(
return msgEmbed
}

func GetColourForGuild(ctx context.Context, worker *worker.Context, colour customisation.Colour, guildId uint64) (int, error) {
func GetColourForGuild(ctx context.Context, worker *worker.Context, colour customisation.Colour, guildId uint64) (*int, error) {
premiumTier, err := PremiumClient.GetTierByGuildId(ctx, guildId, true, worker.Token, worker.RateLimiter)
if err != nil {
return 0, err
return nil, err
}

if premiumTier > premium.None {
colourCode, ok, err := dbclient.Client.CustomColours.Get(ctx, guildId, colour.Int16())
if err != nil {
return 0, err
return nil, err
} else if !ok {
return colour.Default(), nil
return Ptr(colour.Default()), nil
} else {
return colourCode, nil
}
} else {
return colour.Default(), nil
return Ptr(colour.Default()), nil
}
}

Expand Down
2 changes: 1 addition & 1 deletion event/commandexecutor.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func executeCommand(
if errors.Is(err, ErrArgumentNotFound) {
if worker.IsWhitelabel {
content := `This command registration is outdated. Please ask the server administrators to visit the whitelabel dashboard and press "Create Slash Commands" again.`
embed := utils.BuildEmbedRaw(customisation.GetDefaultColour(customisation.Red), "Outdated Command", content, nil, premium.Whitelabel)
embed := utils.BuildEmbedRaw(utils.Ptr(customisation.GetDefaultColour(customisation.Red)), "Outdated Command", content, nil, premium.Whitelabel)
res := command.NewEphemeralEmbedMessageResponse(embed)
responseCh <- command.ResponseMessage{Data: res.IntoApplicationCommandData()}

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ module github.com/TicketsBot-cloud/worker

go 1.26.0

// replace github.com/TicketsBot-cloud/database => ../database
replace github.com/TicketsBot-cloud/database => ../database

// replace github.com/TicketsBot-cloud/common => ../common

// replace github.com/TicketsBot-cloud/gdl => ../gdl
replace github.com/TicketsBot-cloud/gdl => ../gdl

// replace github.com/TicketsBot-cloud/archiverclient => ../archiverclient

Expand Down
Loading