Skip to content
Merged
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/command/impl/tags/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (TagCommand) Execute(ctx registry.CommandContext, tagId string) {
var embeds []*embed.Embed
if tag.Embed != nil {
embeds = []*embed.Embed{
logic.BuildCustomEmbed(ctx, ctx.Worker(), ticket, *tag.Embed.CustomEmbed, tag.Embed.Fields, false, nil),
logic.BuildCustomEmbed(ctx, ctx.Worker(), ticket, *tag.Embed.CustomEmbed, tag.Embed.Fields, logic.FooterPolicy{AllowCustom: true}, nil),
}
}

Expand Down
2 changes: 1 addition & 1 deletion bot/command/impl/tags/tagalias.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (c TagAliasCommand) Execute(ctx registry.CommandContext) {
var embeds []*embed.Embed
if c.tag.Embed != nil {
embeds = []*embed.Embed{
logic.BuildCustomEmbed(ctx, ctx.Worker(), ticket, *c.tag.Embed.CustomEmbed, c.tag.Embed.Fields, false, nil),
logic.BuildCustomEmbed(ctx, ctx.Worker(), ticket, *c.tag.Embed.CustomEmbed, c.tag.Embed.Fields, logic.FooterPolicy{AllowCustom: true}, nil),
}
}

Expand Down
28 changes: 24 additions & 4 deletions bot/logic/welcomemessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"sync"
"time"

"github.com/TicketsBot-cloud/common/model"
"github.com/TicketsBot-cloud/common/premium"
"github.com/TicketsBot-cloud/common/sentry"
"github.com/TicketsBot-cloud/database"
Expand Down Expand Up @@ -145,7 +146,7 @@ func BuildWelcomeMessageEmbed(
return nil, err
}

e := BuildCustomEmbed(ctx, cmd.Worker(), ticket, data, fields, cmd.PremiumTier() == premium.None, additionalPlaceholders)
e := BuildCustomEmbed(ctx, cmd.Worker(), ticket, data, fields, FooterPolicyForContext(ctx, cmd), additionalPlaceholders)
return e, nil
}
}
Expand Down Expand Up @@ -709,12 +710,31 @@ func truncateRunes(s string, limit int) string {
return string(runes[:limit])
}

type FooterPolicy struct {
ShowBranding bool
AllowCustom bool
}

func FooterPolicyForContext(ctx context.Context, cmd registry.CommandContext) FooterPolicy {
if cmd.PremiumTier() == premium.None {
return FooterPolicy{ShowBranding: true}
}

_, source, err := utils.PremiumClient.GetTierByGuildIdWithSource(ctx, cmd.GuildId(), cmd.Worker().Token, cmd.Worker().RateLimiter)
if err != nil {
sentry.Error(err)
return FooterPolicy{AllowCustom: true}
}

return FooterPolicy{AllowCustom: source != model.EntitlementSourceVoting}
}

func BuildCustomEmbed(
ctx context.Context, worker *worker.Context,
ticket database.Ticket,
customEmbed database.CustomEmbed,
fields []database.EmbedField,
branding bool,
footer FooterPolicy,
// Only custom integration placeholders for now - prevent making duplicate requests
additionalPlaceholders map[string]string,
) *embed.Embed {
Expand Down Expand Up @@ -746,9 +766,9 @@ func BuildCustomEmbed(
Color: int(customEmbed.Colour),
}

if branding {
if footer.ShowBranding {
e.SetFooter(fmt.Sprintf("Powered by %s", config.Conf.Bot.PoweredBy), config.Conf.Bot.IconUrl)
} else if customEmbed.FooterText != nil {
} else if footer.AllowCustom && customEmbed.FooterText != nil {
e.SetFooter(
plainTextSubstitute(*customEmbed.FooterText, embedFooterTextLimit),
resolveAvatarUrl(utils.ValueOrZero(customEmbed.FooterIconUrl)),
Expand Down
Loading