tetrio

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2023 License: MIT Imports: 18 Imported by: 0

README

tetrio

Go Reference

TETR.IO API client library in Go.

Not all endpoints are implemented as I don't use most of them.


This is an unofficial project! not affiliated with osk or TETR.IO.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultClient = NewClient(nil)
View Source
var ErrAmbiguousRecord = errors.New("tetrio: record has no winner or loser")
View Source
var ErrNonMultiRecord = errors.New("tetrio: not a multiplayer record")

Functions

This section is empty.

Types

type Badge

type Badge struct {
	ID    string    `json:"id"`
	Label string    `json:"label"`
	TS    time.Time `json:"ts"`
}

type CacheInfo added in v1.0.0

type CacheInfo struct {
	At     CacheTime `json:"cached_at"`
	Until  CacheTime `json:"cached_until"`
	Status string    `json:"status"`
}

func (CacheInfo) Duration added in v1.0.0

func (c CacheInfo) Duration() time.Duration

type CacheTime

type CacheTime struct {
	time.Time
}

func (CacheTime) MarshalJSON added in v1.0.0

func (ct CacheTime) MarshalJSON() ([]byte, error)

func (*CacheTime) UnmarshalJSON

func (ct *CacheTime) UnmarshalJSON(data []byte) error

type Client added in v1.1.0

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

func NewClient added in v1.1.0

func NewClient(h *http.Client) *Client

func (*Client) GetCutoffs added in v1.1.0

func (c *Client) GetCutoffs(ctx context.Context) ([]RankRange, error)

func (*Client) GetLeagueLB added in v1.1.0

func (c *Client) GetLeagueLB(ctx context.Context, country string) ([]LeagueUser, error)

func (*Client) GetLeagueLBGlobal added in v1.1.0

func (c *Client) GetLeagueLBGlobal(ctx context.Context) ([]LeagueUser, error)

func (*Client) GetMatches added in v1.1.0

func (c *Client) GetMatches(ctx context.Context, userID string) ([]LeagueRecord, error)

func (*Client) GetUser added in v1.1.0

func (c *Client) GetUser(ctx context.Context, name string) (*FullUser, error)

func (*Client) SearchUser added in v1.1.0

func (c *Client) SearchUser(ctx context.Context, discordID string) (PartialUser, error)

func (*Client) Session added in v1.1.0

func (c *Client) Session() Session

type DiscordInfo

type DiscordInfo struct {
	ID       string `json:"id"`
	Username string `json:"username"`
}

type Error added in v1.0.0

type Error string // The API returns string errors so... not much can be done.

func (Error) Error added in v1.0.0

func (e Error) Error() string

type FullTLStats added in v1.0.0

type FullTLStats struct {
	PartialTLStats

	NextRank       string `json:"next_rank"`
	PrevRank       string `json:"prev_rank"`
	PercentileRank string `json:"percentile_rank"`

	StandingLocal int     `json:"standing_local"`
	NextAt        int     `json:"next_at"`
	PrevAt        int     `json:"prev_at"`
	Percentile    float64 `json:"percentile"`
}

type FullUser added in v1.0.0

type FullUser struct {
	LeagueUser
	League FullTLStats `json:"league"`

	TS        time.Time `json:"ts"`
	BotMaster string    `json:"botmaster"`
	Badges    []Badge   `json:"badges"`

	GamesPlayed int     `json:"gamesplayed"`
	GamesWon    int     `json:"gameswon"`
	GameTime    float64 `json:"gametime"`

	BadStanding   bool `json:"badstanding"`
	SupporterTier int  `json:"supporter_tier"`

	AvatarRevision int64 `json:"avatar_revision"`
	BannerRevision int64 `json:"banner_revision"`

	Bio         string `json:"bio"`
	FriendCount int    `json:"friend_count"`
	Connections struct {
		Discord DiscordInfo
	} `json:"connections"`
	Distinguishment struct {
		Type string
	} `json:"distinguishment"`
}

func GetUser

func GetUser(name string) (*FullUser, error)

type Handling

type Handling struct {
	ARR      float64 `json:"arr"`
	DAS      float64 `json:"das"`
	DCD      float64 `json:"dcd"`
	SDF      int     `json:"sdf"`
	SafeLock bool    `json:"safelock"`
	Cancel   bool    `json:"cancel"`
}

Handling is the in game handling settings.

type LeaguePlayer

type LeaguePlayer struct {
	User         PartialUser
	Wins         int
	Inputs       int
	PiecesPlaced int
	Handling     Handling
	Stats        VersusStats
	RoundStats   []VersusStats
}

type LeagueRecord added in v0.3.0

type LeagueRecord struct {
	ReplayID  string
	TS        time.Time
	IsForfeit bool
	Winner    LeaguePlayer
	Loser     LeaguePlayer
}

func GetMatches added in v1.0.0

func GetMatches(userID string) ([]LeagueRecord, error)

func (*LeagueRecord) UnmarshalJSON added in v0.3.0

func (g *LeagueRecord) UnmarshalJSON(data []byte) error

type LeagueUser added in v1.0.0

type LeagueUser struct {
	PartialUser

	Role      string         `json:"role"`
	XP        *float64       `json:"xp"`
	Country   *string        `json:"country"`
	Supporter bool           `json:"supporter"`
	Verified  *bool          `json:"verified"`
	League    PartialTLStats `json:"league"`
}

func GetLeagueLB added in v1.0.0

func GetLeagueLB(country string) ([]LeagueUser, error)

func GetLeagueLBGlobal added in v1.0.0

func GetLeagueLBGlobal() ([]LeagueUser, error)

type NoUserError added in v1.0.0

type NoUserError struct {
	UID string
	// contains filtered or unexported fields
}

func (NoUserError) Error added in v1.0.0

func (e NoUserError) Error() string

func (NoUserError) Unwrap added in v1.0.0

func (e NoUserError) Unwrap() error

type PartialTLStats added in v1.0.0

type PartialTLStats struct {
	// Standing isn't returned by the API for the TETRA LEAGUE leaderboard list.
	// It is filled in by the library.
	//
	// The #1 ranked player has Standing 1. (not 0)
	Standing int `json:"standing"`

	GamesPlayed int      `json:"gamesplayed"`
	GamesWon    int      `json:"gameswon"`
	Rating      float64  `json:"rating"`
	Rank        string   `json:"rank"`
	BestRank    *string  `json:"bestrank,omitempty"`
	Glicko      float64  `json:"glicko"`
	RD          float64  `json:"rd"`
	APM         float64  `json:"apm"`
	PPS         float64  `json:"pps"`
	VS          *float64 `json:"vs,omitempty"`
	Decaying    *bool    `json:"decaying,omitempty"`
}

type PartialUser

type PartialUser struct {
	ID       string `json:"_id"`
	Username string `json:"username"`
}

func SearchUser added in v1.0.0

func SearchUser(discordID string) (PartialUser, error)

type RankRange added in v1.0.0

type RankRange struct {
	Rank       string
	Percentile float64
	Top        *LeagueUser
	Bottom     *LeagueUser
}

func GetCutoffs added in v1.0.0

func GetCutoffs() ([]RankRange, error)

func (RankRange) Includes added in v1.0.0

func (r RankRange) Includes(TR float64) bool

Includes returns wheter TR is in range (Bottom, Top]

type Response added in v1.0.0

type Response struct {
	Success bool            `json:"success"`
	Error   json.RawMessage `json:"error"`
	Data    json.RawMessage `json:"data"`
	Cache   CacheInfo       `json:"cache"`
}

type Session added in v1.1.0

type Session struct {
	ID string
	// contains filtered or unexported fields
}

func (Session) GetCutoffs added in v1.1.0

func (s Session) GetCutoffs(ctx context.Context) ([]RankRange, error)

func (Session) GetLeagueLB added in v1.1.0

func (s Session) GetLeagueLB(ctx context.Context, country string) ([]LeagueUser, error)

func (Session) GetLeagueLBGlobal added in v1.1.0

func (s Session) GetLeagueLBGlobal(ctx context.Context) ([]LeagueUser, error)

func (Session) GetMatches added in v1.1.0

func (s Session) GetMatches(ctx context.Context, userID string) ([]LeagueRecord, error)

func (Session) GetUser added in v1.1.0

func (s Session) GetUser(ctx context.Context, name string) (*FullUser, error)

func (Session) SearchUser added in v1.1.0

func (s Session) SearchUser(ctx context.Context, discordID string) (PartialUser, error)

SearchUser returns the PartialUser that has their Discord account linked with TETR.IO. returns a zero PartialUser if no user is found.

type StatusError added in v1.0.0

type StatusError struct {
	Code    int
	Content []byte
}

func (StatusError) Error added in v1.0.0

func (e StatusError) Error() string

type TenchiDump added in v1.0.0

type TenchiDump struct {
	Success bool         `json:"success"`
	Users   []LeagueUser `json:"users"`
	TS      time.Time    `json:"ts"`
}

type UserSnapshot added in v1.0.0

type UserSnapshot struct {
	TS   time.Time  `json:"ts"`
	User LeagueUser `json:"user"`
}

type VersusStats

type VersusStats struct {
	APM float64 `json:"apm"` // Attacks per minute
	PPS float64 `json:"pps"` // Pieces per second
	VS  float64 `json:"vs"`  // Versus score
}

VersusStats is the statistics for multiplayer games.

Jump to

Keyboard shortcuts

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