Documentation
¶
Overview ¶
Package integration is for integrating the chess game engine into slack callbacks
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuthStorage ¶
type AuthStorage interface {
StoreAuthToken(ID string, token string) error
GetAuthToken(ID string) (string, error)
}
AuthStorage interface guarentees implemented mmethods for oauth token storage
type ChallengeCommand ¶
type ChallengeCommand struct {
ChallengedID string
}
ChallengeCommand represents a challenge to propose
type CommandMatch ¶
type CommandMatch struct {
Type CommandType
MatchedPattern *CommandPattern
Params []string
}
CommandMatch represents a matched command pattern with parsed parameters.
func (*CommandMatch) ToChallenge ¶
func (c *CommandMatch) ToChallenge() (*ChallengeCommand, error)
ToChallenge converts this command match to a proper challenge command
func (*CommandMatch) ToMove ¶
func (c *CommandMatch) ToMove() (*MoveCommand, error)
ToMove converts this command match to a proper move command
type CommandParser ¶
type CommandParser struct {
// contains filtered or unexported fields
}
CommandParser will parse and return a CommandMatch.
func NewCommandParser ¶
func NewCommandParser(patterns []CommandPattern) CommandParser
NewCommandParser gets a new instance operating on provided CommandMap.
func (*CommandParser) ParseInput ¶
func (c *CommandParser) ParseInput(input string) CommandMatch
ParseInput will attempt to match a command. An unknown command will still match with a type of Unknown
type CommandPattern ¶
type CommandPattern struct {
Type CommandType
Pattern *regexp.Regexp
}
CommandPattern maps a regular expression pattern to a specific command type.
type CommandType ¶
type CommandType uint8
CommandType is the kind of command a user wishes to execute.
const ( // Unknown represents a command that isn't represented in the enum. Unknown CommandType = iota + 1 // Challenge represents a challenge command for initiating a chess match. Challenge // Move represents a specific move by a player. Move // Resign represents a player's intention of resignation. Resign // Takeback represents a player's request to take back a previous move. Takeback // Help represents a player's need for help (UI or otherwise). Help )
type MemoryStore ¶
type MemoryStore struct {
// contains filtered or unexported fields
}
MemoryStore implements the Auth storage interfaces and holds all state in memory Once the MemoryStore instance is released, all data in that storage is lost
func NewMemoryStore ¶
func NewMemoryStore() *MemoryStore
NewMemoryStore returns a MemoryStore pointer
func (*MemoryStore) GetAuthToken ¶
func (m *MemoryStore) GetAuthToken(teamID string) (string, error)
GetAuthToken retrieves an oauth token for use with slack given a team ID
func (*MemoryStore) StoreAuthToken ¶
func (m *MemoryStore) StoreAuthToken(teamID string, oauthToken string) error
StoreAuthToken stores the oauth token granted by slack user for a given team ID
type MoveCommand ¶
type MoveCommand struct {
LAN string
}
MoveCommand represents a single long algebraic notation move.
type SlackActionHandler ¶
type SlackActionHandler struct {
SigningKey string
Hostname string
SlackClient *slack.Client
AuthStorage AuthStorage
GameStorage game.GameStorage
ChallengeStorage game.ChallengeStorage
TakebackStorage game.TakebackStorage
LinkRenderer rendering.RenderLink
}
SlackActionHandler will respond to all Slack integration component requests
func (SlackActionHandler) HandleChallenge ¶
func (s SlackActionHandler) HandleChallenge(w http.ResponseWriter, event slackevents.MessageAction)
HandleChallenge does the necessary operations for action responses to player challenges.
func (SlackActionHandler) HandleTakeback ¶
func (s SlackActionHandler) HandleTakeback(w http.ResponseWriter, event slackevents.MessageAction)
HandleTakeback performs necessary operations for action responses to player takeback requests.
func (SlackActionHandler) ServeHTTP ¶
func (s SlackActionHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type SlackHandler ¶
type SlackHandler struct {
SigningKey string
Hostname string
SlackClient *slack.Client
AuthStorage AuthStorage
GameStorage game.GameStorage
ChallengeStorage game.ChallengeStorage
TakebackStorage game.TakebackStorage
LinkRenderer rendering.RenderLink
}
SlackHandler will respond to all Slack event callback subscriptions
func (SlackHandler) ServeHTTP ¶
func (s SlackHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type SlackOauthHandler ¶
type SlackOauthHandler struct {
SlackClientID string
SlackClientSecret string
SlackAppID string
AuthStore AuthStorage
}
SlackOauthHandler will respond to all Slack authorization callbacks
func (SlackOauthHandler) ServeHTTP ¶
func (s SlackOauthHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type SqliteStore ¶
type SqliteStore struct {
// contains filtered or unexported fields
}
SqliteStore is an implementation of GameStorage and ChallengeStorage interfaces that persists using sqlite3
func NewSqliteStore ¶
func NewSqliteStore(path string) (*SqliteStore, error)
NewSqliteStore creates (if not exists) the DB file and structure at the path specified It implements the AuthStorage interface and is intended as a suitable perminent storage of oauth tokens
func NewSqliteStoreWithDB ¶
func NewSqliteStoreWithDB(db *sql.DB) (*SqliteStore, error)
NewSqliteStoreWithDB creates the auth table structure using an existing *sql.DB connection. This avoids opening a second connection pool to the same SQLite file.
func (*SqliteStore) GetAuthToken ¶
func (s *SqliteStore) GetAuthToken(teamID string) (string, error)
GetAuthToken retrieves an oauth token for use with slack given a team ID
func (*SqliteStore) StoreAuthToken ¶
func (s *SqliteStore) StoreAuthToken(teamID string, oauthToken string) error
StoreAuthToken stores the oauth token granted by slack user for a given team ID