Allow people to be ignored by nick

This commit is contained in:
2021-02-13 01:26:08 +00:00
parent 264c591495
commit 3d5d18ce44
2 changed files with 45 additions and 5 deletions

34
handlers/ignore/ignore.go Normal file
View File

@@ -0,0 +1,34 @@
package ignore
import (
"context"
"fmt"
"regexp"
"github.com/tcolgate/hugot"
)
type HearsIgnore struct {
hugot.HearsHandler
Ignore []*regexp.Regexp
}
func NewHears(next hugot.HearsHandler, who ...string) hugot.HearsHandler {
var ignoreCompiled []*regexp.Regexp
for _, str := range who {
ignoreCompiled = append(ignoreCompiled, regexp.MustCompile(str))
}
return &HearsIgnore{HearsHandler: next, Ignore: ignoreCompiled}
}
func (i *HearsIgnore) Heard(ctx context.Context, w hugot.ResponseWriter, m *hugot.Message, matches [][]string) {
for _, re := range i.Ignore {
if re.MatchString(m.From) {
return
}
}
i.HearsHandler.Heard(ctx, w, m, matches)
}