update to new go-steam version
This commit is contained in:
@@ -3,17 +3,22 @@ package utils
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/an0nfunc/go-steamapi"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"golang.org/x/time/rate"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"github.com/an0nfunc/go-steamapi"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"golang.org/x/time/rate"
|
||||
"somegit.dev/csgowtf/csgowtfd/ent"
|
||||
"somegit.dev/csgowtf/csgowtfd/ent/match"
|
||||
"somegit.dev/csgowtf/csgowtfd/ent/matchplayer"
|
||||
@@ -21,10 +26,6 @@ import (
|
||||
"somegit.dev/csgowtf/csgowtfd/ent/roundstats"
|
||||
"somegit.dev/csgowtf/csgowtfd/ent/spray"
|
||||
"somegit.dev/csgowtf/csgowtfd/ent/weapon"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Conf struct {
|
||||
@@ -544,7 +545,7 @@ func GetNewShareCodesForPlayer(tPlayer *ent.Player, apiKey string, rl *rate.Limi
|
||||
|
||||
func getNextShareCode(lastCode, apiKey, authCode string, steamID uint64, rl *rate.Limiter) (*string, error) {
|
||||
if lastCode == "" || apiKey == "" || authCode == "" || steamID == 0 {
|
||||
return nil, fmt.Errorf("invalid arguments")
|
||||
return nil, errors.New("invalid arguments")
|
||||
}
|
||||
|
||||
if rl != nil {
|
||||
@@ -607,13 +608,13 @@ func Player(db *ent.Client, id interface{}, apiKey string, rl *rate.Limiter) (*e
|
||||
|
||||
return PlayerFromVanityURL(db, e, apiKey, rl)
|
||||
default:
|
||||
return nil, fmt.Errorf("invalid arguments")
|
||||
return nil, errors.New("invalid arguments")
|
||||
}
|
||||
}
|
||||
|
||||
func PlayerFromVanityURL(db *ent.Client, id, apiKey string, rl *rate.Limiter) (*ent.Player, error) {
|
||||
if id == "" {
|
||||
return nil, fmt.Errorf("invalid arguments")
|
||||
return nil, errors.New("invalid arguments")
|
||||
}
|
||||
|
||||
tPlayer, err := db.Player.Query().Where(player.VanityURL(strings.ToLower(id))).Only(context.Background())
|
||||
@@ -627,7 +628,7 @@ func PlayerFromVanityURL(db *ent.Client, id, apiKey string, rl *rate.Limiter) (*
|
||||
}
|
||||
|
||||
if resp.Success != 1 {
|
||||
return nil, fmt.Errorf("vanity url not found")
|
||||
return nil, errors.New("vanity url not found")
|
||||
}
|
||||
|
||||
nPlayer, err := PlayerFromSteamID64(db, resp.SteamID, apiKey, rl)
|
||||
@@ -717,36 +718,36 @@ func PlayerFromSteam(players []*ent.Player, db *ent.Client, apiKey string, rl *r
|
||||
|
||||
// TODO: what happens if a player deleted their profile?
|
||||
var nPlayers []*ent.Player //nolint:prealloc
|
||||
for _, pS := range playerSum {
|
||||
for i := range playerSum {
|
||||
// check for vanityURL
|
||||
if SteamID64RegEx.MatchString(path.Base(pS.ProfileURL)) {
|
||||
pS.ProfileURL = ""
|
||||
if SteamID64RegEx.MatchString(path.Base(playerSum[i].ProfileURL)) {
|
||||
playerSum[i].ProfileURL = ""
|
||||
} else {
|
||||
pS.ProfileURL = path.Base(pS.ProfileURL)
|
||||
playerSum[i].ProfileURL = path.Base(playerSum[i].ProfileURL)
|
||||
}
|
||||
|
||||
var tPlayer *ent.Player
|
||||
if db != nil {
|
||||
tPlayer, err = db.Player.UpdateOneID(pS.SteamID).
|
||||
SetName(pS.PersonaName).
|
||||
SetAvatar(pS.AvatarHash).
|
||||
SetVanityURL(strings.ToLower(pS.ProfileURL)).
|
||||
SetVanityURLReal(pS.ProfileURL).
|
||||
tPlayer, err = db.Player.UpdateOneID(playerSum[i].SteamID).
|
||||
SetName(playerSum[i].PersonaName).
|
||||
SetAvatar(playerSum[i].AvatarHash).
|
||||
SetVanityURL(strings.ToLower(playerSum[i].ProfileURL)).
|
||||
SetVanityURLReal(playerSum[i].ProfileURL).
|
||||
SetSteamUpdated(time.Now().UTC()).
|
||||
SetProfileCreated(time.Unix(pS.TimeCreated, 0).UTC()).
|
||||
SetProfileCreated(time.Unix(playerSum[i].TimeCreated, 0).UTC()).
|
||||
Save(context.Background())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
tPlayer = &ent.Player{
|
||||
ID: pS.SteamID,
|
||||
Name: pS.PersonaName,
|
||||
Avatar: pS.AvatarHash,
|
||||
VanityURL: strings.ToLower(pS.ProfileURL),
|
||||
VanityURLReal: pS.ProfileURL,
|
||||
ID: playerSum[i].SteamID,
|
||||
Name: playerSum[i].PersonaName,
|
||||
Avatar: playerSum[i].AvatarHash,
|
||||
VanityURL: strings.ToLower(playerSum[i].ProfileURL),
|
||||
VanityURLReal: playerSum[i].ProfileURL,
|
||||
SteamUpdated: time.Now().UTC(),
|
||||
ProfileCreated: time.Unix(pS.TimeCreated, 0),
|
||||
ProfileCreated: time.Unix(playerSum[i].TimeCreated, 0),
|
||||
}
|
||||
}
|
||||
nPlayers = append(nPlayers, tPlayer)
|
||||
|
||||
Reference in New Issue
Block a user