From 608646deb1f4293dfe2e5a0c6c3ee5a5a83096f7 Mon Sep 17 00:00:00 2001 From: Aaron Bieber Date: Thu, 11 Jun 2020 17:13:33 -0600 Subject: [PATCH] +groan. --- README.md | 1 + plugins/groan.go | 56 ++++++++++++++++++++++++++++++++++++++++++++++ plugins/plugins.go | 1 + 3 files changed, 58 insertions(+) create mode 100644 plugins/groan.go diff --git a/README.md b/README.md index b384fff..4d6ca3c 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ |BotSnack|`(?i)botsnack`|Consumes a botsnack. This pleases mcchunkie and brings balance to the universe.| |Covid|`(?i)^covid: (.+)$`|Queries [thebigboard.cc](http://www.thebigboard.cc)'s api for information on COVID-19.| |Feder|`(?i)^(?:feder: |tayshame: )(.*)$`|check the Matrix federation status of a given URL.| +|Groan|`(?i)^@groan$`|Ugh.| |Ham|`(?i)^ham: (\w+)$`|queries the FCC's [ULS](https://wireless2.fcc.gov/UlsApp/UlsSearch/searchLicense.jsp) for a given callsign.| |HighFive|`o/|\\o`|Everyone loves highfives.| |Hi|`(?i)^hi|hi$`|Friendly bots say hi.| diff --git a/plugins/groan.go b/plugins/groan.go new file mode 100644 index 0000000..3731c8e --- /dev/null +++ b/plugins/groan.go @@ -0,0 +1,56 @@ +package plugins + +import ( + "github.com/matrix-org/gomatrix" + "math/rand" + "regexp" + "time" +) + +// Groan responds to groans. +type Groan struct { +} + +// Descr describes this plugin +func (h *Groan) Descr() string { + return "Ugh." +} + +// Re are the regexes that high five uses +func (h *Groan) Re() string { + return `(?i)^@groan$` +} + +// SetStore we don't need a store here. +func (h *Groan) SetStore(_ PluginStore) {} + +// Match determines if we should bother groaning +func (h *Groan) Match(user, msg string) bool { + re := regexp.MustCompile(h.Re()) + return re.MatchString(msg) +} + +func (h *Groan) resp() string { + a := []string{ + "Ugh.", + "ugh", + "ffffuuuu", + "sigh.", + "oh fml.", + "........", + } + + rand.Seed(time.Now().Unix()) + return a[rand.Intn(len(a))] + +} + +// RespondText to groan events +func (h *Groan) RespondText(c *gomatrix.Client, ev *gomatrix.Event, _, post string) error { + return SendText(c, ev.RoomID, h.resp()) +} + +// Name returns the name of the Groan plugin +func (h *Groan) Name() string { + return "Groan" +} diff --git a/plugins/plugins.go b/plugins/plugins.go index 288a59e..90d0c5e 100644 --- a/plugins/plugins.go +++ b/plugins/plugins.go @@ -217,6 +217,7 @@ var Plugs = Plugins{ &BotSnack{}, &Covid{}, &Feder{}, + &Groan{}, &Ham{}, &HighFive{}, &Hi{},