state

package
v0.0.0-...-51943a4 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateRound

func ValidateRound(r Round) error

Types

type Client

type Client struct {
	// Important: to avoid deadlocks, do not send to this channel while holding
	// the lock below.
	DiscoveryChange chan bool
	PuzzleChange    chan PuzzleChange
	RoundChange     chan RoundChange
	// contains filtered or unexported fields
}

func New

func New(ctx context.Context, path string) *Client

func (*Client) ClearPuzzleVoiceRoom

func (c *Client) ClearPuzzleVoiceRoom(ctx context.Context, room string) error

func (*Client) CompleteDiscoveredPuzzle

func (c *Client) CompleteDiscoveredPuzzle(ctx context.Context, id int64) error

func (*Client) CompleteDiscoveredRound

func (c *Client) CompleteDiscoveredRound(ctx context.Context, id int64, round Round) error

func (*Client) CreateDiscoveredPuzzle

func (c *Client) CreateDiscoveredPuzzle(ctx context.Context, puzzle db.CreateDiscoveredPuzzleParams) error

func (*Client) CreateDiscoveredRound

func (c *Client) CreateDiscoveredRound(ctx context.Context, round string) (int64, error)

func (*Client) CreatePuzzle

func (c *Client) CreatePuzzle(ctx context.Context, puzzle RawPuzzle) (Puzzle, int64, error)

func (*Client) CreateRound

func (c *Client) CreateRound(ctx context.Context, round Round) (Round, int64, error)

func (*Client) DeletePuzzle

func (c *Client) DeletePuzzle(ctx context.Context, id int64) (int64, error)

func (*Client) DeleteRound

func (c *Client) DeleteRound(ctx context.Context, id int64) (int64, error)

func (*Client) DiscoveryConfig

func (c *Client) DiscoveryConfig(ctx context.Context) (DiscoveryConfig, error)

func (*Client) EnableDiscovery

func (c *Client) EnableDiscovery(ctx context.Context, enabled bool) bool

func (*Client) GetCreatedRound

func (c *Client) GetCreatedRound(ctx context.Context, name string) (Round, error)

func (*Client) GetDiscoveredRound

func (c *Client) GetDiscoveredRound(ctx context.Context, name string) (db.DiscoveredRound, error)

func (*Client) GetPuzzle

func (c *Client) GetPuzzle(ctx context.Context, id int64) (Puzzle, error)

func (*Client) GetPuzzleByChannel

func (c *Client) GetPuzzleByChannel(ctx context.Context, channel string) (Puzzle, error)

func (*Client) GetRound

func (c *Client) GetRound(ctx context.Context, id int64) (Round, error)

func (*Client) IncrementSyncEpoch

func (c *Client) IncrementSyncEpoch(ctx context.Context) (int64, error)

func (*Client) IsEnabled

func (c *Client) IsEnabled(ctx context.Context) bool

func (*Client) IsPuzzleCreated

func (c *Client) IsPuzzleCreated(ctx context.Context, puzzle ScrapedPuzzle) (bool, error)

func (*Client) IsPuzzleDiscovered

func (c *Client) IsPuzzleDiscovered(ctx context.Context, puzzle ScrapedPuzzle) (bool, error)

func (*Client) ListCreatablePuzzles

func (c *Client) ListCreatablePuzzles(ctx context.Context) ([]db.ListCreatablePuzzlesRow, error)

func (*Client) ListDiscoveredPuzzlesForRound

func (c *Client) ListDiscoveredPuzzlesForRound(ctx context.Context, id int64) ([]db.DiscoveredPuzzle, error)

func (*Client) ListHome

func (c *Client) ListHome(ctx context.Context) ([]Puzzle, []Round, int64, error)

func (*Client) ListPendingDiscoveredRounds

func (c *Client) ListPendingDiscoveredRounds(ctx context.Context) ([]db.DiscoveredRound, error)

func (*Client) ListPuzzles

func (c *Client) ListPuzzles(ctx context.Context) ([]Puzzle, error)

func (*Client) ListRounds

func (c *Client) ListRounds(ctx context.Context) ([]Round, error)

func (*Client) ListVoiceRoomInfo

func (c *Client) ListVoiceRoomInfo(ctx context.Context) ([]VoiceInfo, error)

func (*Client) ReminderTimestamp

func (c *Client) ReminderTimestamp(ctx context.Context) (time.Time, error)

func (*Client) SetReminderTimestamp

func (c *Client) SetReminderTimestamp(ctx context.Context, reminder time.Time) error

func (*Client) UpdateDiscoveredRound

func (c *Client) UpdateDiscoveredRound(ctx context.Context, round db.DiscoveredRound) error

func (*Client) UpdateDiscoveryConfig

func (c *Client) UpdateDiscoveryConfig(ctx context.Context,
	mutate func(config *DiscoveryConfig) error) (DiscoveryConfig, error)

func (*Client) UpdatePuzzle

func (c *Client) UpdatePuzzle(ctx context.Context, id int64,
	mutate func(puzzle *RawPuzzle) error) (Puzzle, int64, error)

func (*Client) UpdatePuzzleByDiscordChannel

func (c *Client) UpdatePuzzleByDiscordChannel(ctx context.Context, channel string,
	mutate func(puzzle *RawPuzzle) error) (PuzzleChange, error)

func (*Client) UpdateRound

func (c *Client) UpdateRound(ctx context.Context, id int64,
	mutate func(round *Round) error) (Round, int64, error)

func (*Client) ValidatePuzzle

func (c *Client) ValidatePuzzle(ctx context.Context, p RawPuzzle) error

type DiscoveryConfig

type DiscoveryConfig struct {
	// URL of the "All Puzzles" page on the hunt website
	PuzzlesURL  string `json:"puzzles_url"`
	CookieName  string `json:"cookie_name"`
	CookieValue string `json:"cookie_value"`

	// Group Mode: in many years (2021, 2020, etc.), the puzzle list is grouped
	// by round, and there is some grouping element (e.g. a <section>) for each
	// round that contains both the round name and the list of puzzles.
	//
	// In other years (2022), the puzzle list is presented as a sequence of
	// alternating round names (e.g. <h2>) and puzzle lists (e.g. <table>) with
	// no grouping element. If this is the case, set `groupedMode=false` and use
	// the group selector to select the overall container. Note that the round
	// name element must be an *immediate* child of the container, and the
	// puzzle list element must be its immediate sibling.
	//
	// EXAMPLES
	//
	// 2022 (https://puzzles.mit.edu/2022/puzzles/)
	// - Group:       `section#main-content` (group mode off)
	// - Round Name:  `h2`
	// - Puzzle List: `table`
	//
	// 2021 (https://puzzles.mit.edu/2021/puzzles.html)
	// - Group:       `.info div section` (group mode on)
	// - Round Name:  `a h3`
	// - Puzzle List: `table`
	//
	// 2020 (https://puzzles.mit.edu/2020/puzzles/)
	// - Group:       `#loplist > li:not(:first-child)` (group mode on)
	// - Round Name:  `a`
	// - Puzzle List: `ul li a`
	//
	// 2019 (https://puzzles.mit.edu/2019/puzzle.html)
	// - Group:       `.puzzle-list-section:nth-child(2) .round-list-item` (group mode on)
	// - Round Name:  `.round-list-header`
	// - Puzzle List: `.round-list-item`
	// - Puzzle Item: `.puzzle-list-item a`
	//
	GroupMode          bool   `json:"group_mode"`
	GroupSelector      string `json:"group_selector"`
	RoundNameSelector  string `json:"round_name_selector"`
	PuzzleListSelector string `json:"puzzle_list_selector"`

	// Optional: defaults to "a" (this is probably what you want)
	PuzzleItemSelector string `json:"puzzle_item_selector"`

	// URL of the websocket endpoint (optional)
	WebsocketURL string `json:"websocket_url"`

	// Token to send in the AUTH message (optional)
	WebsocketToken string `json:"websocket_token"`
}

type Puzzle

type Puzzle struct {
	ID             int64         `json:"id"`
	Name           string        `json:"name"`
	Answer         string        `json:"answer"`
	Round          Round         `json:"round"`
	Status         status.Status `json:"status"`
	Note           string        `json:"note"`
	Location       string        `json:"location"`
	PuzzleURL      string        `json:"puzzle_url"`
	SpreadsheetID  string        `json:"spreadsheet_id"`
	DiscordChannel string        `json:"discord_channel"`
	Meta           bool          `json:"meta"`
	VoiceRoom      string        `json:"voice_room"`
	Reminder       time.Time     `json:"reminder"`
}

Must match db.GetPuzzleRow and db.ListPuzzlesRow

func (Puzzle) HasReminder

func (p Puzzle) HasReminder() bool

func (Puzzle) RawPuzzle

func (p Puzzle) RawPuzzle() RawPuzzle

type PuzzleChange

type PuzzleChange struct {
	Before   *Puzzle
	After    *Puzzle
	ChangeID int64

	// An optional channel to notify on completion. Only set when called from a
	// bot command.
	BotComplete chan error
}

type RawPuzzle

type RawPuzzle = db.Puzzle

type Round

type Round = db.Round

type RoundChange

type RoundChange struct {
	Before   *Round
	After    *Round
	ChangeID int64
}

type ScrapedPuzzle

type ScrapedPuzzle struct {
	Name      string `json:"name"`
	RoundName string `json:"round_name"`
	PuzzleURL string `json:"puzzle_url"`
}

type ScrapedRound

type ScrapedRound struct {
	MessageID  string
	Name       string
	NotifiedAt time.Time
	Puzzles    []ScrapedPuzzle
}

type ValidationError

type ValidationError struct {
	Field   string
	Message string
}

func (ValidationError) Error

func (e ValidationError) Error() string

type VoiceInfo

type VoiceInfo = db.ListPuzzlesByVoiceRoomRow

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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