mcchunkie/plugins/ban.go

66 lines
1.4 KiB
Go
Raw Permalink Normal View History

package plugins
import (
"fmt"
"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 {
2022-08-09 20:37:09 -06:00
return "Ban a list of users or servers."
}
// Re matches "ban:" in a given string
func (h *Ban) Re() string {
2022-08-09 20:37:09 -06:00
return `(?i)^ban (user|server): (.*)$`
}
// 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 {
2022-04-03 13:41:19 -06:00
return ""
}
// 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())
2022-08-09 20:37:09 -06:00
cmd := re.ReplaceAllString(post, "$1")
bans := strings.Split(re.ReplaceAllString(post, "$2"), " ")
2022-04-03 13:50:25 -06:00
go func() {
2022-08-09 20:37:09 -06:00
SendText(c, ev.RoomID, fmt.Sprintf("Banning %d %s with %d seconds inbetween bans.", len(bans), cmd, speed))
2022-04-03 13:50:25 -06:00
for _, ban := range bans {
2022-08-09 20:37:09 -06:00
st := fmt.Sprintf("hammer ban ob %s %s spam", cmd, ban)
2022-04-03 13:50:25 -06:00
SendText(c, ev.RoomID, st)
time.Sleep(time.Second * time.Duration(speed))
}
SendText(c, ev.RoomID, "Done banning.")
}()
}
return nil
}
// Name Ban
func (h *Ban) Name() string {
return "Ban"
}