Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release #138

Merged
merged 61 commits into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
3e1b369
removed realm
Cufee Jan 14, 2025
83ca376
minor color/size tweaks
Cufee Jan 14, 2025
e105ae9
Merge branch 'develop' into release
Cufee Jan 14, 2025
574a288
Merge branch 'release' of github.com:Cufee/aftermath into release
Cufee Jan 14, 2025
de3ad72
incorrect color
Cufee Jan 14, 2025
d756fbc
Merge branch 'develop' into release
Cufee Jan 14, 2025
dafb92d
remove color bombs, fixed footer sizing
Cufee Jan 14, 2025
63625c5
Merge branch 'develop' into release
Cufee Jan 14, 2025
e620123
removed days option from career command
Cufee Jan 14, 2025
3558209
fixed strings
Cufee Jan 14, 2025
7a75dc7
Merge pull request #134 from Cufee/separata-stats-command
Cufee Jan 14, 2025
af8a3c9
Merge pull request #135 from Cufee/develop
Cufee Jan 14, 2025
9d08e34
updated help message
Cufee Jan 14, 2025
0a4b409
Merge branch 'develop' into release
Cufee Jan 14, 2025
337ce7c
Merge branch 'release' of github.com:Cufee/aftermath into release
Cufee Jan 14, 2025
7a8b09b
removed session color bombing
Cufee Jan 14, 2025
10b2bc1
Merge branch 'develop' into release
Cufee Jan 14, 2025
8f32945
cleanup, more consistent UI
Cufee Jan 14, 2025
7cd1e4d
Merge branch 'develop' into release
Cufee Jan 14, 2025
078a8fc
fixed missing autocomplete match keys
Cufee Jan 15, 2025
23c616e
Merge branch 'develop' into release
Cufee Jan 15, 2025
1f38c16
fixed subcommand options
Cufee Jan 15, 2025
9f491a1
Merge branch 'develop' into release
Cufee Jan 15, 2025
db9e259
cleaned up compose
Cufee Jan 16, 2025
f6d1402
kinda works
Cufee Jan 17, 2025
9575584
fixing buggos
Cufee Jan 17, 2025
e8e5a91
fixed grow with gaps
Cufee Jan 18, 2025
462f368
fixed more grow bugs
Cufee Jan 18, 2025
849d7cd
fixed width calculation bug with gaps
Cufee Jan 18, 2025
0e6d93a
absolute positioning
Cufee Jan 18, 2025
f6e0832
added zIndex
Cufee Jan 18, 2025
b557b68
removed unusable method
Cufee Jan 18, 2025
9085416
moved some useful common logic out
Cufee Jan 18, 2025
9df1344
made cards more transparent
Cufee Jan 18, 2025
aa4deb7
Merge branch 'develop' into release
Cufee Jan 18, 2025
00ac2a5
moved render package out
Cufee Jan 18, 2025
5959770
added v2 rendering package
Cufee Jan 18, 2025
11f7ba1
added player name
Cufee Jan 19, 2025
31e02ee
removed mod replace
Cufee Jan 19, 2025
b8c92b4
Merge branch 'render-v2' into develop
Cufee Jan 19, 2025
d00c878
enabled v2 client
Cufee Jan 19, 2025
9308537
Merge branch 'render-v2' into develop
Cufee Jan 19, 2025
dbd5bb2
added highlight cards
Cufee Jan 19, 2025
8c295d3
removed unused arg
Cufee Jan 19, 2025
d50cedd
Merge pull request #136 from Cufee/render-v2
Cufee Jan 19, 2025
a702973
more accurate sizing
Cufee Jan 19, 2025
5c3fefd
Merge branch 'develop' of github.com:Cufee/aftermath into develop
Cufee Jan 19, 2025
f13dd18
fixed highlight card width
Cufee Jan 19, 2025
9195948
added gap
Cufee Jan 19, 2025
47ef561
slightly bigger gaps
Cufee Jan 19, 2025
d06459e
more consistent cards
Cufee Jan 19, 2025
0cbd231
darker pill
Cufee Jan 19, 2025
2c97c44
mod tidy
Cufee Jan 19, 2025
c569565
Merge pull request #137 from Cufee/develop
Cufee Jan 19, 2025
7312873
reduced min ga
Cufee Jan 19, 2025
7f6db84
Merge branch 'develop' into release
Cufee Jan 19, 2025
9f17d6c
Merge branch 'release' of github.com:Cufee/aftermath into release
Cufee Jan 19, 2025
0895114
fixed custom background
Cufee Jan 19, 2025
8f7cf99
Merge branch 'develop' into release
Cufee Jan 19, 2025
2a25fe6
removed restart from collector
Cufee Jan 19, 2025
d1aa15b
Merge branch 'develop' into release
Cufee Jan 19, 2025
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/core/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/cufee/aftermath/internal/database"
"github.com/cufee/aftermath/internal/external/wargaming"
"github.com/cufee/aftermath/internal/realtime"
stats "github.com/cufee/aftermath/internal/stats/client/v1"
stats "github.com/cufee/aftermath/internal/stats/client/v2"
"github.com/cufee/aftermath/internal/stats/fetch/v1"
"golang.org/x/text/language"
)
Expand Down
8 changes: 7 additions & 1 deletion cmd/discord/commands/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,19 @@ var UserOption = builder.NewOption("user", discordgo.ApplicationCommandOptionUse
builder.SetDescKey("common_option_stats_user_description"),
)

var DefaultStatsOptions = []builder.Option{
var SessionStatsOptions = []builder.Option{
DaysOption,
NicknameOption,
VehicleOption,
UserOption,
}

var CareerStatsOptions = []builder.Option{
NicknameOption,
VehicleOption,
UserOption,
}

type StatsOptions struct {
PeriodStart time.Time
Days int
Expand Down
12 changes: 6 additions & 6 deletions cmd/discord/commands/public/autocomplete.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func init() {
ComponentType(func(s string) bool {
var keys []string
keys = append(keys, "autocomplete_links_favorite_selected", "autocomplete_links_remove_selected") // links
keys = append(keys, "autocomplete_my_session_account", "autocomplete_my_stats_account") // my
keys = append(keys, "autocomplete_my_session_account", "autocomplete_my_career_account") // my
keys = append(keys, "autocomplete_widget_account") // widget
return slices.Contains(keys, s)
}).
Expand Down Expand Up @@ -63,8 +63,8 @@ func init() {
builder.NewCommand("autocomplete_tank_search").
ComponentType(func(s string) bool {
var keys []string
keys = append(keys, "autocomplete_stats_tank", "autocomplete_session_tank") // stats/session
keys = append(keys, "autocomplete_my_session_tank", "autocomplete_my_stats_tank") // my
keys = append(keys, "autocomplete_career_tank", "autocomplete_stats_tank", "autocomplete_session_tank") // stats/session
keys = append(keys, "autocomplete_my_session_tank", "autocomplete_my_career_tank") // my
return slices.Contains(keys, s)
}).
Handler(func(ctx common.Context) error {
Expand Down Expand Up @@ -100,9 +100,9 @@ func init() {
builder.NewCommand("autocomplete_account_search").
ComponentType(func(s string) bool {
var keys []string
keys = append(keys, "autocomplete_manage_accounts_search_nickname") // manage
keys = append(keys, "autocomplete_stats_nickname", "autocomplete_session_nickname") // stats/session
keys = append(keys, "autocomplete_links_add_nickname") // links
keys = append(keys, "autocomplete_manage_accounts_search_nickname") // manage
keys = append(keys, "autocomplete_career_nickname", "autocomplete_stats_nickname", "autocomplete_session_nickname") // stats/session
keys = append(keys, "autocomplete_links_add_nickname") // links
return slices.Contains(keys, s)
}).
Handler(func(ctx common.Context) error {
Expand Down
158 changes: 158 additions & 0 deletions cmd/discord/commands/public/career.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
package public

import (
"bytes"
"context"
"errors"
"fmt"

"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/external/blitzstars"
"github.com/cufee/aftermath/internal/log"
"github.com/cufee/aftermath/internal/logic"
"github.com/cufee/aftermath/internal/permissions"
stats "github.com/cufee/aftermath/internal/stats/client/common"
"github.com/cufee/aftermath/internal/utils"
)

var (
careerCommandMiddleware = []middleware.MiddlewareFunc{middleware.RequirePermissions(permissions.UseTextCommands, permissions.UseImageCommands)}
careerCommandOptions = commands.CareerStatsOptions
)

func careerCommandHandler(ctx common.Context) error {
options := commands.GetDefaultStatsOptions(ctx.Options())
message, valid := options.Validate(ctx)
if !valid {
return ctx.Reply().Send(message)
}

var accountID string
var opts = []stats.RequestOption{stats.WithWN8(), stats.WithVehicleID(options.TankID)}

ioptions := statsOptions{StatsOptions: options}

switch {
case options.UserID != "":
// mentioned another user, check if the user has an account linked
mentionedUser, _ := ctx.Core().Database().GetUserByID(ctx.Ctx(), options.UserID, database.WithConnections(), database.WithSubscriptions(), database.WithContent())
defaultAccount, hasDefaultAccount := mentionedUser.Connection(models.ConnectionTypeWargaming, nil, utils.Pointer(true))
if !hasDefaultAccount {
return ctx.Reply().Send("stats_error_connection_not_found_vague")
}
accountID = defaultAccount.ReferenceID

if img, content, err := logic.GetAccountBackgroundImage(ctx.Ctx(), ctx.Core().Database(), accountID); err == nil {
opts = append(opts, stats.WithBackground(img, true))
ioptions.BackgroundID = content.ID
}

case options.AccountID != "":
// account selected from autocomplete
accountID = options.AccountID

if img, content, err := logic.GetAccountBackgroundImage(ctx.Ctx(), ctx.Core().Database(), accountID); err == nil {
opts = append(opts, stats.WithBackground(img, true))
ioptions.BackgroundID = content.ID
}

case options.NicknameSearch != "" && options.AccountID == "":
// nickname provided, but user did not select an option from autocomplete
accounts, err := accountsFromBadInput(ctx.Ctx(), ctx.Core().Fetch(), options.NicknameSearch)
if err != nil {
return ctx.Err(err)
}
if len(accounts) == 0 {
return ctx.Reply().Send("stats_account_not_found")
}

realms := make(map[string]struct{})
for _, a := range accounts {
realms[a.Realm.String()] = struct{}{}
}
if len(realms) > 1 {
reply, err := realmSelectButtons(ctx, ctx.ID(), accounts)
if err != nil {
return ctx.Err(err)
}
return reply.Send()
}

// one or more options on the same server - just pick the first one
message = "stats_bad_nickname_input_hint"
accountID = fmt.Sprint(accounts[0].ID)

default:
defaultAccount, hasDefaultAccount := ctx.User().Connection(models.ConnectionTypeWargaming, nil, utils.Pointer(true))
if !hasDefaultAccount {
return ctx.Reply().Send("command_career_help_message")
}
// command used without options, but user has a default connection
accountID = defaultAccount.ReferenceID

if img, content, err := logic.GetAccountBackgroundImage(ctx.Ctx(), ctx.Core().Database(), accountID); err == nil {
opts = append(opts, stats.WithBackground(img, true))
ioptions.BackgroundID = content.ID
} else {
background, _ := ctx.User().Content(models.UserContentTypePersonalBackground)
if img, err := logic.UserContentToImage(background); err == nil {
opts = append(opts, stats.WithBackground(img, true))
ioptions.BackgroundID = background.ID
}
}
}

image, meta, err := ctx.Core().Stats(ctx.Locale()).PeriodImage(context.Background(), accountID, options.PeriodStart, opts...)
if errors.Is(err, blitzstars.ErrServiceUnavailable) {
return ctx.Reply().
Hint(ctx.InteractionID()).
Component(discordgo.ActionsRow{Components: []discordgo.MessageComponent{common.ButtonJoinPrimaryGuild(ctx.Localize("buttons_have_a_question_question"))}}).
Send("blitz_stars_error_service_down")
}
if err != nil {
return ctx.Err(err)
}

ioptions.AccountID = accountID
button, saveErr := ioptions.refreshButton(ctx, ctx.ID())
if saveErr != nil {
// nil button will not cause an error and will be ignored
log.Err(err).Str("interactionId", ctx.ID()).Str("command", "session").Msg("failed to save discord interaction")
}

var buf bytes.Buffer
err = image.PNG(&buf)
if err != nil {
return ctx.Err(err)
}

var timings []string
if ctx.User().HasPermission(permissions.UseDebugFeatures) {
timings = append(timings, "```")
for name, duration := range meta.Timings {
timings = append(timings, fmt.Sprintf("%s: %v", name, duration.Milliseconds()))
}
timings = append(timings, "```")
}

return ctx.Reply().WithAds().Hint(message).File(buf.Bytes(), "stats_command_by_aftermath.png").Component(button).Text(timings...).Send()
}

func init() {
commands.LoadedPublic.Add(builder.NewCommand("stats").
Middleware(careerCommandMiddleware...).
Options(careerCommandOptions...).
Params(builder.SetDescKey("command_career_desc")).
Handler(careerCommandHandler))
commands.LoadedPublic.Add(builder.NewCommand("career").
Middleware(careerCommandMiddleware...).
Options(careerCommandOptions...).
Params(builder.SetNameKey("command_career_name"), builder.SetDescKey("command_career_desc")).
Handler(careerCommandHandler))
}
4 changes: 2 additions & 2 deletions cmd/discord/commands/public/interactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"golang.org/x/sync/errgroup"
"golang.org/x/text/language"

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

"github.com/cufee/aftermath/internal/log"
"github.com/pkg/errors"
Expand Down Expand Up @@ -315,7 +315,7 @@ func init() {
var image stats.Image
var meta stats.Metadata
switch interaction.EventID {
case "stats":
case "career", "stats":
img, mt, err := ctx.Core().Stats(ctx.Locale()).PeriodImage(context.Background(), ioptions.AccountID, ioptions.PeriodStart, opts...)
if errors.Is(err, blitzstars.ErrServiceUnavailable) {
return ctx.Reply().
Expand Down
10 changes: 5 additions & 5 deletions cmd/discord/commands/public/my.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/cufee/aftermath/internal/log"
"github.com/cufee/aftermath/internal/logic"
"github.com/cufee/aftermath/internal/permissions"
stats "github.com/cufee/aftermath/internal/stats/client/v1"
stats "github.com/cufee/aftermath/internal/stats/client/common"
"github.com/cufee/aftermath/internal/stats/fetch/v1"
"github.com/cufee/aftermath/internal/utils"
"github.com/pkg/errors"
Expand All @@ -27,8 +27,8 @@ func init() {
Middleware(middleware.RequirePermissions(permissions.UseTextCommands, permissions.UseImageCommands)).
Params(builder.SetNameKey("command_my_name"), builder.SetDescKey("command_my_description")).
Options(
builder.NewOption("stats", discordgo.ApplicationCommandOptionSubCommand).
Params(builder.SetNameKey("command_my_stats_name"), builder.SetDescKey("command_my_stats_description")).
builder.NewOption("career", discordgo.ApplicationCommandOptionSubCommand).
Params(builder.SetNameKey("command_my_career_name"), builder.SetDescKey("command_my_career_description")).
Options(
commands.DaysOption,
commands.VehicleOption,
Expand Down Expand Up @@ -85,7 +85,7 @@ func init() {
var err error
var image stats.Image
switch subcommand {
case "stats":
case "career":
image, _, err = ctx.Core().Stats(ctx.Locale()).PeriodImage(context.Background(), accountID, options.PeriodStart, opts...)
case "session":
image, _, err = ctx.Core().Stats(ctx.Locale()).SessionImage(context.Background(), accountID, options.PeriodStart, opts...)
Expand Down Expand Up @@ -120,7 +120,7 @@ func init() {
if err != nil {
return ctx.Err(err)
}
return ctx.Reply().File(buf.Bytes(), "session_command_by_aftermath.png").Component(button).Send()
return ctx.Reply().WithAds().File(buf.Bytes(), "session_command_by_aftermath.png").Component(button).Send()
}),
)
}
2 changes: 1 addition & 1 deletion cmd/discord/commands/public/replay.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/cufee/aftermath/cmd/discord/common"
"github.com/cufee/aftermath/cmd/discord/middleware"
"github.com/cufee/aftermath/internal/permissions"
stats "github.com/cufee/aftermath/internal/stats/client/v1"
stats "github.com/cufee/aftermath/internal/stats/client/common"
"github.com/cufee/aftermath/internal/stats/fetch/v1/replay"
"github.com/pkg/errors"
)
Expand Down
4 changes: 2 additions & 2 deletions cmd/discord/commands/public/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/cufee/aftermath/internal/log"
"github.com/cufee/aftermath/internal/logic"
"github.com/cufee/aftermath/internal/permissions"
stats "github.com/cufee/aftermath/internal/stats/client/v1"
stats "github.com/cufee/aftermath/internal/stats/client/common"
"github.com/cufee/aftermath/internal/stats/fetch/v1"
"github.com/cufee/aftermath/internal/utils"
"github.com/pkg/errors"
Expand All @@ -24,7 +24,7 @@ func init() {
commands.LoadedPublic.Add(
builder.NewCommand("session").
Middleware(middleware.RequirePermissions(permissions.UseTextCommands, permissions.UseImageCommands)).
Options(commands.DefaultStatsOptions...).
Options(commands.SessionStatsOptions...).
Handler(func(ctx common.Context) error {
options := commands.GetDefaultStatsOptions(ctx.Options())
message, valid := options.Validate(ctx)
Expand Down
Loading
Loading