api

package
v0.0.0-...-c5bc949 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2023 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HostUrl  string = "https://lichess.org"
	ClientID string = "chess-cli"
	AuthURL  string = HostUrl + "/oauth"
	TokenURL string = HostUrl + "/api/token"
)

Variables

View Source
var (
	UserInfo                = UserConfig{ApiToken: "", TokenCreationDate: time.Now(), TokenExpirationDate: time.Now().AddDate(1, 0, 0)}
	StreamEventStarted bool = false
	Online             bool = false
	Scopes                  = []string{
		"preference:read",
		"preference:write",
		"email:read",
		"challenge:read",
		"challenge:write",
		"challenge:bulk",
		"study:read",
		"study:write",
		"puzzle:read",
		"follow:read",
		"follow:write",
		"msg:write",
		"bot:play",
		"board:play",
	}
)

Functions

func AbortGame

func AbortGame(gameid string) error

func AcceptChallenge

func AcceptChallenge(gameid string) error

func AuthUser

func AuthUser() (string, error)

func CreateAiChallenge

func CreateAiChallenge(challenge CreateChallengeType) (error, string)

func CreateChallenge

func CreateChallenge(challenge CreateChallengeType) (error, string)

create a challenge against a specific user or get the url (POST)

func CreateSeek

func CreateSeek(challenge CreateChallengeType) error

func GetChallenges

func GetChallenges() ([]ChallengeInfo, []ChallengeInfo, error)

func GetEmail

func GetEmail() (string, error)

get user email

func GetFriends

func GetFriends() ([]string, error)

application/x-ndjson list of friends(and their online/offline status), to be displayed on challenge screen

func GetUsername

func GetUsername() (string, error)

get username from profile json

func HandleDraw

func HandleDraw(gameid string, accept bool) error

func HandleTakeback

func HandleTakeback(gameid string, accept bool) error

func MakeMove

func MakeMove(gameid string, move string) error

create a challenge against a specific user or get the url

func PerformOAuth

func PerformOAuth() (string, error)

func ResignGame

func ResignGame(gameid string) error

func StreamBoardState

func StreamBoardState(EventChannel chan<- BoardEvent, StreamError chan<- error, game string)

https://lichess.org/api/board/game/stream/{gameId} after initializing a game, this function streams the the state of the board of the game

func StreamEvent

func StreamEvent(EventChannel chan<- StreamEventType, got_token chan struct{}) error

starts event stream for a user after login

func TimeCheck

func TimeCheck()

Types

type BoardEvent

type BoardEvent struct {
	Type   BoardEventEnum
	Full   StreamBoardGameFull
	State  StreamBoardGameState
	Chat   StreamBoardChat
	Resign StreamBoardResign
}

type BoardEventEnum

type BoardEventEnum int
const (
	GameFull BoardEventEnum = iota
	GameState
	ChatLine
	ChatLineSpectator
	GameStateResign
	EOF
)

type ChallengeInfo

type ChallengeInfo struct {
	ID          string `json:"id"`
	URL         string `json:"url"`
	Color       string `json:"color"`
	Direction   string `json:"direction"`
	TimeControl struct {
		Increment int    `json:"increment"`
		Limit     int    `json:"limit"`
		Show      string `json:"show"`
		Type      string `json:"type"`
	} `json:"timeControl"`
	Variant struct {
		Key   string `json:"key"`
		Name  string `json:"name"`
		Short string `json:"short"`
	} `json:"variant"`
	Challenger struct {
		ID          string `json:"id"`
		Name        string `json:"name"`
		Online      bool   `json:"online"`
		Provisional bool   `json:"provisional"`
		Rating      int    `json:"rating"`
		Title       string `json:"title"`
	} `json:"challenger"`
	DestUser struct {
		ID          string `json:"id"`
		Name        string `json:"name"`
		Online      bool   `json:"online"`
		Provisional bool   `json:"provisional"`
		Rating      int    `json:"rating"`
		Title       string `json:"title"`
	} `json:"destUser"`
	Perf struct {
		Icon string `json:"icon"`
		Name string `json:"name"`
	} `json:"perf"`
	Rated  bool   `json:"rated"`
	Speed  string `json:"speed"`
	Status string `json:"status"`
}

https://lichess.org/api#operation/challengeList

type CreateChallengeType

type CreateChallengeType struct {
	Type           int
	DestUser       string
	Variant        string
	VariantIndex   int
	TimeOption     int
	ClockLimit     string
	ClockIncrement string
	Days           string
	Rated          string
	RatedBool      bool
	Color          string
	ColorIndex     int
	MinTurn        float64
	OpenEnded      bool
	Level          string
}

type OngoingGameInfo

type OngoingGameInfo struct {
	GameID   string `json:"gameId"`
	FullID   string `json:"fullId"`
	Color    string `json:"color"`
	Fen      string `json:"fen"`
	HasMoved bool   `json:"hasMoved"`
	IsMyTurn bool   `json:"isMyTurn"`
	LastMove string `json:"lastMove"`
	Opponent struct {
		ID       string `json:"id"`
		Rating   int    `json:"rating"`
		Username string `json:"username"`
	} `json:"opponent"`
	Perf        string `json:"perf"`
	Rated       bool   `json:"rated"`
	SecondsLeft int    `json:"secondsLeft"`
	Source      string `json:"source"`
	Speed       string `json:"speed"`
	Variant     struct {
		Key  string `json:"key"`
		Name string `json:"name"`
	} `json:"variant"`
}

https://lichess.org/api#operation/apiAccountPlaying

func GetOngoingGames

func GetOngoingGames() ([]OngoingGameInfo, error)

type StreamBoardChat

type StreamBoardChat struct {
	Type     string `json:"type"`
	Username string `json:"username"`
	Text     string `json:"text"`
	Room     string `json:"room"`
}

https://lichess.org/api#operation/boardGameStream

type StreamBoardGameFull

type StreamBoardGameFull struct {
	Type    string `json:"type"`
	ID      string `json:"id"`
	Rated   bool   `json:"rated"`
	Variant struct {
		Key   string `json:"key"`
		Name  string `json:"name"`
		Short string `json:"short"`
	} `json:"variant"`
	Clock struct {
		Initial   int `json:"initial"`
		Increment int `json:"increment"`
	} `json:"clock"`
	Speed string `json:"speed"`
	Perf  struct {
		Name string `json:"name"`
	} `json:"perf"`
	CreatedAt int64 `json:"createdAt"`
	White     struct {
		ID          string `json:"id"`
		Name        string `json:"name"`
		Provisional bool   `json:"provisional"`
		Rating      int    `json:"rating"`
		Title       string `json:"title"`
	} `json:"white"`
	Black struct {
		ID     string      `json:"id"`
		Name   string      `json:"name"`
		Rating int         `json:"rating"`
		Title  interface{} `json:"title"`
	} `json:"black"`
	InitialFen string `json:"initialFen"`
	State      struct {
		Type   string `json:"type"`
		Moves  string `json:"moves"`
		Wtime  int    `json:"wtime"`
		Btime  int    `json:"btime"`
		Winc   int    `json:"winc"`
		Binc   int    `json:"binc"`
		Status string `json:"status"`
	} `json:"state"`
}

https://lichess.org/api#operation/boardGameStream

type StreamBoardGameState

type StreamBoardGameState struct {
	Type      string `json:"type"`
	Moves     string `json:"moves"`
	Wtime     int    `json:"wtime"`
	Btime     int    `json:"btime"`
	Winc      int    `json:"winc"`
	Binc      int    `json:"binc"`
	Status    string `json:"status"`
	Winner    string `json:"winner"`
	Wdraw     bool   `json:"wdraw"`
	Bdraw     bool   `json:"bdraw"`
	Wtakeback bool   `json:"wtakeback"`
	Btakeback bool   `json:"btakeback"`
}

https://lichess.org/api#operation/boardGameStream

type StreamBoardResign

type StreamBoardResign struct {
	Type   string `json:"type"`
	Moves  string `json:"moves"`
	Wtime  int    `json:"wtime"`
	Btime  int    `json:"btime"`
	Winc   int    `json:"winc"`
	Binc   int    `json:"binc"`
	Status string `json:"status"`
	Winner string `json:"winner"`
}

https://lichess.org/api#operation/boardGameStream

type StreamEventChallenge

type StreamEventChallenge struct {
	Type      string `json:"type"`
	Challenge struct {
		ID     string `json:"id"`
		URL    string `json:"url"`
		Status string `json:"status"`
		Compat struct {
			Bot   bool `json:"bot"`
			Board bool `json:"board"`
		} `json:"compat"`
		Challenger struct {
			ID     string `json:"id"`
			Name   string `json:"name"`
			Title  string `json:"title"`
			Rating int    `json:"rating"`
			Patron bool   `json:"patron"`
			Online bool   `json:"online"`
			Lag    int    `json:"lag"`
		} `json:"challenger"`
		DestUser struct {
			ID          string      `json:"id"`
			Name        string      `json:"name"`
			Title       interface{} `json:"title"`
			Rating      int         `json:"rating"`
			Provisional bool        `json:"provisional"`
			Online      bool        `json:"online"`
			Lag         int         `json:"lag"`
		} `json:"destUser"`
		Variant struct {
			Key   string `json:"key"`
			Name  string `json:"name"`
			Short string `json:"short"`
		} `json:"variant"`
		Rated       bool `json:"rated"`
		TimeControl struct {
			Type      string `json:"type"`
			Limit     int    `json:"limit"`
			Increment int    `json:"increment"`
			Show      string `json:"show"`
		} `json:"timeControl"`
		Color string `json:"color"`
		Speed string `json:"speed"`
		Perf  struct {
			Icon string `json:"icon"`
			Name string `json:"name"`
		} `json:"perf"`
	} `json:"challenge"`
}

https://lichess.org/api#operation/apiStreamEvent

type StreamEventGame

type StreamEventGame struct {
	Type string `json:"type"`
	Game struct {
		GameID   string `json:"gameId"`
		FullID   string `json:"fullId"`
		Color    string `json:"color"`
		Fen      string `json:"fen"`
		HasMoved bool   `json:"hasMoved"`
		IsMyTurn bool   `json:"isMyTurn"`
		LastMove string `json:"lastMove"`
		Opponent struct {
			ID       string `json:"id"`
			Rating   int    `json:"rating"`
			Username string `json:"username"`
		} `json:"opponent"`
		Perf        string `json:"perf"`
		Rated       bool   `json:"rated"`
		SecondsLeft int    `json:"secondsLeft"`
		Source      string `json:"source"`
		Speed       string `json:"speed"`
		Variant     struct {
			Key  string `json:"key"`
			Name string `json:"name"`
		} `json:"variant"`
		Compat struct {
			Bot   bool `json:"bot"`
			Board bool `json:"board"`
		} `json:"compat"`
	} `json:"game"`
}

https://lichess.org/api#operation/apiStreamEvent

type StreamEventType

type StreamEventType struct {
	EventType string
	GameID    string
	Source    string
}

type UserConfig

type UserConfig struct {
	ApiToken            string
	TokenCreationDate   time.Time
	TokenExpirationDate time.Time
}

type for storing user info into a json

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳