From c7f54fe204f9ea42459a1bc13eb9fc68dcec5ff6 Mon Sep 17 00:00:00 2001 From: Aaron Bieber Date: Fri, 7 Feb 2020 16:06:24 -0700 Subject: [PATCH] +wb --- plugins/plugins.go | 1 + plugins/welcome_back.go | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 plugins/welcome_back.go 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" +}