Add player profiles and community settings
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -4,9 +4,11 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -63,6 +65,7 @@ type Player struct {
|
||||
ID string `json:"id"`
|
||||
AccountID string `json:"accountId"`
|
||||
DisplayName string `json:"displayName"`
|
||||
BattleTag string `json:"battleTag"`
|
||||
Ratings Ratings `json:"ratings"`
|
||||
PreferredRoles []Role `json:"preferredRoles"`
|
||||
PreferredPlayerIDs []string `json:"preferredPlayerIds"`
|
||||
@@ -71,6 +74,21 @@ type Player struct {
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
}
|
||||
|
||||
var battleTagPattern = regexp.MustCompile(`^[^#\s]{2,20}#[0-9]{3,12}$`)
|
||||
|
||||
func (p *Player) ValidateIdentity() error {
|
||||
p.DisplayName = strings.TrimSpace(p.DisplayName)
|
||||
length := utf8.RuneCountInString(p.DisplayName)
|
||||
if length < 2 || length > 32 {
|
||||
return fmt.Errorf("%w: display name must contain 2 to 32 characters", ErrInvalid)
|
||||
}
|
||||
p.BattleTag = strings.TrimSpace(p.BattleTag)
|
||||
if p.BattleTag != "" && !battleTagPattern.MatchString(p.BattleTag) {
|
||||
return fmt.Errorf("%w: BattleTag must have the form Name#digits", ErrInvalid)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p Player) ValidatePreferences() error {
|
||||
if len(p.PreferredPlayerIDs) > 3 {
|
||||
return fmt.Errorf("%w: at most three preferred teammates are allowed", ErrInvalid)
|
||||
|
||||
Reference in New Issue
Block a user