From 049e748c0dd4b85ccf154495d413b5b79244f494 Mon Sep 17 00:00:00 2001 From: Aaron Bieber Date: Sun, 3 Apr 2022 13:35:20 -0600 Subject: [PATCH] Add plugin to let me bulk-ban a list of users --- plugins/ban.go | 70 ++++++++++++++++++++++++++++++++++++++++++++++ plugins/plugins.go | 1 + 2 files changed, 71 insertions(+) create mode 100644 plugins/ban.go diff --git a/plugins/ban.go b/plugins/ban.go new file mode 100644 index 0000000..8f5ec8c --- /dev/null +++ b/plugins/ban.go @@ -0,0 +1,70 @@ +package plugins + +import ( + "fmt" + "math/rand" + "regexp" + "strings" + "time" + + "github.com/matrix-org/gomatrix" +) + +// Ban responds to ban messages +type Ban struct { +} + +// Descr returns a description +func (h *Ban) Descr() string { + return "Ban a list of users." +} + +// Re matches "ban:" in a given string +func (h *Ban) Re() string { + return `(?i)^ban: (.*)$` +} + +// Match determines if we should execute Ban +func (h *Ban) Match(_, msg string) bool { + re := regexp.MustCompile(h.Re()) + return re.MatchString(msg) +} + +// SetStore we don't need a store, so just return +func (h *Ban) SetStore(_ PluginStore) {} + +// Process does the heavy lifting +func (h *Ban) Process(from, msg string) string { + a := []string{ + "omm nom nom nom", + "*puke*", + "MOAR!", + "=.=", + } + + rand.Seed(time.Now().Unix()) + return a[rand.Intn(len(a))] +} + +// RespondText to botsnack events +func (h *Ban) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) error { + switch ev.Sender { + case "@qbit:tapenet.org": + speed := 5 + re := regexp.MustCompile(h.Re()) + bans := strings.Split(re.ReplaceAllString(post, "$1"), " ") + + SendText(c, ev.RoomID, fmt.Sprintf("Banning %d users with %d seconds inbetween bans.", len(bans), speed)) + for _, ban := range bans { + st := fmt.Sprintf("hammer ban ob user %s spam", ban) + SendText(c, ev.RoomID, st) + time.Sleep(time.Second * time.Duration(speed)) + } + } + return nil +} + +// Name Ban +func (h *Ban) Name() string { + return "Ban" +} diff --git a/plugins/plugins.go b/plugins/plugins.go index 473f702..b9404c8 100644 --- a/plugins/plugins.go +++ b/plugins/plugins.go @@ -282,6 +282,7 @@ type Plugins []Plugin // Plugs defines the "enabled" plugins. var Plugs = Plugins{ + &Ban{}, &BananaStab{}, &Beat{}, &Beer{},