diff --git a/main.go b/main.go index b3e25d9..a26ac7b 100644 --- a/main.go +++ b/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)) diff --git a/plugins/mayi/cani.go b/plugins/mayi/cani.go new file mode 100644 index 0000000..53da384 --- /dev/null +++ b/plugins/mayi/cani.go @@ -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\S+) (?P.+)`) + +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 +}