mcchunkie/plugins/botsnack.go

61 lines
1.2 KiB
Go
Raw Normal View History

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 {
}
// 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
func (h *BotSnack) Match(user, 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-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
func (h *BotSnack) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) {
u := NameRE.ReplaceAllString(user, "$1")
if ToMe(u, post) {
2020-02-10 17:10:57 -07:00
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"
}