Files
lysenko/handlers/ignore/ignore.go

34 lines
668 B
Go
Raw Normal View History

2021-02-13 01:26:08 +00:00
package ignore
import (
"context"
"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)
}