utils

package
v0.0.0-...-4b256dd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 13, 2022 License: GPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CachePrefix       = "csgowtfd_"
	SideMetaCacheKey  = CachePrefix + "side_meta_%d"
	MatchChatCacheKey = CachePrefix + "chat_%d_%s"
)

Variables

View Source
var (
	SteamId64RegEx = regexp.MustCompile(`^\d{17}$`)
	ShareCodeRegEx = regexp.MustCompile(`^CSGO(?:-?[ABCDEFGHJKLMNOPQRSTUVWXYZabcdefhijkmnopqrstuvwxyz23456789]{5}){5}$`)
	AuthCodeRegEx  = regexp.MustCompile(`^[ABCDEFGHJKLMNOPQRSTUVWXYZ23456789]{4}-[ABCDEFGHJKLMNOPQRSTUVWXYZ23456789]{5}-[ABCDEFGHJKLMNOPQRSTUVWXYZ23456789]{4}$`)
)

Functions

func DeleteMatch

func DeleteMatch(matchDel *ent.Match, db *ent.Client) error

func GetNewShareCodesForPlayer

func GetNewShareCodesForPlayer(player *ent.Player, apiKey string, rl *rate.Limiter) ([]string, error)

func GetWinLossTieForPlayer

func GetWinLossTieForPlayer(dbPlayer *ent.Player) (wins int, looses int, ties int, err error)

func IsAuthCodeValid

func IsAuthCodeValid(player *ent.Player, apiKey string, shareCode string, authCode string, rl *rate.Limiter) (bool, error)

func Player

func Player(db *ent.Client, id interface{}, apiKey string, rl *rate.Limiter) (*ent.Player, error)

func PlayerFromSteam

func PlayerFromSteam(players []*ent.Player, db *ent.Client, apiKey string, rl *rate.Limiter) ([]*ent.Player, error)

func PlayerFromSteamID64

func PlayerFromSteamID64(db *ent.Client, steamID uint64, apiKey string, rl *rate.Limiter) (*ent.Player, error)

func PlayerFromVanityURL

func PlayerFromVanityURL(db *ent.Client, id string, apiKey string, rl *rate.Limiter) (*ent.Player, error)

func RealIP

func RealIP(header *http.Header, fallback string) string

func TranslateWithDeepL

func TranslateWithDeepL(text string, language string, baseURL string, apiKey string, timeout int) (translated string, detectedLanguage string, err error)

Types

type AuthcodeRateLimitError

type AuthcodeRateLimitError struct {
	// contains filtered or unexported fields
}

type AuthcodeUnauthorizedError

type AuthcodeUnauthorizedError struct {
	// contains filtered or unexported fields
}

type ChatResponse

type ChatResponse struct {
	Player         *PlayerResponse `json:"player,omitempty"`
	Message        string          `json:"message"`
	AllChat        bool            `json:"all_chat"`
	Tick           int             `json:"tick"`
	TranslatedFrom string          `json:"translated_from,omitempty"`
	TranslatedTo   string          `json:"translated_to,omitempty"`
}

type CommunityXML

type CommunityXML struct {
	SteamID64   uint64 `xml:"steamID64"`
	AvatarURL   string `xml:"avatarFull"`
	VacBanned   bool   `xml:"vacBanned"`
	ProfileName string `xml:"steamID"`
	Error       string `xml:"error"`
	VanityURL   string `xml:"customURL"`
}

type Conf

type Conf struct {
	Logging struct {
		Level string
	}
	Db struct {
		Driver    string
		ConnectTo string `yaml:"connect_to"`
	}
	Parser struct {
		Worker int
	}
	Steam struct {
		Username      string
		Password      string
		AuthCode      string  `yaml:"auth_code"`
		APIKey        string  `yaml:"api_key"`
		RatePerSecond float64 `yaml:"rate_per_sec"`
		Sentry        string
		LoginKey      string `yaml:"login_key"`
		MaxRetryWait  int    `yaml:"max_retry_wait"`
	}
	Redis struct {
		Address  string
		Password string
	}
	Httpd struct {
		CORSAllowDomains []string `yaml:"cors_allow_domains"`
		Listen           []struct {
			Socket string
			Host   string
			Port   int
		}
	}
	Csgowtfd struct {
		ProfileUpdate   string `yaml:"profile_update"`
		SharecodeUpdate string `yaml:"sharecode_update"`
		DemosExpire     int    `yaml:"demos_expire"`
		SprayTimeout    int    `yaml:"spray_timeout"`
		Timeout         struct {
			Read  int
			Write int
			Idle  int
		}
	}
	DeepL struct {
		BaseURL string `yaml:"base_url"`
		APIKey  string `yaml:"api_key"`
		Timeout int    `yaml:"timeout"`
	} `yaml:"deepl"`
}

type Damage

type Damage struct {
	Enemy uint `json:"enemy,omitempty"`
	Team  uint `json:"team,omitempty"`
}

type DeepLResponse

type DeepLResponse struct {
	Translations []struct {
		DetectedSourceLanguage string `json:"detected_source_language"`
		Text                   string `json:"text"`
	} `json:"translations"`
}

type Flash

type Flash struct {
	Duration *SelfTeamEnemy `json:"duration,omitempty"`
	Total    *SelfTeamEnemy `json:"total,omitempty"`
}

type MatchResponse

type MatchResponse struct {
	MatchId     uint64      `json:"match_id,string"`
	ShareCode   string      `json:"share_code,omitempty"`
	Map         string      `json:"map"`
	Date        int64       `json:"date"`
	Score       [2]int      `json:"score"`
	Duration    int         `json:"duration"`
	MatchResult int         `json:"match_result"`
	MaxRounds   int         `json:"max_rounds,omitempty"`
	Parsed      bool        `json:"parsed"`
	ReplayURL   string      `json:"replay_url,omitempty"`
	VAC         bool        `json:"vac"`
	GameBan     bool        `json:"game_ban"`
	Stats       interface{} `json:"stats,omitempty"`
	AvgRank     float64     `json:"avg_rank,omitempty"`
	TickRate    float64     `json:"tick_rate,omitempty"`
}

type MatchStats

type MatchStats struct {
	Win  int `json:"win,omitempty"`
	Tie  int `json:"tie,omitempty"`
	Loss int `json:"loss,omitempty"`
}

type MateResponse

type MateResponse struct {
	Player  *PlayerResponse `json:"player"`
	WinRate float32         `json:"win_rate,omitempty"`
	TieRate float32         `json:"tie_rate,omitempty"`
	Total   int             `json:"total,omitempty"`
}

type MetaStatsResponse

type MetaStatsResponse struct {
	Player    *PlayerResponse    `json:"player"`
	BestMates []*MateResponse    `json:"best_mates,omitempty"`
	MostMates []*MateResponse    `json:"most_mates,omitempty"`
	EqMap     map[int]string     `json:"eq_map,omitempty"`
	WeaponDmg []*WeaponDmg       `json:"weapon_dmg,omitempty"`
	WinMaps   map[string]float32 `json:"win_maps,omitempty"`
	TieMaps   map[string]float32 `json:"tie_maps,omitempty"`
	TotalMaps map[string]int     `json:"total_maps,omitempty"`
}

func GetMetaStats

func GetMetaStats(dbPlayer *ent.Player) (*MetaStatsResponse, error)

type MultiKills

type MultiKills struct {
	Duo    uint `json:"duo,omitempty"`
	Triple uint `json:"triple,omitempty"`
	Quad   uint `json:"quad,omitempty"`
	Pent   uint `json:"pent,omitempty"`
}

type PlayerResponse

type PlayerResponse struct {
	SteamID64   uint64           `json:"steamid64,string"`
	Name        string           `json:"name,omitempty"`
	Avatar      string           `json:"avatar,omitempty"`
	VAC         bool             `json:"vac"`
	VACDate     int64            `json:"vac_date,omitempty"`
	GameBan     bool             `json:"game_ban"`
	GameBanDate int64            `json:"game_ban_date,omitempty"`
	Tracked     bool             `json:"tracked"`
	VanityURL   string           `json:"vanity_url,omitempty"`
	MatchStats  *MatchStats      `json:"match_stats,omitempty"`
	Matches     []*MatchResponse `json:"matches,omitempty"`
}

type Rank

type Rank struct {
	Old int `json:"old,omitempty"`
	New int `json:"new,omitempty"`
}

type SelfTeamEnemy

type SelfTeamEnemy struct {
	Self  interface{} `json:"self,omitempty"`
	Team  interface{} `json:"team,omitempty"`
	Enemy interface{} `json:"enemy,omitempty"`
}

type ShareCodeResponse

type ShareCodeResponse struct {
	Result struct {
		Code string `json:"nextcode"`
	} `json:"result"`
}

type SharecodeNoMatchError

type SharecodeNoMatchError struct {
	// contains filtered or unexported fields
}

type StatsResponse

type StatsResponse struct {
	TeamID     int         `json:"team_id"`
	Kills      int         `json:"kills"`
	Deaths     int         `json:"deaths"`
	Assists    int         `json:"assists"`
	Headshot   int         `json:"headshot"`
	MVP        uint        `json:"mvp"`
	Score      int         `json:"score"`
	Player     interface{} `json:"player,omitempty"`
	Rank       *Rank       `json:"rank,omitempty"`
	MultiKills *MultiKills `json:"multi_kills,omitempty"`
	Dmg        *Damage     `json:"dmg,omitempty"`
	Flash      *Flash      `json:"flash,omitempty"`
	Crosshair  string      `json:"crosshair,omitempty"`
	Color      string      `json:"color,omitempty"`
	KAST       int         `json:"kast,omitempty"`
}

type WeaponDmg

type WeaponDmg struct {
	Eq  int  `json:"eq"`
	Dmg uint `json:"dmg"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL