2020-01-31 20:27:22 -07:00
|
|
|
package plugins
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"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 {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *BotSnack) match(msg string) bool {
|
2020-02-01 15:14:24 -07:00
|
|
|
re := regexp.MustCompile(`(?i)botsnack`)
|
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-02-10 16:08:33 -07:00
|
|
|
func (h *BotSnack) SetStore(s PluginStore) {}
|
2020-02-05 22:04:04 -07:00
|
|
|
|
2020-02-05 07:56:18 -07:00
|
|
|
// RespondText to botsnack events
|
2020-02-02 19:43:26 -07:00
|
|
|
func (h *BotSnack) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) {
|
|
|
|
u := NameRE.ReplaceAllString(user, "$1")
|
|
|
|
if ToMe(u, post) {
|
|
|
|
if h.match(post) {
|
|
|
|
log.Printf("%s: responding to '%s'", h.Name(), ev.Sender)
|
|
|
|
SendText(c, ev.RoomID, h.resp())
|
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"
|
|
|
|
}
|