2020-02-07 16:06:24 -07:00
|
|
|
package plugins
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"regexp"
|
|
|
|
|
|
|
|
"github.com/matrix-org/gomatrix"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Wb responds to welcome back messages
|
|
|
|
type Wb struct {
|
|
|
|
}
|
|
|
|
|
2020-02-11 07:56:19 -07:00
|
|
|
// Descr describes this plugin
|
|
|
|
func (h *Wb) Descr() string {
|
|
|
|
return "Respond to welcome back messages."
|
|
|
|
}
|
|
|
|
|
|
|
|
// Re checks for various welcome back things
|
|
|
|
func (h *Wb) Re() string {
|
|
|
|
return `(?i)^welcome back|welcome back$|^wb|wb$`
|
|
|
|
}
|
|
|
|
|
2020-05-13 17:36:26 -06:00
|
|
|
// Match determines if we are welcomed back
|
2020-02-10 17:10:57 -07:00
|
|
|
func (h *Wb) 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-07 16:06:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetStore we don't need a store here
|
2020-05-13 17:05:01 -06:00
|
|
|
func (h *Wb) SetStore(_ PluginStore) {}
|
2020-02-07 16:06:24 -07:00
|
|
|
|
2021-04-01 16:15:25 -06:00
|
|
|
func (h *Wb) Process(from, post string) string {
|
|
|
|
s := NameRE.ReplaceAllString(from, "$1")
|
|
|
|
return fmt.Sprintf("thanks %s!", s)
|
|
|
|
}
|
|
|
|
|
2020-02-07 16:06:24 -07:00
|
|
|
// RespondText to welcome back events
|
2020-05-13 17:05:01 -06:00
|
|
|
func (h *Wb) RespondText(c *gomatrix.Client, ev *gomatrix.Event, _, _ string) error {
|
2021-04-01 16:15:25 -06:00
|
|
|
return SendText(c, ev.RoomID, h.Process(ev.Sender, ""))
|
2020-02-10 17:10:57 -07:00
|
|
|
|
2020-02-07 16:06:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Name Wb
|
|
|
|
func (h *Wb) Name() string {
|
|
|
|
return "Wb"
|
|
|
|
}
|