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
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ BOT_USER_ID="1090704976784916581"
# This is not required for local deployment using compose. When deploying with Dokploy, this is the domain aftermath service will be available on.
TRAEFIK_HOST="local.amth.one"

# Themes
HIGHLIGHTED_THEME="" # Theme ID applied to users without a custom theme or background (e.g. "spring2026")

# Misc configuration
FRONTEND_URL="https://yourdomain.com"
WEBAPP_NAME="Aftermath"
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
FROM golang:1.26.0 AS builder-go

ARG BRAND_FLAVOR=red
ENV BRAND_FLAVOR $BRAND_FLAVOR

Check warning on line 19 in Dockerfile

View workflow job for this annotation

GitHub Actions / build-and-push-amd64-image

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/

WORKDIR /workspace

Expand All @@ -29,9 +29,10 @@
# COPY --from=builder-node /workspace/static/localization/ ./static/localization/

# generate static assets
RUN --mount=type=cache,target=$GOPATH/pkg/mod go generate ./internal/assets
RUN --mount=type=cache,target=$GOPATH/pkg/mod go generate ./internal/external/blitzkit
RUN --mount=type=cache,target=$GOPATH/pkg/mod go generate ./internal/assets
RUN --mount=type=cache,target=$GOPATH/pkg/mod go generate ./cmd/frontend/assets/generate
RUN --mount=type=cache,target=$GOPATH/pkg/mod go generate ./internal/stats/render/themes/.../assets

# generate frontend
RUN --mount=type=cache,target=$GOPATH/pkg/mod go tool templ generate
Expand Down
9 changes: 9 additions & 0 deletions cmd/discord/commands/public/career.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@ func careerCommandHandler(ctx common.Context) error {
}
}

themeID, theme, themeHint := resolveTheme(ctx.User(), ioptions.BackgroundID != "")
if theme != nil {
opts = append(opts, stats.WithTheme(*theme))
ioptions.ThemeID = themeID
if themeHint != "" && message == "" {
message = themeHint
}
}

image, meta, err := ctx.Core().Stats(ctx.Locale()).PeriodImage(ctx.Ctx(), accountID, options.PeriodStart, opts...)
if err != nil {
return ctx.Err(err, common.ApplicationError)
Expand Down
23 changes: 23 additions & 0 deletions cmd/discord/commands/public/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ import (
"unicode"
"unicode/utf8"

"github.com/cufee/aftermath/internal/constants"
"github.com/cufee/aftermath/internal/external/wargaming"
"github.com/cufee/aftermath/internal/json"
rendercommon "github.com/cufee/aftermath/internal/render/common"
"github.com/cufee/aftermath/internal/stats/render/themes"
"github.com/cufee/am-wg-proxy-next/v2/types"

"github.com/bwmarrin/discordgo"
Expand All @@ -24,6 +27,26 @@ type statsOptions struct {
commands.StatsOptions
BackgroundID string
ReferenceID string
ThemeID string
}

// resolveTheme determines the theme to apply based on user preference and highlighted env.
// When a non-nil theme is returned, the caller should skip loading custom backgrounds.
func resolveTheme(user models.User, hasCustomBackground bool) (themeID string, theme *rendercommon.Theme, hintKey string) {
if content, ok := user.Content(models.UserContentTypeThemePreference); ok {
id := string(content.Value)
if t, ok := themes.GetTheme(id); ok {
return id, &t, ""
}
}

if !hasCustomBackground && constants.HighlightedTheme != "" {
if t, ok := themes.GetTheme(constants.HighlightedTheme); ok {
return constants.HighlightedTheme, &t, "theme_highlighted_hint"
}
}

return "", nil, ""
}

func (o statsOptions) fromInteraction(data models.DiscordInteraction) (statsOptions, error) {
Expand Down
11 changes: 10 additions & 1 deletion cmd/discord/commands/public/my.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ func init() {
accountID = defaultAccount.ReferenceID
}

themeID, theme, themeHint := resolveTheme(ctx.User(), ioptions.BackgroundID != "")
if theme != nil {
opts = append(opts, stats.WithTheme(*theme))
ioptions.ThemeID = themeID
if themeHint != "" && message == "" {
message = themeHint
}
}

var err error
var image stats.Image
switch subcommand {
Expand Down Expand Up @@ -122,7 +131,7 @@ func init() {
if err != nil {
return ctx.Err(err, common.ApplicationError)
}
return ctx.Reply().WithAds().File(buf.Bytes(), "session_command_by_aftermath.png").Component(button).Send()
return ctx.Reply().WithAds().Hint(message).File(buf.Bytes(), "session_command_by_aftermath.png").Component(button).Send()
}),
)
}
9 changes: 9 additions & 0 deletions cmd/discord/commands/public/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@ func init() {
}
}

themeID, theme, themeHint := resolveTheme(ctx.User(), ioptions.BackgroundID != "")
if theme != nil {
opts = append(opts, stats.WithTheme(*theme))
ioptions.ThemeID = themeID
if themeHint != "" && message == "" {
message = themeHint
}
}

image, meta, err := ctx.Core().Stats(ctx.Locale()).SessionImage(ctx.Ctx(), accountID, options.PeriodStart, opts...)
if err != nil {
if errors.Is(err, stats.ErrAccountNotTracked) || (errors.Is(err, fetch.ErrSessionNotFound) && options.Days < 1) {
Expand Down
10 changes: 7 additions & 3 deletions cmd/discord/commands/public/stats_interactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (
"github.com/cufee/aftermath/internal/glossary"
"github.com/cufee/aftermath/internal/logic"
"github.com/cufee/aftermath/internal/permissions"
"github.com/cufee/aftermath/internal/stats/fetch/v1"

stats "github.com/cufee/aftermath/internal/stats/client/common"
"github.com/cufee/aftermath/internal/stats/fetch/v1"
"github.com/cufee/aftermath/internal/stats/render/themes"

"github.com/cufee/aftermath/internal/log"
"github.com/pkg/errors"
Expand Down Expand Up @@ -66,7 +66,11 @@ func init() {
}
}

if ioptions.BackgroundID != "" {
if ioptions.ThemeID != "" {
if t, ok := themes.GetTheme(ioptions.ThemeID); ok {
opts = append(opts, stats.WithTheme(t))
}
} else if ioptions.BackgroundID != "" {
background, _ := ctx.Core().Database().GetUserContent(ctx.Ctx(), ioptions.BackgroundID)
if img, err := logic.UserContentToImage(background); err == nil {
opts = append(opts, stats.WithBackground(img, true))
Expand Down
123 changes: 123 additions & 0 deletions cmd/discord/commands/public/theme.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package public

import (
"fmt"
"sort"
"strings"

"github.com/bwmarrin/discordgo"
"github.com/cufee/aftermath/cmd/discord/commands"
"github.com/cufee/aftermath/cmd/discord/commands/builder"
"github.com/cufee/aftermath/cmd/discord/common"
"github.com/cufee/aftermath/cmd/discord/middleware"
"github.com/cufee/aftermath/internal/database"
"github.com/cufee/aftermath/internal/database/models"
"github.com/cufee/aftermath/internal/permissions"
"github.com/cufee/aftermath/internal/stats/render/themes"
)

func buildThemeChoices() []builder.OptionChoice {
var choices []builder.OptionChoice
for _, id := range themes.AvailableThemes() {
choices = append(choices, builder.NewChoice(id, id))
}
return choices
}

func init() {
commands.LoadedPublic.Add(
builder.NewCommand("theme").
Middleware(middleware.RequirePermissions(permissions.UseTextCommands)).
Ephemeral().
Params(builder.SetNameKey("command_theme_name"), builder.SetDescKey("command_theme_description")).
Options(
builder.NewOption("select", discordgo.ApplicationCommandOptionString).
Params(builder.SetNameKey("command_theme_option_select_name"), builder.SetDescKey("command_theme_option_select_description")).
Choices(buildThemeChoices()...),
builder.NewOption("clear", discordgo.ApplicationCommandOptionBoolean).
Params(builder.SetNameKey("command_theme_option_clear_name"), builder.SetDescKey("command_theme_option_clear_description")),
).
Handler(func(ctx common.Context) error {
if clear, ok := common.GetOption[bool](ctx.Options(), "clear"); ok && clear {
existing, err := ctx.Core().Database().GetUserContentFromRef(ctx.Ctx(), ctx.User().ID, models.UserContentTypeThemePreference)
if err != nil && !database.IsNotFound(err) {
return ctx.Err(err, common.ApplicationError)
}
if !database.IsNotFound(err) {
err = ctx.Core().Database().DeleteUserContent(ctx.Ctx(), existing.ID)
if err != nil {
return ctx.Err(err, common.ApplicationError)
}
}
return ctx.Reply().Send("command_theme_reset_success")
}

selected, hasSelection := common.GetOption[string](ctx.Options(), "select")
if !hasSelection {
currentTheme, hasTheme := ctx.User().Content(models.UserContentTypeThemePreference)
var currentID string
if hasTheme {
currentID = string(currentTheme.Value)
} else {
currentID = "default"
}

ids := themes.AvailableThemes()
sort.Strings(ids)

var lines []string
for _, id := range ids {
name := ctx.Localize(fmt.Sprintf("command_theme_option_select_choice_%s_name", id))
if name == "" {
name = id
}
if id == currentID {
lines = append(lines, "⬢ "+name)
} else {
lines = append(lines, "⬡ "+name)
}
}

return ctx.Reply().Format("command_theme_current_fmt", strings.Join(lines, "\n")).Send()
}

if selected == "default" {
existing, err := ctx.Core().Database().GetUserContentFromRef(ctx.Ctx(), ctx.User().ID, models.UserContentTypeThemePreference)
if err != nil && !database.IsNotFound(err) {
return ctx.Err(err, common.ApplicationError)
}
if !database.IsNotFound(err) {
err = ctx.Core().Database().DeleteUserContent(ctx.Ctx(), existing.ID)
if err != nil {
return ctx.Err(err, common.ApplicationError)
}
}
return ctx.Reply().Send("command_theme_reset_success")
}

if _, ok := themes.GetTheme(selected); !ok {
return ctx.Reply().IsError(common.UserError).Send("command_theme_not_found")
}

existing, err := ctx.Core().Database().GetUserContentFromRef(ctx.Ctx(), ctx.User().ID, models.UserContentTypeThemePreference)
if err != nil && !database.IsNotFound(err) {
return ctx.Err(err, common.ApplicationError)
}
if database.IsNotFound(err) {
existing = models.UserContent{
UserID: ctx.User().ID,
ReferenceID: ctx.User().ID,
}
}

existing.Type = models.UserContentTypeThemePreference
existing.Value = []byte(selected)
_, err = ctx.Core().Database().UpsertUserContent(ctx.Ctx(), existing)
if err != nil {
return ctx.Err(err, common.ApplicationError)
}

return ctx.Reply().Format("command_theme_set_success_fmt", selected).Send()
}),
)
}
7 changes: 7 additions & 0 deletions cmd/discord/cta/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ var (
buttons: []discordgo.Button{common.ButtonInviteAftermath("cta_guild_install_button")},
}

ctaCommandTheme = CallToActionMessage{
TagsBlacklist: []string{"command_theme"},
headKey: "cta_command_theme_head",
bodyKey: "cta_command_theme_body",
}

ctaAbandonedPositiveGrowth = CallToActionMessage{
TagsWhitelist: []string{"growth", "growth_positive"},
headKey: "cta_abandoned_positive_growth_head",
Expand Down Expand Up @@ -120,6 +126,7 @@ var defaultCTACollection = MessageCollection{
ctaCommandReplay,
ctaCommandLinksAdd,
ctaCommandLinksVerify,
ctaCommandTheme,
}

func (c MessageCollection) NewEmbed(locale language.Tag, tags []string) (discordgo.MessageEmbed, []discordgo.MessageComponent, bool) {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/bwmarrin/discordgo v0.29.0
github.com/cufee/aftermath-assets v0.1.0
github.com/cufee/am-wg-proxy-next/v2 v2.2.6
github.com/cufee/facepaint v0.0.9
github.com/cufee/facepaint v0.1.0
github.com/fogleman/gg v1.3.0
github.com/go-co-op/gocron v1.37.0
github.com/goccy/go-json v0.10.5
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ github.com/cufee/aftermath-assets v0.1.0 h1:r8p2mUN+h/cw1T6/oEX7bntD+lrL9Nz27GXO
github.com/cufee/aftermath-assets v0.1.0/go.mod h1:6yCITCiz7POJnUMn1oohvadLA4z5YrFNo3p9EKgRdGU=
github.com/cufee/am-wg-proxy-next/v2 v2.2.6 h1:6RAnPuYbPGtaLzOPhTk/N2Hx4KJx14x/c/cIik668xA=
github.com/cufee/am-wg-proxy-next/v2 v2.2.6/go.mod h1:x6fkRfYry3l4Ykxl+v6pJAw5ISw+CuGzJzSkc5y5SYs=
github.com/cufee/facepaint v0.0.9 h1:cXoQpjqLtrcEKs6KwVt2DKB+uPREIPHPw14ilLRyboc=
github.com/cufee/facepaint v0.0.9/go.mod h1:7zR5lQMN3EO3qNtff0J8nzIhDb258UoYbRzhRToLQdg=
github.com/cufee/facepaint v0.1.0 h1:MKD5HIzuaBGDF84GWtkhi/XsQxCHv1sjCPPFMQuoWvM=
github.com/cufee/facepaint v0.1.0/go.mod h1:7zR5lQMN3EO3qNtff0J8nzIhDb258UoYbRzhRToLQdg=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
5 changes: 5 additions & 0 deletions internal/constants/themes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package constants

import "os"

var HighlightedTheme = os.Getenv("HIGHLIGHTED_THEME")
1 change: 1 addition & 0 deletions internal/database/models/user_content.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const (
UserContentTypeInModeration = UserContentType("in-moderation")
UserContentTypeClanBackground = UserContentType("clan-background-image")
UserContentTypePersonalBackground = UserContentType("personal-background-image")
UserContentTypeThemePreference = UserContentType("theme-preference")
)

func (t UserContentType) Valid() bool {
Expand Down
Loading
Loading