mcchunkie/plugins/botsnack.go

58 lines
1.2 KiB
Go
Raw Normal View History

2020-01-31 20:27:22 -07:00
package plugins
import (
"math/rand"
"regexp"
"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)
}
// SetStore we don't need a store, so just return
func (h *BotSnack) SetStore(_ PluginStore) {}
// Process does the heavy lifting
func (h *BotSnack) Process(from, msg string) string {
2020-01-31 20:27:22 -07:00
a := []string{
"omm nom nom nom",
"*puke*",
"MOAR!",
"=.=",
}
return a[rand.Intn(len(a))]
}
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) {
return SendText(c, ev.RoomID, h.Process(ev.Sender, post))
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"
}