Documentation ¶
Index ¶
- Variables
- func AddAnswer(pool *redis.Pool, registry *pubsub.Registry) http.HandlerFunc
- func ForceErrorDuringPuzzleLoad(t *testing.T, err error)
- func ForceErrorDuringSettingsLoad(t *testing.T, err error)
- func ForceErrorDuringSettingsSave(t *testing.T, err error)
- func ForceErrorDuringStateLoad(t *testing.T, err error)
- func ForceErrorDuringStateSave(t *testing.T, err error)
- func ForcePuzzleToBeLoaded(t *testing.T, filename string)
- func GetAllChannels(conn redis.Conn) ([]model.Channel, error)
- func GetEvents(pool *redis.Pool, registry *pubsub.Registry) http.HandlerFunc
- func InferLetters(words []string) (string, []string, error)
- func NewEventSubscription(t *testing.T, registry *pubsub.Registry, channel string) <-chan pubsub.Event
- func NewRedisConnection(t *testing.T, pool *redis.Pool) redis.Conn
- func NewTestRouter(t *testing.T) (chi.Router, *redis.Pool, *pubsub.Registry)
- func RegisterRoutes(router chi.Router, pool *redis.Pool)
- func RegisterRoutesWithRegistry(r chi.Router, pool *redis.Pool, registry *pubsub.Registry)
- func SetSettings(conn redis.Conn, channel string, settings Settings) error
- func SetState(conn redis.Conn, channel string, state State) error
- func SettingsKey(name string) string
- func ShuffleLetters(pool *redis.Pool, registry *pubsub.Registry) http.HandlerFunc
- func StateKey(name string) string
- func ToggleStatus(pool *redis.Pool, registry *pubsub.Registry) http.HandlerFunc
- func UpdatePuzzle(pool *redis.Pool, registry *pubsub.Registry) http.HandlerFunc
- func UpdateSetting(pool *redis.Pool, registry *pubsub.Registry) http.HandlerFunc
- type Puzzle
- type Settings
- type State
Constants ¶
This section is empty.
Variables ¶
var StateTTL = 4 * time.Hour
StateTTL determines how long a particular crossword's solve state should remain in redis in the absence of any activity.
Functions ¶
func ForceErrorDuringPuzzleLoad ¶
ForceErrorDuringLoad sets up an error to be returned when an attempt is made to load a puzzle.
func ForceErrorDuringSettingsLoad ¶
ForceErrorDuringSettingsLoad sets up an error to be returned when an attempt is made to load settings.
func ForceErrorDuringSettingsSave ¶
ForceErrorDuringSettingsSave sets up an error to be returned when an attempt is made to save settings.
func ForceErrorDuringStateLoad ¶
ForceErrorDuringStateLoad sets up an error to be returned when an attempt is made to load state.
func ForceErrorDuringStateSave ¶
ForceErrorDuringStateSave sets up an error to be returned when an attempt is made to save state.
func ForcePuzzleToBeLoaded ¶
ForcePuzzleToBeLoaded sets up a cached version of a puzzle using a file from the testdata directory.
func GetAllChannels ¶
GetAllChannels returns a slice of model.Channel instances for each spelling bee that contains state in the database. If there are no active channels then an empty slice is returned. This method does not update the expiration times of any state instance.
func GetEvents ¶
GetEvents establishes an event stream with a client. An event stream is server side event stream (SSE) with a client's browser that allows one way communication from the server to the client. Clients that call into this handler will keep an open connection open to the server waiting to receive events as JSON objects. The server can send events to all clients of a channel using the pubsub.Registry's Publish method.
func InferLetters ¶
InferLetters looks at the list of words and determines which letter is the center letter (because it's used in every word) and which letters are the surrounding letters. If for some reason the letters can't be inferred then an error will be returned.
func NewEventSubscription ¶
func NewEventSubscription(t *testing.T, registry *pubsub.Registry, channel string) <-chan pubsub.Event
NewEventSubscription will return a channel of events that are subscribed to the specified channel. The subscription will be configured to automatically unsubscribe when the test completes.
func NewRedisConnection ¶
NewRedisConnection will return a connection to the provided connection pool. The returned connection will be configured to automatically close when the test completes.
func NewTestRouter ¶
NewTestRouter will return a router configured with a redis pool and pubsub registry and wired together along with all of the routes for a spelling bee puzzle.
func SetSettings ¶
SetSettings will write settings for the provided channel name. If the settings can't be properly written then an error will be returned.
func SetState ¶
SetState writes the state for a channel's spelling bee solve to redis. If the state can't be property written then an error will be returned.
func SettingsKey ¶
SettingsKey returns the key that should be used in redis to store a particular channel's settings.
func ShuffleLetters ¶
ShuffleLetters changes the order of the letters in the puzzle.
func StateKey ¶
StateKey returns the key that should be used in redis to store a particular spelling bee solve's state.
func ToggleStatus ¶
ToggleStatus changes the status of the current puzzle solve to a new status. This effectively toggles between the solving and paused statuses as long as the solve is in a state that can be paused or resumed.
func UpdatePuzzle ¶
UpdatePuzzle changes the spelling bee puzzle that's currently being solved for a channel.
func UpdateSetting ¶
UpdateSetting changes a specified spelling bee setting to a new value.
Types ¶
type Puzzle ¶
type Puzzle struct { // The date that the spelling bee puzzle was published. PublishedDate time.Time `json:"published"` // The center letter of the spelling bee puzzle. This letter must be used in // every answer. CenterLetter string `json:"center"` // The non-center letters in the spelling bee puzzle. Each entry will // always be a single letter long and there will always be 6 entries. Letters []string `json:"letters"` // The list of official answers from The New York Times. OfficialAnswers []string `json:"official_answers,omitempty"` // The list of unofficial answers from NYTBee.com. UnofficialAnswers []string `json:"unofficial_answers,omitempty"` }
Puzzle represents a spelling bee puzzle. The puzzle is comprised of a circular grid of 6 letters around a single letter. The goal is to use the letters to make words that all use the center letter and have length 4 or greater. Letters may be reused.
func InferPuzzle ¶
InferPuzzle looks at the list of words and determines the puzzle structure from them. In addition it verifies that the provided words have a valid structure for the puzzle.
func LoadFromNYTBee ¶
LoadFromNYTBee loads a spelling bee puzzle from the NYTBee website for a particular date.
This method loads the HTML of the spelling bee page for a desired date and parses it to obtain the answer list(s) from it.
If the puzzle cannot be loaded or the HTML properly parsed then an error is returned.
func LoadTestPuzzle ¶
LoadTestPuzzle loads a puzzle from the testdata directory.
func ParseNYTBeeResponse ¶
ParseNYTBeeResponse converts an HTML page from nytbee.com into a puzzle object.
func (*Puzzle) WithoutAnswers ¶
WithoutAnswers returns a copy of the puzzle that has the answers removed. This makes the resulting puzzle suitable to pass to a client that shouldn't know the answers to the puzzle.
type Settings ¶
type Settings struct { // When enabled unofficial answers will be allowed. AllowUnofficialAnswers bool `json:"allow_unofficial_answers"` // What font size words should be rendered with. FontSize model.FontSize `json:"font_size"` }
Settings represents the optional behaviors that can be enabled or disabled by a streamer for their channel's spelling bee solves.
type State ¶
type State struct { // The status of the channel's solve. Status model.Status `json:"status"` // The spelling bee puzzle that's being solved. May not always be present, // for example when the state is being serialized to be sent to the browser. Puzzle *Puzzle `json:"puzzle,omitempty"` // The current order of the letters of the puzzle, not including the first // letter. Letters []string `json:"letters"` // The currently discovered words the puzzle. Words []string `json:"words"` // The current score of the solve. Score int `json:"score"` // The time that we last started or resumed solving the puzzle. If the // channel has not yet started solving the puzzle or is in a non-playing state // this will be nil. LastStartTime *time.Time `json:"last_start_time,omitempty"` // The total time spent on solving the puzzle up to the last start time. TotalSolveDuration model.Duration `json:"total_solve_duration"` }
State represents the state of an active channel that is attempting to solve a spelling bee puzzle.
func GetState ¶
GetState loads the state for a spelling bee solve from redis. If the state can't be loaded then an error will be returned. If there is no state, then the zero value will be returned. After a state is read, its expiration time is automatically updated.
func NewState ¶
NewState creates a new spelling bee puzzle state that has been properly initialized with the puzzle corresponding to the provided filename.
func (*State) ApplyAnswer ¶
ApplyAnswer applies an answer to the state. If the answer cannot be applied or is incorrect then an error is returned.
func (*State) ClearUnofficialAnswers ¶
func (s *State) ClearUnofficialAnswers()
ClearUnofficialAnswers goes through all of the provided answers for a puzzle and removes any that are on the unofficial answers list.