mayi: add coinflip plugin

This commit is contained in:
Chris Sexton 2021-10-13 21:11:35 -04:00 committed by Chris Sexton
parent 373929646c
commit 6bcf1142c4
2 changed files with 38 additions and 0 deletions

View File

@ -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))

36
plugins/mayi/cani.go Normal file
View File

@ -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
}