mirror of https://github.com/velour/catbase.git
slack: update library
This commit is contained in:
parent
04f7b34e14
commit
4bf0ac095c
2
go.mod
2
go.mod
|
@ -50,7 +50,7 @@ require (
|
|||
github.com/robertkrimen/otto v0.0.0-20180617131154-15f95af6e78d // indirect
|
||||
github.com/rs/zerolog v1.15.0
|
||||
github.com/saintfish/chardet v0.0.0-20120816061221-3af4cd4741ca // indirect
|
||||
github.com/slack-go/slack v0.7.2
|
||||
github.com/slack-go/slack v0.9.4
|
||||
github.com/spaolacci/murmur3 v1.1.0 // indirect
|
||||
github.com/stretchr/objx v0.2.0 // indirect
|
||||
github.com/stretchr/testify v1.4.0
|
||||
|
|
4
go.sum
4
go.sum
|
@ -129,8 +129,8 @@ github.com/rs/zerolog v1.15.0 h1:uPRuwkWF4J6fGsJ2R0Gn2jB1EQiav9k3S6CSdygQJXY=
|
|||
github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc=
|
||||
github.com/saintfish/chardet v0.0.0-20120816061221-3af4cd4741ca h1:NugYot0LIVPxTvN8n+Kvkn6TrbMyxQiuvKdEwFdR9vI=
|
||||
github.com/saintfish/chardet v0.0.0-20120816061221-3af4cd4741ca/go.mod h1:uugorj2VCxiV1x+LzaIdVa9b4S4qGAcH6cbhh4qVxOU=
|
||||
github.com/slack-go/slack v0.7.2 h1:oLy2a2YqrtoHSSxbjRhrtLDGbCKcZJwgbuQ826BWxaI=
|
||||
github.com/slack-go/slack v0.7.2/go.mod h1:FGqNzJBmxIsZURAxh2a8D21AnOVvvXZvGligs4npPUM=
|
||||
github.com/slack-go/slack v0.9.4 h1:C+FC3zLxLxUTQjDy2RZeMHYon005zsCROiZNWVo+opQ=
|
||||
github.com/slack-go/slack v0.9.4/go.mod h1:wWL//kk0ho+FcQXcBTmEafUI5dz4qz5f4mMk8oIkioQ=
|
||||
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
|
||||
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
|
|
2
main.go
2
main.go
|
@ -13,6 +13,7 @@ import (
|
|||
"github.com/velour/catbase/connectors/discord"
|
||||
"github.com/velour/catbase/plugins/giphy"
|
||||
"github.com/velour/catbase/plugins/last"
|
||||
"github.com/velour/catbase/plugins/quotegame"
|
||||
"github.com/velour/catbase/plugins/rest"
|
||||
"github.com/velour/catbase/plugins/secrets"
|
||||
|
||||
|
@ -163,6 +164,7 @@ func main() {
|
|||
b.AddPlugin(sms.New(b))
|
||||
b.AddPlugin(countdown.New(b))
|
||||
b.AddPlugin(rest.New(b))
|
||||
b.AddPlugin(quotegame.New(b))
|
||||
// catches anything left, will always return true
|
||||
b.AddPlugin(fact.New(b))
|
||||
|
||||
|
|
|
@ -2,9 +2,11 @@ package quotegame
|
|||
|
||||
import (
|
||||
"math/rand"
|
||||
"regexp"
|
||||
"time"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/velour/catbase/bot"
|
||||
"github.com/velour/catbase/config"
|
||||
)
|
||||
|
@ -14,16 +16,38 @@ type QuoteGame struct {
|
|||
c *config.Config
|
||||
db *sqlx.DB
|
||||
|
||||
handlers []bot.HandlerSpec
|
||||
|
||||
currentGame *time.Timer
|
||||
}
|
||||
|
||||
func New(b bot.Bot) *QuoteGame {
|
||||
return &QuoteGame{
|
||||
p := &QuoteGame{
|
||||
b: b,
|
||||
c: b.Config(),
|
||||
db: b.DB(),
|
||||
currentGame: nil,
|
||||
}
|
||||
p.register()
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *QuoteGame) register() {
|
||||
log.Debug().Msg("registering quote handlers")
|
||||
p.handlers = []bot.HandlerSpec{
|
||||
{
|
||||
Kind: bot.Message, IsCmd: true,
|
||||
Regex: regexp.MustCompile(`(?i)^quote game$`),
|
||||
HelpText: "Start a quote game",
|
||||
Handler: p.startGame,
|
||||
},
|
||||
{
|
||||
Kind: bot.Message, IsCmd: false,
|
||||
Regex: regexp.MustCompile(`.*`),
|
||||
Handler: p.message,
|
||||
},
|
||||
}
|
||||
p.b.RegisterTable(p, p.handlers)
|
||||
}
|
||||
|
||||
func (p *QuoteGame) getAllQuotes() ([]string, error) {
|
||||
|
@ -47,4 +71,29 @@ func (p *QuoteGame) getRandomquote() (string, error) {
|
|||
return "", err
|
||||
}
|
||||
return quotes[rand.Intn(len(quotes))], nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p *QuoteGame) startGame(r bot.Request) bool {
|
||||
log.Debug().Msg("startGame called")
|
||||
if p.currentGame != nil {
|
||||
p.b.Send(r.Conn, bot.Message, r.Msg.Channel, "There is already a quote game running.")
|
||||
return true
|
||||
}
|
||||
|
||||
length := time.Duration(p.c.GetInt("quotegame.length", 120))
|
||||
p.currentGame = time.AfterFunc(length * time.Second, func() {
|
||||
p.currentGame = nil
|
||||
p.b.Send(r.Conn, bot.Message, r.Msg.Channel, "Game ended.")
|
||||
})
|
||||
|
||||
p.b.Send(r.Conn, bot.Message, r.Msg.Channel, "Game started.")
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (p *QuoteGame) message(r bot.Request) bool {
|
||||
if p.currentGame == nil {
|
||||
return false
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue