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 {
|
|
|
|
}
|
|
|
|
|
2020-02-11 07:56:19 -07:00
|
|
|
// 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 {
|
2020-02-11 07:56:19 -07:00
|
|
|
re := regexp.MustCompile(h.Re())
|
2020-01-31 20:27:22 -07:00
|
|
|
return re.MatchString(msg)
|
|
|
|
}
|
|
|
|
|
2021-04-01 16:15:25 -06:00
|
|
|
// 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!",
|
|
|
|
"=.=",
|
|
|
|
}
|
|
|
|
|
|
|
|
rand.Seed(time.Now().Unix())
|
|
|
|
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 {
|
2020-02-02 19:43:26 -07:00
|
|
|
u := NameRE.ReplaceAllString(user, "$1")
|
|
|
|
if ToMe(u, post) {
|
2021-04-01 16:15:25 -06:00
|
|
|
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"
|
|
|
|
}
|