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 Dockerfile.collector
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:latest AS builder-go
FROM golang:1.26.0 AS builder-go

WORKDIR /workspace

Expand Down
7 changes: 2 additions & 5 deletions cmd/core/server/handlers/private/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func LoadAccountsHandler(client core.Client) http.HandlerFunc {
return
}

w.Write([]byte(fmt.Sprintf("working on %d accounts", len(accounts)-len(existing))))
w.Write(fmt.Appendf(nil, "working on %d accounts", len(accounts)-len(existing)))
log.Debug().Int("count", len(accounts)-len(existing)).Msg("importing accounts")

go func(accounts []string, existing []models.Account) {
Expand Down Expand Up @@ -64,10 +64,7 @@ func LoadAccountsHandler(client core.Client) http.HandlerFunc {
sem := semaphore.NewWeighted(5)
for realm, accounts := range accountsByRealm {
for i := 0; i < len(accounts); i += batchSize {
end := i + batchSize
if end > len(accounts) {
end = len(accounts)
}
end := min(i+batchSize, len(accounts))

wg.Add(1)
go func(accounts []string, realm types.Realm) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/discord/commands/builder/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (c Builder) Build() Command {
NameLocalizations: &nameLocalized,
DescriptionLocalizations: &descLocalized,
Options: options,
DMPermission: common.Pointer(!c.guildOnly),
DMPermission: new(!c.guildOnly),
Type: discordgo.ChatApplicationCommand,
IntegrationTypes: c.integrationTypes,
Contexts: c.interactionContexts,
Expand Down
8 changes: 4 additions & 4 deletions cmd/discord/commands/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ func GetDefaultStatsOptions(data []*discordgo.ApplicationCommandInteractionDataO
var options StatsOptions

options.TankSearch, _ = common.GetOption[string](data, "tank")
if strings.HasPrefix(options.TankSearch, "valid#vehicle#") {
options.TankID = strings.TrimPrefix(options.TankSearch, "valid#vehicle#")
if after, ok := strings.CutPrefix(options.TankSearch, "valid#vehicle#"); ok {
options.TankID = after
}

tier, ok := common.GetOption[float64](data, "tier")
Expand All @@ -99,8 +99,8 @@ func GetDefaultStatsOptions(data []*discordgo.ApplicationCommandInteractionDataO
}

options.NicknameSearch, _ = common.GetOption[string](data, "nickname")
if strings.HasPrefix(options.NicknameSearch, "valid#account#") {
data := strings.Split(strings.TrimPrefix(options.NicknameSearch, "valid#account#"), "#")
if after, ok0 := strings.CutPrefix(options.NicknameSearch, "valid#account#"); ok0 {
data := strings.Split(after, "#")
if len(data) == 2 {
options.Realm = types.Realm(data[1])
options.AccountID = data[0]
Expand Down
5 changes: 2 additions & 3 deletions cmd/discord/commands/public/career.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/cufee/aftermath/internal/permissions"
stats "github.com/cufee/aftermath/internal/stats/client/common"
"github.com/cufee/aftermath/internal/stats/fetch/v1"
"github.com/cufee/aftermath/internal/utils"
)

var (
Expand Down Expand Up @@ -51,7 +50,7 @@ func careerCommandHandler(ctx common.Context) error {
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))
defaultAccount, hasDefaultAccount := mentionedUser.Connection(models.ConnectionTypeWargaming, nil, new(true))
if !hasDefaultAccount {
return ctx.Reply().IsError(common.UserError).Send("stats_error_connection_not_found_vague")
}
Expand Down Expand Up @@ -98,7 +97,7 @@ func careerCommandHandler(ctx common.Context) error {
accountID = fmt.Sprint(accounts[0].ID)

default:
defaultAccount, hasDefaultAccount := ctx.User().Connection(models.ConnectionTypeWargaming, nil, utils.Pointer(true))
defaultAccount, hasDefaultAccount := ctx.User().Connection(models.ConnectionTypeWargaming, nil, new(true))
if !hasDefaultAccount {
return ctx.Reply().Send("command_career_help_message")
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/discord/commands/public/my.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/cufee/aftermath/internal/permissions"
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 Down Expand Up @@ -85,7 +84,7 @@ func init() {
if len(parts) == 4 && parts[0] == "valid" {
accountID = parts[1]
} else {
defaultAccount, hasDefaultAccount := ctx.User().Connection(models.ConnectionTypeWargaming, nil, utils.Pointer(true))
defaultAccount, hasDefaultAccount := ctx.User().Connection(models.ConnectionTypeWargaming, nil, new(true))
if !hasDefaultAccount {
return ctx.Reply().IsError(common.UserError).Send("my_error_no_account_linked")
}
Expand Down
5 changes: 2 additions & 3 deletions cmd/discord/commands/public/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/cufee/aftermath/internal/permissions"
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 Down Expand Up @@ -51,7 +50,7 @@ func init() {
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))
defaultAccount, hasDefaultAccount := mentionedUser.Connection(models.ConnectionTypeWargaming, nil, new(true))
if !hasDefaultAccount {
return ctx.Reply().IsError(common.UserError).Send("stats_error_connection_not_found_vague")
}
Expand Down Expand Up @@ -98,7 +97,7 @@ func init() {
accountID = fmt.Sprint(accounts[0].ID)

default:
defaultAccount, hasDefaultAccount := ctx.User().Connection(models.ConnectionTypeWargaming, nil, utils.Pointer(true))
defaultAccount, hasDefaultAccount := ctx.User().Connection(models.ConnectionTypeWargaming, nil, new(true))
if !hasDefaultAccount {
return ctx.Reply().Send("command_session_help_message")
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/discord/commands/public/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/cufee/aftermath/internal/constants"
"github.com/cufee/aftermath/internal/database/models"
"github.com/cufee/aftermath/internal/permissions"
"github.com/cufee/aftermath/internal/utils"
)

func init() {
Expand All @@ -32,7 +31,7 @@ func init() {
if len(parts) == 4 && parts[0] == "valid" {
accountID = parts[1]
} else {
defaultAccount, hasDefaultAccount := ctx.User().Connection(models.ConnectionTypeWargaming, nil, utils.Pointer(true))
defaultAccount, hasDefaultAccount := ctx.User().Connection(models.ConnectionTypeWargaming, nil, new(true))
if !hasDefaultAccount {
return ctx.Reply().Format("commands_widget_message_fmt", constants.FrontendURL+"/widget/").Send()
}
Expand Down
5 changes: 0 additions & 5 deletions cmd/discord/common/pointer.go

This file was deleted.

5 changes: 2 additions & 3 deletions cmd/discord/common/reply.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package common
import (
"context"
"fmt"
"maps"
"strings"
"time"

Expand Down Expand Up @@ -79,9 +80,7 @@ func (r Reply) Metadata() map[string]any {

func (r Reply) WithMeta(data map[string]any) Reply {
meta := r.Metadata()
for key, value := range data {
meta[key] = value
}
maps.Copy(meta, data)
return r
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/discord/gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type Client interface {

Connect() error
Disconnect() error
Handler(fn interface{})
Handler(fn any)
SetStatus(status status, text string, emoji *discordgo.Emoji) error
}

Expand Down Expand Up @@ -72,7 +72,7 @@ func (c *gatewayClient) Rest() *rest.Client {
return c.rest
}

func (c *gatewayClient) Handler(fn interface{}) {
func (c *gatewayClient) Handler(fn any) {
c.manager.AddHandler(fn)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/discord/router/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func (r *router) handleInteraction(ctx context.Context, interaction discordgo.In

func sendPingReply(w http.ResponseWriter) {
w.WriteHeader(http.StatusOK)
_, err := w.Write([]byte(fmt.Sprintf(`{"type": %d}`, discordgo.InteractionPing)))
_, err := w.Write(fmt.Appendf(nil, `{"type": %d}`, discordgo.InteractionPing))
if err != nil {
log.Err(err).Msg("failed to reply to a discord PING")
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
Expand Down
4 changes: 2 additions & 2 deletions cmd/frontend/handler/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,15 @@ func (ctx *Context) Error(format string, args ...any) error {
}

func (ctx *Context) String(format string, args ...any) error {
_, err := ctx.w.Write([]byte(fmt.Sprintf(format, args...)))
_, err := ctx.w.Write(fmt.Appendf(nil, format, args...))
return err
}

func (ctx *Context) JSON(data any) error {
ctx.w.Header().Set("Content-Type", "application/json")
err := json.NewEncoder(ctx.w).Encode(data)
if err != nil {
ctx.w.Write([]byte(fmt.Sprintf(`{"error":"%s"}`, err.Error())))
ctx.w.Write(fmt.Appendf(nil, `{"error":"%s"}`, err.Error()))
}
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/frontend/logic/scripts.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/tdewolff/minify/v2/js"
)

func EmbedScript(script templ.ComponentScript, params ...interface{}) templ.Component {
func EmbedScript(script templ.ComponentScript, params ...any) templ.Component {
return templ.ComponentFunc(func(ctx context.Context, w io.Writer) (err error) {
if _, err = io.WriteString(w, `<script type="text/javascript">`+"\r\n"+script.Function+"\r\n"+script.Name+"("); err != nil {
return err
Expand Down Expand Up @@ -41,7 +41,7 @@ func EmbedScript(script templ.ComponentScript, params ...interface{}) templ.Comp

var m = minify.New()

func EmbedMinifiedScript(script templ.ComponentScript, params ...interface{}) templ.Component {
func EmbedMinifiedScript(script templ.ComponentScript, params ...any) templ.Component {
r := bytes.NewReader([]byte(script.Function))
w := bytes.NewBuffer(nil)
err := js.Minify(m, w, r, nil)
Expand Down
2 changes: 1 addition & 1 deletion cmd/frontend/routes/api/widget/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (p *widgetSettingsPayload) parse(values url.Values) {

if formValues, ok := values[formTag]; ok && len(formValues) > 0 {
switch field.Kind() {
case reflect.Ptr:
case reflect.Pointer:
switch fieldType.Type.Elem().Kind() {
case reflect.String:
strVal := formValues[0]
Expand Down
3 changes: 1 addition & 2 deletions cmd/frontend/routes/app/index.templ
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/cufee/aftermath/internal/constants"
"github.com/cufee/aftermath/internal/database"
"github.com/cufee/aftermath/internal/database/models"
"github.com/cufee/aftermath/internal/utils"
"net/http"
"slices"
)
Expand Down Expand Up @@ -64,7 +63,7 @@ var Index handler.Page = func(ctx *handler.Context) (handler.Layout, templ.Compo
}
}
}
defaultConn, _ := user.Connection(models.ConnectionTypeWargaming, nil, utils.Pointer(true))
defaultConn, _ := user.Connection(models.ConnectionTypeWargaming, nil, new(true))

return layouts.Main, index(connections, defaultConn.ID, 3, widgets, constants.WidgetAccountLimit), nil
}
Expand Down
Loading
Loading