resources

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2024 License: GPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IncorrectAnswer int = iota
	CorrectAnswer
	WarningAnswer // Not submitted, but weird behavior
	NeutralAnswer // Not submitted, but no warning
)

Answer Response types

View Source
const PUZZLE_URL = "https://adventofcode.com/%v/day/%v"

Base URL for a single day's puzzle

Variables

View Source
var UseHighPerformanceRenderer = true
View Source
var ViewportWidth = 80

Functions

func NewLeaderboardViewport

func NewLeaderboardViewport(content, title string)

func NewPuzzleViewport

func NewPuzzleViewport(puzzle *Puzzle)

Types

type Day

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

type DayLB

type DayLB struct {
	Year int
	Day  int

	BothStars []*Placing
	FirstStar []*Placing
}

DayLB is the model to handle a specific day's leaderboard

func NewDayLB

func NewDayLB(year, day int) *DayLB

NewDayLB creates a new leaderboard for a single day

func (*DayLB) GetContent

func (lb *DayLB) GetContent() string

GetContent will get the lb content in a printable format

func (*DayLB) GetTitle

func (l *DayLB) GetTitle() string

func (*DayLB) LoadPositions

func (lb *DayLB) LoadPositions() error

LoadPositions will get all of the daily positions

type LeaderboardModel

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

func (LeaderboardModel) Init

func (m LeaderboardModel) Init() tea.Cmd

func (LeaderboardModel) Update

func (m LeaderboardModel) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (LeaderboardModel) View

func (m LeaderboardModel) View() string

type LoadUserModel

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

LoadUserModel is the BubbleTea model for loading and displaying a user's information

func (LoadUserModel) Init

func (m LoadUserModel) Init() tea.Cmd

func (LoadUserModel) Update

func (m LoadUserModel) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (LoadUserModel) View

func (m LoadUserModel) View() string

type Placing

type Placing struct {
	DisplayName string
	UserID      string
	Position    int
	IsSupporter bool

	// UserLink is the link for the username
	UserLink string
	// SponsorLink is the link for the user's associated sponsor
	SponsorLink string

	// FinishTime is only used for daily leaderboards
	FinishTime string

	// Score is only used for yearly leaderboards
	Score int
}

Placing represents a single placing on a leaderboard

type Puzzle

type Puzzle struct {
	SessionToken string

	Day      int
	Year     int
	BucketID string
	URL      string

	Title      string
	ArticleOne []string
	AnswerOne  string
	ArticleTwo []string
	AnswerTwo  string

	UserInput   []byte
	Submissions map[int][]*Submission

	LockoutEnd time.Time
}

Puzzle represents a single day's puzzle. Consists of user info as well as page display info.

func LoadOrCreatePuzzle

func LoadOrCreatePuzzle(year int, day int, userSession string) *Puzzle

LoadOrCreatePuzzle attempts to load the requested puzzle from storage. If it's unable to be loaded, it will attempt to be created, loading the information from the website.

func (*Puzzle) Display

func (p *Puzzle) Display()

Displays the puzzle's page to the user

func (*Puzzle) GetBucketName

func (p *Puzzle) GetBucketName() string

func (*Puzzle) GetID

func (p *Puzzle) GetID() string

func (*Puzzle) GetPrettyPageData

func (p *Puzzle) GetPrettyPageData() []string

GetPrettyPageData parses the puzzle's stored information and displays it in a visually pleasing way.

func (*Puzzle) GetUserInput

func (p *Puzzle) GetUserInput() ([]byte, error)

GetUserInput returns the input for the associated puzzle.

func (*Puzzle) MarshalData

func (p *Puzzle) MarshalData() ([]byte, error)

func (*Puzzle) ReloadPuzzleData

func (p *Puzzle) ReloadPuzzleData() error

Reloads puzzle information from the server

func (*Puzzle) SaveResource

func (p *Puzzle) SaveResource()

func (*Puzzle) SubmitAnswer

func (p *Puzzle) SubmitAnswer(answer string, part int) (int, string)

SubmitAnswer takes an answer and a part to submit to. If no part is provided, it will be derived based on stored puzzle information.

type PuzzleModel

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

func (PuzzleModel) Init

func (m PuzzleModel) Init() tea.Cmd

func (PuzzleModel) Update

func (m PuzzleModel) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (PuzzleModel) View

func (m PuzzleModel) View() string

type Submission

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

func NewSubmission

func NewSubmission(data *http.Response, answer string) (*Submission, error)

type User

type User struct {
	DisplayName string
	NumStars    int
	Years       map[int][]*Puzzle
	SessionTok  string
}

User represents a session token and accompanying puzzles.

func NewUser

func NewUser(token string) (*User, error)

Creates a new user based on a provided session token. If none is provided, it'll be loaded from environment variable or from config file.

func (*User) Display

func (u *User) Display()

func (*User) GetToken

func (u *User) GetToken() string

GetToken returns the user's session token.

func (*User) LoadDisplayName

func (u *User) LoadDisplayName() string

func (*User) LoadUser

func (u *User) LoadUser()

func (*User) NewModel

func (u *User) NewModel() tea.Model

type Value

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

Possible submission value for a puzzle

func (Value) GetValue

func (v Value) GetValue() string

type ViewableLB

type ViewableLB interface {
	GetTitle() string
	GetContent() string
}

type Year

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

type YearLB

type YearLB struct {
	Year      int
	Positions []*Placing
}

YearLB is the model to handle the leaderboard for a year as a whole

func NewYearLB

func NewYearLB(year int) *YearLB

NewYearLB creates and returns a new whole-year leaderboard

func (*YearLB) GetContent

func (lb *YearLB) GetContent() string

GetContent will get the lb content in a printable format

func (*YearLB) GetTitle

func (l *YearLB) GetTitle() string

func (*YearLB) LoadPositions

func (lb *YearLB) LoadPositions() error

LoadPositions will get all of the yearly positions

Jump to

Keyboard shortcuts

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