2020-02-01 15:15:01 -07:00
|
|
|
package plugins
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math/rand"
|
|
|
|
"regexp"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/matrix-org/gomatrix"
|
|
|
|
)
|
|
|
|
|
|
|
|
// LoveYou responds to love messages
|
|
|
|
type LoveYou struct {
|
|
|
|
}
|
|
|
|
|
2020-02-11 07:56:19 -07:00
|
|
|
// Descr describes this plugin
|
|
|
|
func (h *LoveYou) Descr() string {
|
|
|
|
return "Spreading love where ever we can by responding when someone shows us love."
|
|
|
|
}
|
|
|
|
|
|
|
|
// Re matches "i love you"
|
|
|
|
func (h *LoveYou) Re() string {
|
|
|
|
return `(?i)i love you`
|
|
|
|
}
|
|
|
|
|
2020-02-10 17:10:57 -07:00
|
|
|
// Match checks for 'i love you' and a reference to the bot name
|
|
|
|
func (h *LoveYou) Match(user, msg string) bool {
|
2020-02-11 07:56:19 -07:00
|
|
|
re := regexp.MustCompile(h.Re())
|
2020-02-10 17:10:57 -07:00
|
|
|
return re.MatchString(msg) && ToMe(user, msg)
|
2020-02-01 15:15:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func (h *LoveYou) resp() string {
|
|
|
|
a := []string{
|
|
|
|
"I am not ready for this kind of relationship!",
|
|
|
|
"ಠ_ಠ",
|
|
|
|
"I love you too!",
|
|
|
|
"(╯‵Д′)╯彡┻━┻",
|
|
|
|
"hawkard!",
|
|
|
|
}
|
|
|
|
|
|
|
|
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 *LoveYou) SetStore(s PluginStore) {}
|
2020-02-05 22:04:04 -07:00
|
|
|
|
2020-02-02 19:43:26 -07:00
|
|
|
// RespondText to love events
|
|
|
|
func (h *LoveYou) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) {
|
2020-02-10 17:10:57 -07:00
|
|
|
SendText(c, ev.RoomID, h.resp())
|
2020-02-01 15:15:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Name i love you
|
|
|
|
func (h *LoveYou) Name() string {
|
|
|
|
return "LoveYou"
|
|
|
|
}
|