mcchunkie/plugins/botsnack.go

60 lines
1.2 KiB
Go
Raw Normal View History

2020-01-31 20:27:22 -07:00
package plugins
import (
"math/rand"
"regexp"
"time"
"github.com/matrix-org/gomatrix"
)
2020-02-05 07:56:18 -07:00
// BotSnack responds to botsnack messages
2020-01-31 20:27:22 -07:00
type BotSnack struct {
}
// Descr returns a description
func (h *BotSnack) Descr() string {
return "Consumes a botsnack. This pleases mcchunkie and brings balance to the universe."
}
// Re matches "botsnack" in a given string
func (h *BotSnack) Re() string {
return `(?i)botsnack`
}
2020-02-10 17:10:57 -07:00
// Match determines if we should execute BotSnack
2020-05-13 17:05:01 -06:00
func (h *BotSnack) Match(_, msg string) bool {
re := regexp.MustCompile(h.Re())
2020-01-31 20:27:22 -07:00
return re.MatchString(msg)
}
func (h *BotSnack) resp() string {
a := []string{
"omm nom nom nom",
"*puke*",
"MOAR!",
"=.=",
}
rand.Seed(time.Now().Unix())
return a[rand.Intn(len(a))]
}
2020-02-05 22:04:04 -07:00
// SetStore we don't need a store, so just return
2020-05-13 17:05:01 -06:00
func (h *BotSnack) SetStore(_ PluginStore) {}
2020-02-05 22:04:04 -07:00
2020-02-05 07:56:18 -07:00
// RespondText to botsnack events
2020-05-13 16:53:31 -06:00
func (h *BotSnack) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) error {
u := NameRE.ReplaceAllString(user, "$1")
if ToMe(u, post) {
2020-05-13 16:53:31 -06:00
return SendText(c, ev.RoomID, h.resp())
2020-01-31 20:27:22 -07:00
}
2020-05-13 16:53:31 -06:00
return nil
2020-01-31 20:27:22 -07:00
}
2020-02-05 07:56:18 -07:00
// Name BotSnack
2020-01-31 20:27:22 -07:00
func (h *BotSnack) Name() string {
return "BotSnack"
}