From 27b6fa03143dbcd9bfbff6031295f12d32f4f5af Mon Sep 17 00:00:00 2001 From: Aaron Bieber Date: Sat, 1 Feb 2020 20:53:56 -0700 Subject: [PATCH] tell people about the source if they ask --- plugins/plugins.go | 1 + plugins/source.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 plugins/source.go diff --git a/plugins/plugins.go b/plugins/plugins.go index 8fa48ee..ee3657d 100644 --- a/plugins/plugins.go +++ b/plugins/plugins.go @@ -47,4 +47,5 @@ var Plugs = Plugins{ &HighFive{}, &Hi{}, &LoveYou{}, + &Source{}, } diff --git a/plugins/source.go b/plugins/source.go new file mode 100644 index 0000000..f9ea011 --- /dev/null +++ b/plugins/source.go @@ -0,0 +1,42 @@ +package plugins + +import ( + "fmt" + "log" + "regexp" + + "github.com/matrix-org/gomatrix" +) + +// Source responds to source requests +type Source struct { +} + +func (h *Source) match(msg string) bool { + re := regexp.MustCompile(`(?i)where is your (source|code)`) + return re.MatchString(msg) +} + +// Respond to questions about TheSource™©®⑨ +func (h *Source) Respond(c *gomatrix.Client, ev *gomatrix.Event, user string) { + if mtype, ok := ev.MessageType(); ok { + switch mtype { + case "m.text": + if post, ok := ev.Body(); ok { + 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) + SendMessage(c, ev.RoomID, fmt.Sprintf("%s: %s ;D", s, "https://git.sr.ht/~qbit/mcchunkie")) + } + } + } + } + } +} + +// Name Source +func (h *Source) Name() string { + return "Source" +}