This commit is contained in:
Aaron Bieber 2020-02-07 16:06:24 -07:00
parent 67091a62de
commit c7f54fe204
2 changed files with 39 additions and 0 deletions

View File

@ -62,5 +62,6 @@ var Plugs = Plugins{
&OpenBSDMan{},
&Source{},
&Version{},
&Wb{},
&Weather{},
}

38
plugins/welcome_back.go Normal file
View File

@ -0,0 +1,38 @@
package plugins
import (
"fmt"
"log"
"regexp"
"github.com/matrix-org/gomatrix"
)
// Wb responds to welcome back messages
type Wb struct {
}
func (h *Wb) match(msg string) bool {
re := regexp.MustCompile(`(?i)^welcome back|welcome back$|^wb|wb$`)
return re.MatchString(msg)
}
// SetStore we don't need a store here
func (h *Wb) SetStore(s PluginStore) { return }
// RespondText to welcome back events
func (h *Wb) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) {
u := NameRE.ReplaceAllString(user, "$1")
s := NameRE.ReplaceAllString(ev.Sender, "$1")
if ToMe(u, post) {
if h.match(post) {
log.Printf("%s: responding to '%s'", h.Name(), ev.Sender)
SendText(c, ev.RoomID, fmt.Sprintf("thanks %s!", s))
}
}
}
// Name Wb
func (h *Wb) Name() string {
return "Wb"
}