From 7ff27fa6b14f1901d1b98e7fb08613b563f6a584 Mon Sep 17 00:00:00 2001 From: Vovko Date: Sat, 28 Feb 2026 20:03:43 -0600 Subject: [PATCH] added career to sessions --- cmd/discord/commands/public/career.go | 2 +- cmd/discord/commands/public/common.go | 36 +++++++++++++++---- cmd/discord/commands/public/my.go | 2 +- cmd/discord/commands/public/session.go | 2 +- .../commands/public/stats_interactions.go | 3 +- 5 files changed, 35 insertions(+), 10 deletions(-) diff --git a/cmd/discord/commands/public/career.go b/cmd/discord/commands/public/career.go index e0c6218..0e64472 100644 --- a/cmd/discord/commands/public/career.go +++ b/cmd/discord/commands/public/career.go @@ -121,7 +121,7 @@ func careerCommandHandler(ctx common.Context) error { } ioptions.AccountID = accountID - button, saveErr := ioptions.actionRow(ctx, ctx.ID(), true) + button, saveErr := ioptions.actionRow(ctx, ctx.ID(), true, false) if saveErr != nil { // nil button will not cause an error and will be ignored log.Err(saveErr).Str("interactionId", ctx.ID()).Str("command", ctx.ID()).Msg("failed to save discord interaction") diff --git a/cmd/discord/commands/public/common.go b/cmd/discord/commands/public/common.go index 0b507fa..e7c7308 100644 --- a/cmd/discord/commands/public/common.go +++ b/cmd/discord/commands/public/common.go @@ -63,7 +63,7 @@ func (o statsOptions) interactionButton(ctx common.Context, eventID string, resu return ctx.Core().Database().CreateDiscordInteraction(ctx.Ctx(), interaction) } -func (o statsOptions) actionRow(ctx common.Context, refreshEventID string, includeSession bool) (discordgo.MessageComponent, error) { +func (o statsOptions) actionRow(ctx common.Context, refreshEventID string, includeSession bool, includeCareer bool) (discordgo.MessageComponent, error) { refresh, err := o.interactionButton(ctx, refreshEventID, "generated-refresh-button") if err != nil { return nil, err @@ -74,16 +74,28 @@ func (o statsOptions) actionRow(ctx common.Context, refreshEventID string, inclu newStatsRefreshButton(refresh), }, } - if !includeSession { + if !includeSession && !includeCareer { return row, nil } - session, sessionErr := o.interactionButton(ctx, "session", "generated-session-button") - if sessionErr != nil { - return row, sessionErr + if includeSession { + session, sessionErr := o.interactionButton(ctx, "session", "generated-session-button") + if sessionErr != nil { + return row, sessionErr + } + + row.Components = append(row.Components, newStatsSessionButton(ctx, session)) + } + + if includeCareer { + career, careerErr := o.interactionButton(ctx, "career", "generated-career-button") + if careerErr != nil { + return row, careerErr + } + + row.Components = append(row.Components, newStatsCareerButton(ctx, career)) } - row.Components = append(row.Components, newStatsSessionButton(ctx, session)) return row, nil } @@ -210,3 +222,15 @@ func newStatsSessionButton(ctx common.Context, data models.DiscordInteraction) d CustomID: fmt.Sprintf("refresh_stats_from_button#%s", data.ID), } } + +func newStatsCareerButton(ctx common.Context, data models.DiscordInteraction) discordgo.Button { + label := ctx.Localize("command_career_name") + r, size := utf8.DecodeRuneInString(label) + label = string(unicode.ToUpper(r)) + label[size:] + + return discordgo.Button{ + Style: discordgo.SecondaryButton, + Label: label, + CustomID: fmt.Sprintf("refresh_stats_from_button#%s", data.ID), + } +} diff --git a/cmd/discord/commands/public/my.go b/cmd/discord/commands/public/my.go index aecb15c..7d21259 100644 --- a/cmd/discord/commands/public/my.go +++ b/cmd/discord/commands/public/my.go @@ -111,7 +111,7 @@ func init() { } ioptions.AccountID = accountID - button, saveErr := ioptions.actionRow(ctx, subcommand, subcommand != "session") + button, saveErr := ioptions.actionRow(ctx, subcommand, subcommand != "session", subcommand == "session") if saveErr != nil { // nil button will not cause an error and will be ignored log.Err(saveErr).Str("interactionId", ctx.ID()).Str("command", subcommand).Msg("failed to save discord interaction") diff --git a/cmd/discord/commands/public/session.go b/cmd/discord/commands/public/session.go index 52d45d5..0c764cd 100644 --- a/cmd/discord/commands/public/session.go +++ b/cmd/discord/commands/public/session.go @@ -127,7 +127,7 @@ func init() { } ioptions.AccountID = accountID - button, saveErr := ioptions.actionRow(ctx, ctx.ID(), false) + button, saveErr := ioptions.actionRow(ctx, ctx.ID(), false, true) if saveErr != nil { // nil button will not cause an error and will be ignored log.Err(saveErr).Str("interactionId", ctx.ID()).Str("command", "session").Msg("failed to save discord interaction") diff --git a/cmd/discord/commands/public/stats_interactions.go b/cmd/discord/commands/public/stats_interactions.go index a02856c..fd4e4e6 100644 --- a/cmd/discord/commands/public/stats_interactions.go +++ b/cmd/discord/commands/public/stats_interactions.go @@ -111,7 +111,8 @@ func init() { } includeSession := interaction.EventID != "session" && interaction.EventID != "replay" - button, saveErr := ioptions.actionRow(ctx, interaction.EventID, includeSession) + includeCareer := interaction.EventID == "session" + button, saveErr := ioptions.actionRow(ctx, interaction.EventID, includeSession, includeCareer) if saveErr != nil { // nil button will not cause an error and will be ignored log.Err(saveErr).Str("interactionId", ctx.ID()).Str("command", interaction.EventID).Msg("failed to save discord interaction")