From 6c7742cdf2fe8f88763ade126eebc105c8852258 Mon Sep 17 00:00:00 2001 From: Brian Buller Date: Mon, 4 Nov 2024 16:44:20 -0600 Subject: [PATCH] Session Stuff --- aoc.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/aoc.go b/aoc.go index 14032e2..8a1bee6 100644 --- a/aoc.go +++ b/aoc.go @@ -13,6 +13,8 @@ type AoC struct { session string boardId string boards map[int]*Leaderboard + + sessionErr bool } func NewAoC(boardId, session string) (*AoC, error) { @@ -29,6 +31,12 @@ func NewAoC(boardId, session string) (*AoC, error) { }, nil } +func (a *AoC) SetSession(session string) { + a.session = session + a.sessionErr = false +} +func (a *AoC) NeedsNewSession() bool { return a.sessionErr } + func (a *AoC) SetCachedLeaderboard(l *Leaderboard) error { yr, err := strconv.Atoi(l.Event) if err != nil { @@ -53,6 +61,9 @@ func (a *AoC) GetLeaderboard(year int) (*Leaderboard, error) { if year < 2015 || year > time.Now().Year() { return nil, new(InvalidYearError) } + if a.sessionErr { + return nil, new(SessionError) + } if board, ok := a.boards[year]; ok { if time.Since(board.LastFetch) < (time.Minute * 15) { return board, nil @@ -62,6 +73,7 @@ func (a *AoC) GetLeaderboard(year int) (*Leaderboard, error) { a.boards[year], err = a.fetchLeaderboard(year) if err != nil { if err.Error() == "invalid character '<' looking for beginning of value" { + a.sessionErr = true return nil, new(SessionError) } return nil, err