34 lines
668 B
Go
34 lines
668 B
Go
|
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)
|
||
|
}
|