2020-02-12 20:13:05 -07:00
|
|
|
package plugins
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"math/rand"
|
|
|
|
"regexp"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/matrix-org/gomatrix"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Thanks responds to thanks
|
|
|
|
type Thanks struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
// Descr describes this plugin
|
|
|
|
func (h *Thanks) Descr() string {
|
|
|
|
return "Bots should be respectful. Respond to thanks."
|
|
|
|
}
|
|
|
|
|
|
|
|
// Re checks for various forms of thanks
|
|
|
|
func (h *Thanks) Re() string {
|
|
|
|
return `(?i)^thank you|thank you$|^thanks|thanks$|^ty|ty$`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Match determins if we are being thanked
|
|
|
|
func (h *Thanks) Match(user, msg string) bool {
|
|
|
|
re := regexp.MustCompile(h.Re())
|
|
|
|
return re.MatchString(msg) && ToMe(user, msg)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetStore we don't need a store here
|
|
|
|
func (h *Thanks) SetStore(s PluginStore) {}
|
|
|
|
|
|
|
|
// RespondText to welcome back events
|
2020-05-13 16:53:31 -06:00
|
|
|
func (h *Thanks) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) error {
|
2020-02-12 20:13:05 -07:00
|
|
|
s := NameRE.ReplaceAllString(ev.Sender, "$1")
|
|
|
|
a := []string{
|
|
|
|
fmt.Sprintf("welcome %s", s),
|
|
|
|
"welcome",
|
|
|
|
"you're welcome",
|
|
|
|
"np!",
|
2020-03-10 10:30:54 -06:00
|
|
|
fmt.Sprintf("you're welcome, %s", s),
|
2020-02-12 20:13:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
rand.Seed(time.Now().Unix())
|
|
|
|
|
2020-05-13 16:53:31 -06:00
|
|
|
return SendText(c, ev.RoomID, a[rand.Intn(len(a))])
|
2020-02-12 20:13:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Name Thanks
|
|
|
|
func (h *Thanks) Name() string {
|
|
|
|
return "Thanks"
|
|
|
|
}
|