update ban to allow banning servers

This commit is contained in:
Aaron Bieber 2022-08-09 20:37:09 -06:00
parent 1b097fe4db
commit 877abf1331
No known key found for this signature in database
2 changed files with 7 additions and 6 deletions

View File

@ -15,12 +15,12 @@ type Ban struct {
// Descr returns a description // Descr returns a description
func (h *Ban) Descr() string { func (h *Ban) Descr() string {
return "Ban a list of users." return "Ban a list of users or servers."
} }
// Re matches "ban:" in a given string // Re matches "ban:" in a given string
func (h *Ban) Re() string { func (h *Ban) Re() string {
return `(?i)^ban: (.*)$` return `(?i)^ban (user|server): (.*)$`
} }
// Match determines if we should execute Ban // Match determines if we should execute Ban
@ -43,12 +43,13 @@ func (h *Ban) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post str
case "@qbit:tapenet.org": case "@qbit:tapenet.org":
speed := 5 speed := 5
re := regexp.MustCompile(h.Re()) re := regexp.MustCompile(h.Re())
bans := strings.Split(re.ReplaceAllString(post, "$1"), " ") cmd := re.ReplaceAllString(post, "$1")
bans := strings.Split(re.ReplaceAllString(post, "$2"), " ")
go func() { go func() {
SendText(c, ev.RoomID, fmt.Sprintf("Banning %d users with %d seconds inbetween bans.", len(bans), speed)) SendText(c, ev.RoomID, fmt.Sprintf("Banning %d %s with %d seconds inbetween bans.", len(bans), cmd, speed))
for _, ban := range bans { for _, ban := range bans {
st := fmt.Sprintf("hammer ban ob user %s spam", ban) st := fmt.Sprintf("hammer ban ob %s %s spam", cmd, ban)
SendText(c, ev.RoomID, st) SendText(c, ev.RoomID, st)
time.Sleep(time.Second * time.Duration(speed)) time.Sleep(time.Second * time.Duration(speed))
} }

View File

@ -33,7 +33,7 @@ func (h *Feder) Descr() string {
// Re returns the federation check matching string // Re returns the federation check matching string
func (h *Feder) Re() string { func (h *Feder) Re() string {
return `(?i)^(?:feder: |tayshame: )(.*)$` return `(?i)^(?:feder: |tayshame: |danshame: )(.*)$`
} }
func (h *Feder) fix(msg string) string { func (h *Feder) fix(msg string) string {