Documentation ¶
Index ¶
- Variables
- func Abs(x int) int
- func BindRoutes(karmaGroup *gin.RouterGroup, knaveGroup *gin.RouterGroup, karmaHandler Handler)
- func InitDB(dataSourceName string) (*sql.DB, error)
- func IsoDate(t time.Time) string
- func MsgGiveKarma(callee, target string, delta int) string
- func MsgOverDailyLimit(limit, usage, remainder int) string
- func MsgTakeKarma(callee, target string, delta int) string
- func MsgTopKarma(topUsers []UserKarma) string
- func MsgUserDailyLimit(usage, remaining int) string
- func MsgUserStatus(userID string, k int) string
- func MsgUserStatusTarget(callee, target string) string
- type Command
- type DAO
- type Handler
- type MockDAO
- func (m MockDAO) DeleteKarma(team, user string) (int, error)
- func (m MockDAO) GetDaily(team, user string, date time.Time) (int, error)
- func (m MockDAO) GetKarma(team, user string) (int, error)
- func (m MockDAO) Top(team string, n int) ([]UserKarma, error)
- func (m MockDAO) UpdateDaily(team, user string, date time.Time, karma int) (int, error)
- func (m MockDAO) UpdateKarma(team, user string, delta int) (int, error)
- func (m MockDAO) UpdateKarmaDaily(team, callee, target string, delta int, date time.Time) (int, error)
- func (m MockDAO) Usage(d slack.CommandData, r slack.Response) error
- type ProcConfig
- type Processor
- type SQLiteDAO
- func (dao SQLiteDAO) DeleteKarma(team, user string) (int, error)
- func (dao SQLiteDAO) GetDaily(team, user string, date time.Time) (int, error)
- func (dao SQLiteDAO) GetKarma(team, user string) (int, error)
- func (dao SQLiteDAO) Top(team string, n int) ([]UserKarma, error)
- func (dao SQLiteDAO) UpdateDaily(team, user string, date time.Time, karma int) (int, error)
- func (dao SQLiteDAO) UpdateKarma(workspace, user string, delta int) (int, error)
- func (dao SQLiteDAO) UpdateKarmaDaily(team, callee, target string, delta int, date time.Time) (int, error)
- func (dao SQLiteDAO) Usage(data slack.CommandData, res slack.Response) error
- type SQLiteHandler
- type SlackProcessor
- type UserKarma
Constants ¶
This section is empty.
Variables ¶
var Commands = map[string]struct{}{ // contains filtered or unexported fields }
Commands a set of the support commands by this processor
var ResponseHelp = slack.Response{ ResponseType: slack.ResponseType.Ephemeral, Text: "", Attachments: []slack.Attachments{ { Fallback: "*Help* Helpful information on how to manage karma.", Title: "Helpful information on how to manage karma.", Text: "Below are the sub-commands:", Fields: []slack.Field{ { Title: cmdMe, Value: "Return your karma and daily usage limits.", Short: true, }, { Title: cmdStatus, Value: "Provide a @user and return their karma.", Short: true, }, { Title: cmdAdd, Value: "Provide a @user and increase their karma. Optionally, pass a quantity of karma to give.", Short: true, }, { Title: cmdSub, Value: "Provide a @user and decrease their karma. Optionally, pass a quantity of karma to take.", Short: true, }, { Title: cmdTop, Value: "Return the top 3 users by karma. Optionally, pass a quantity for the top n users", Short: true, }, { Title: cmdHelp, Value: "This helpful dialogue. You're welcome!", Short: true, }, }, }, }, }
ResponseHelp the slack response for the HELP command
Functions ¶
func BindRoutes ¶
func BindRoutes(karmaGroup *gin.RouterGroup, knaveGroup *gin.RouterGroup, karmaHandler Handler)
BindRoutes bind handlers to router
func MsgGiveKarma ¶
MsgGiveKarma announces who gave how much karma to whom
func MsgOverDailyLimit ¶
MsgOverDailyLimit generates daily limit error message (string)
func MsgTakeKarma ¶
MsgTakeKarma announces who took how much karma from whom
func MsgTopKarma ¶
MsgTopKarma table for viewing top users by karma
func MsgUserDailyLimit ¶
MsgUserDailyLimit the remaining daily limits
func MsgUserStatus ¶
MsgUserStatus the User's Karma status
func MsgUserStatusTarget ¶
MsgUserStatusTarget lets all users know who requested karma totals
Types ¶
type DAO ¶
type DAO interface { GetKarma(team, user string) (int, error) UpdateKarma(team, user string, delta int) (int, error) DeleteKarma(team, user string) (int, error) Top(team string, n int) ([]UserKarma, error) Usage(slack.CommandData, slack.Response) error GetDaily(team, user string, date time.Time) (int, error) UpdateDaily(team, user string, date time.Time, karma int) (int, error) UpdateKarmaDaily(team, callee, target string, delta int, date time.Time) (int, error) }
DAO Data Access Object for the Karma database
type Handler ¶
type Handler interface { GetKarma(c *gin.Context) AddKarma(c *gin.Context) DelKarma(c *gin.Context) SlashKarma(c *gin.Context) TopKarma(c *gin.Context) }
Handler interface for Karma handler
type MockDAO ¶
type MockDAO struct { GetKarmaMock func(team, user string) (int, error) UpdateKarmaMock func(team, user string, delta int) (int, error) DeleteKarmaMock func(team, user string) (int, error) UsageMock func(slack.CommandData, slack.Response) error TopMock func(team string, n int) ([]UserKarma, error) GetDailyMock func(team, user string, date time.Time) (int, error) UpdateDailyMock func(team, user string, date time.Time, karma int) (int, error) UpdateKarmaDailyMock func(team, callee, target string, delta int, date time.Time) (int, error) }
MockDAO a mock dao for karma whose mock functions can be monkeypatched
func FullDailyDao ¶
func FullDailyDao() MockDAO
FullDailyDao factory method for a mock dao were all users are full on their daily limit
func HappyDao ¶
func HappyDao() MockDAO
HappyDao factory method for a mock dao that will always succeed
func NewMockDao ¶
NewMockDao constructor func for making mock dao
func SadDao ¶
func SadDao() MockDAO
SadDao factory method for a mock dao that will always fail with an error
func (MockDAO) DeleteKarma ¶
DeleteKarma .
func (MockDAO) UpdateDaily ¶
UpdateDaily .
func (MockDAO) UpdateKarma ¶
UpdateKarma .
type ProcConfig ¶
ProcConfig processor config object to contain all of these customizations SingleLimit one time karma swings are capped at 5 (default) DailyLimit this is the default daily limit for giving/ taking karma used by top function as guard rails used by top function as guard rails
var DefaultConfig ProcConfig = ProcConfig{
SingleLimit: 5,
DailyLimit: 25,
TopUserDefault: 3,
TopUserMax: 10,
}
DefaultConfig default settings for the Processor
type Processor ¶
type Processor interface {
Process(cd slack.CommandData) (slack.Response, error)
}
Processor processes slash-commands into slack responses
type SQLiteDAO ¶
type SQLiteDAO struct {
// contains filtered or unexported fields
}
SQLiteDAO a SQLite imlpementation of the Karma database
func (SQLiteDAO) DeleteKarma ¶
DeleteKarma resets all karma for a given user in a given team to zer0
func (SQLiteDAO) GetDaily ¶
GetDaily return the amount of karma the team/user has gives/taken for a day
func (SQLiteDAO) UpdateDaily ¶
UpdateDaily adds karma to team/user's daily usage count
func (SQLiteDAO) UpdateKarma ¶
UpdateKarma adds (or removes) karma from a user in a given team (workspace)
func (SQLiteDAO) UpdateKarmaDaily ¶
func (dao SQLiteDAO) UpdateKarmaDaily(team, callee, target string, delta int, date time.Time) (int, error)
UpdateKarmaDaily updates the karma total and daily usage at the same time, returns new karma the target receives karma the callee has their daily usage incremented
type SQLiteHandler ¶
type SQLiteHandler struct {
// contains filtered or unexported fields
}
SQLiteHandler Karma Handler implementation using sqlite
func (SQLiteHandler) AddKarma ¶
func (h SQLiteHandler) AddKarma(c *gin.Context)
AddKarma handler method to add (or subtract) karma from an individual
func (SQLiteHandler) DelKarma ¶
func (h SQLiteHandler) DelKarma(c *gin.Context)
DelKarma handler method to delete (reset) karma to zer0
func (SQLiteHandler) GetKarma ¶
func (h SQLiteHandler) GetKarma(c *gin.Context)
GetKarma handler method to read the current karma for an individual
func (SQLiteHandler) SlashKarma ¶
func (h SQLiteHandler) SlashKarma(c *gin.Context)
SlashKarma handler method for the `/karma` slash-command
func (SQLiteHandler) TopKarma ¶
func (h SQLiteHandler) TopKarma(c *gin.Context)
TopKarma returns the top n users for a given team
type SlackProcessor ¶
type SlackProcessor struct {
// contains filtered or unexported fields
}
SlackProcessor an implementation of KarmaProcessor that uses SQLite
func NewProcessor ¶
func NewProcessor(config ProcConfig, dao DAO, insult, compliment shakespeare.Generator) SlackProcessor
NewProcessor factory method
func (SlackProcessor) Process ¶
func (p SlackProcessor) Process(c slack.CommandData) (slack.Response, error)
Process handles Karma processing from slack API
func (SlackProcessor) Salutation ¶
func (p SlackProcessor) Salutation(k int) string
Salutation appends a Salutation (insult or compliment)