mcchunkie/plugins/welcome_back.go

36 lines
777 B
Go
Raw Normal View History

2020-02-07 16:06:24 -07:00
package plugins
import (
"fmt"
"log"
"regexp"
"github.com/matrix-org/gomatrix"
)
// Wb responds to welcome back messages
type Wb struct {
}
2020-02-10 17:10:57 -07:00
// Match determins if we are welcomed back
func (h *Wb) Match(user, msg string) bool {
2020-02-07 16:06:24 -07:00
re := regexp.MustCompile(`(?i)^welcome back|welcome back$|^wb|wb$`)
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-02-10 16:08:33 -07:00
func (h *Wb) SetStore(s PluginStore) {}
2020-02-07 16:06:24 -07:00
// RespondText to welcome back events
func (h *Wb) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) {
s := NameRE.ReplaceAllString(ev.Sender, "$1")
2020-02-10 17:10:57 -07:00
log.Printf("%s: responding to '%s'", h.Name(), ev.Sender)
SendText(c, ev.RoomID, fmt.Sprintf("thanks %s!", s))
2020-02-07 16:06:24 -07:00
}
// Name Wb
func (h *Wb) Name() string {
return "Wb"
}