diff --git a/plugins/plugins.go b/plugins/plugins.go index f1f0b13..4c98770 100644 --- a/plugins/plugins.go +++ b/plugins/plugins.go @@ -62,5 +62,6 @@ var Plugs = Plugins{ &OpenBSDMan{}, &Source{}, &Version{}, + &Wb{}, &Weather{}, } diff --git a/plugins/welcome_back.go b/plugins/welcome_back.go new file mode 100644 index 0000000..deef635 --- /dev/null +++ b/plugins/welcome_back.go @@ -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" +}