diff --git a/go.mod b/go.mod index ef3bf4f..05ed9f4 100644 --- a/go.mod +++ b/go.mod @@ -26,6 +26,7 @@ require ( github.com/charmbracelet/x/input v0.1.3 // indirect github.com/charmbracelet/x/term v0.1.1 // indirect github.com/charmbracelet/x/windows v0.1.2 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect github.com/go-logfmt/logfmt v0.6.0 // indirect github.com/lucasb-eyer/go-colorful v1.2.0 // indirect @@ -35,11 +36,14 @@ require ( github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect github.com/muesli/cancelreader v0.2.2 // indirect github.com/muesli/termenv v0.15.2 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect github.com/rivo/uniseg v0.4.7 // indirect + github.com/stretchr/testify v1.9.0 // indirect github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa // indirect golang.org/x/net v0.28.0 // indirect golang.org/x/sync v0.8.0 // indirect golang.org/x/sys v0.24.0 // indirect golang.org/x/text v0.17.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 4e9c1d9..af62c7c 100644 --- a/go.sum +++ b/go.sum @@ -103,5 +103,6 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/internal/resources/Puzzle.go b/internal/resources/Puzzle.go index 8610545..2fe20bd 100644 --- a/internal/resources/Puzzle.go +++ b/internal/resources/Puzzle.go @@ -10,6 +10,7 @@ import ( "dalton.dog/aocgo/internal/api" "dalton.dog/aocgo/internal/cache" + "dalton.dog/aocgo/internal/utils" "github.com/PuerkitoBio/goquery" "github.com/charmbracelet/lipgloss" @@ -74,6 +75,10 @@ const ( ) func (p *Puzzle) SubmitAnswer(answer string) (int, string) { + if !time.Now().After(p.LockoutEnd) { + return WarningAnswer, fmt.Sprintf("Still within lockout period of last submission. Lockout End: %s", p.LockoutEnd.Format(time.Stamp)) + } + var part int if p.AnswerOne == "" { part = 1 @@ -84,9 +89,7 @@ func (p *Puzzle) SubmitAnswer(answer string) (int, string) { } // TODO: Check past submissions and lockout period before allowing submission - // - Lockout period // - Past submissions - // - Equal to // - Too high / too low for _, pastSub := range p.Submissions[part] { @@ -118,6 +121,7 @@ func (p *Puzzle) SubmitAnswer(answer string) (int, string) { p.Submissions[part] = outList if submission.correct { + p.ReloadPage() if p.AnswerOne == "" { p.AnswerOne = answer @@ -126,8 +130,15 @@ func (p *Puzzle) SubmitAnswer(answer string) (int, string) { p.AnswerTwo = answer return CorrectAnswer, "Second star obtained! That's all for today, good luck tomorrow!" } + } else { // TODO: Parse the response message for lockout period + lockoutDuration, err := utils.ParseDuration(submission.message) + if err != nil { + return IncorrectAnswer, submission.message + "\nUnable to parse lockout duration from message." + } + + p.LockoutEnd = time.Now().Add(lockoutDuration) return IncorrectAnswer, submission.message }