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 cmd/discord/commands/public/career.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
36 changes: 30 additions & 6 deletions cmd/discord/commands/public/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand Down Expand Up @@ -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),
}
}
2 changes: 1 addition & 1 deletion cmd/discord/commands/public/my.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion cmd/discord/commands/public/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 2 additions & 1 deletion cmd/discord/commands/public/stats_interactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Loading