mirror of https://github.com/velour/catbase.git
mayi: add coinflip plugin
This commit is contained in:
parent
373929646c
commit
6bcf1142c4
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/mayi"
|
||||
"github.com/velour/catbase/plugins/quotegame"
|
||||
"github.com/velour/catbase/plugins/rest"
|
||||
"github.com/velour/catbase/plugins/secrets"
|
||||
|
@ -124,6 +125,7 @@ func main() {
|
|||
|
||||
b.AddPlugin(admin.New(b))
|
||||
b.AddPlugin(secrets.New(b))
|
||||
b.AddPlugin(mayi.New(b))
|
||||
b.AddPlugin(giphy.New(b))
|
||||
b.AddPlugin(emojifyme.New(b))
|
||||
b.AddPlugin(last.New(b))
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
package mayi
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"regexp"
|
||||
|
||||
"github.com/velour/catbase/bot"
|
||||
"github.com/velour/catbase/config"
|
||||
)
|
||||
|
||||
type MayIPlugin struct {
|
||||
b bot.Bot
|
||||
c *config.Config
|
||||
}
|
||||
|
||||
var regex = regexp.MustCompile(`(?i)(may|can) (?P<who>\S+) (?P<what>.+)`)
|
||||
|
||||
func New(b bot.Bot) *MayIPlugin {
|
||||
m := &MayIPlugin{
|
||||
b: b,
|
||||
c: b.Config(),
|
||||
}
|
||||
|
||||
b.RegisterRegexCmd(m, bot.Message, regex, m.message)
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
func (p *MayIPlugin) message(r bot.Request) bool {
|
||||
msg := p.c.Get("mayi.no", "no")
|
||||
if rand.Intn(2) == 0 {
|
||||
msg = p.c.Get("mayi.yes", "yes")
|
||||
}
|
||||
p.b.Send(r.Conn, bot.Message, r.Msg.Channel, msg)
|
||||
return true
|
||||
}
|
Loading…
Reference in New Issue